mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +00:00
Filter empty budgets.
This commit is contained in:
@@ -199,10 +199,11 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function year(BudgetRepositoryInterface $repository, $year, $shared = false)
|
public function year(BudgetRepositoryInterface $repository, $year, $shared = false)
|
||||||
{
|
{
|
||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
$shared = $shared == 'shared' ? true : false;
|
$shared = $shared == 'shared' ? true : false;
|
||||||
$budgets = $repository->getBudgets();
|
$allBudgets = $repository->getBudgets();
|
||||||
|
$budgets = new Collection;
|
||||||
|
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
@@ -214,6 +215,15 @@ class BudgetController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filter empty budgets:
|
||||||
|
|
||||||
|
foreach ($allBudgets as $budget) {
|
||||||
|
$spent = $repository->spentInPeriodCorrected($budget, $start, $end, $shared);
|
||||||
|
if ($spent != 0) {
|
||||||
|
$budgets->push($budget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
|
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
@@ -225,13 +235,13 @@ class BudgetController extends Controller
|
|||||||
// each budget, fill the row:
|
// each budget, fill the row:
|
||||||
foreach ($budgets as $budget) {
|
foreach ($budgets as $budget) {
|
||||||
$spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
|
$spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
|
||||||
$row[] = $spent*-1;
|
$row[] = $spent * -1;
|
||||||
}
|
}
|
||||||
$entries->push($row);
|
$entries->push($row);
|
||||||
$start->endOfMonth()->addDay();
|
$start->endOfMonth()->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->generator->year($budgets, $entries);
|
$data = $this->generator->year($allBudgets, $entries);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
Reference in New Issue
Block a user