mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 04:34:00 +00:00
New stuff! [skip ci]
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Controllers\BudgetInterface as BI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
|
||||
use Carbon\Carbon;
|
||||
/**
|
||||
* Class BudgetController
|
||||
*/
|
||||
@@ -9,16 +10,40 @@ class BudgetController extends BaseController
|
||||
{
|
||||
|
||||
protected $_budgets;
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param BRI $budgets
|
||||
*/
|
||||
public function __construct(BRI $budgets)
|
||||
public function __construct(BI $budgets, BRI $repository)
|
||||
{
|
||||
$this->_budgets = $budgets;
|
||||
$this->_repository = $repository;
|
||||
View::share('menu', 'budgets');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('budgets.create')->with('periods', $periods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function indexByBudget()
|
||||
{
|
||||
$budgets = $this->_repository->get();
|
||||
$today = new Carbon;
|
||||
|
||||
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', $today);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
* @throws Firefly\Exception\FireflyException
|
||||
@@ -26,76 +51,12 @@ class BudgetController extends BaseController
|
||||
public function indexByDate()
|
||||
{
|
||||
// get a list of dates by getting all repetitions:
|
||||
$budgets = $this->_budgets->get();
|
||||
$reps = [];
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
|
||||
if (is_null($dateFormats)) {
|
||||
throw new \Firefly\Exception\FireflyException('No date formats for ' . $limit->repeat_freq);
|
||||
}
|
||||
$set = $this->_repository->get();
|
||||
$budgets = $this->_budgets->organizeByDate($set);
|
||||
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$periodOrder = $rep->startdate->format($dateFormats['group_date']);
|
||||
$period = $rep->startdate->format($dateFormats['display_date']);
|
||||
$reps[$periodOrder] = isset($reps[$periodOrder]) ? $reps[$periodOrder] : ['date' => $period];
|
||||
return View::make('budgets.indexByDate')->with('budgets', $budgets);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// put all the budgets under their respective date:
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
|
||||
$month = $rep->startdate->format($dateFormats['group_date']);
|
||||
$reps[$month]['limitrepetitions'][] = $rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
krsort($reps);
|
||||
|
||||
return View::make('budgets.indexByDate')->with('reps', $reps);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function indexByBudget()
|
||||
{
|
||||
$budgets = $this->_budgets->get();
|
||||
$today = new \Carbon\Carbon;
|
||||
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', $today);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
return View::make('budgets.create')->with('periods', $periods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'name' => Input::get('name'),
|
||||
'amount' => floatval(Input::get('amount')),
|
||||
'repeat_freq' => Input::get('period'),
|
||||
'repeats' => intval(Input::get('repeats'))
|
||||
];
|
||||
|
||||
$this->_budgets->store($data);
|
||||
Session::flash('success', 'Budget created!');
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,5 +107,24 @@ class BudgetController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'name' => Input::get('name'),
|
||||
'amount' => floatval(Input::get('amount')),
|
||||
'repeat_freq' => Input::get('period'),
|
||||
'repeats' => intval(Input::get('repeats'))
|
||||
];
|
||||
|
||||
$this->_budgets->store($data);
|
||||
Session::flash('success', 'Budget created!');
|
||||
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user