First calculations for multi-year budget chart.

This commit is contained in:
James Cole 2015-12-15 12:52:42 +01:00
parent 36d7a02994
commit 69553b138b
2 changed files with 19 additions and 2 deletions

View File

@ -47,14 +47,25 @@ class BudgetController extends Controller
public function multiYear(BudgetRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
{
$currentStart = clone $start;
$collection = new Collection;
while ($currentStart < $end) {
$currentEnd = clone $currentStart;
$currentEnd->endOfYear();
//echo 'now for '.$currentStart->format('Ymd').' to '.$currentEnd->format('Ymd').'<br>';
//epository->balanceInPeriod()
echo 'now for ' . $currentStart->format('Ymd') . ' to ' . $currentEnd->format('Ymd') . '<br>';
/** @var Budget $budget */
foreach ($budgets as $budget) {
if (is_null($budget->id)) {
$name = trans('firefly.noBudget');
$sum = $repository->getWithoutBudgetSum($currentStart, $currentEnd);
} else {
$name = $budget->name;
$sum = $repository->balanceInPeriodForList($budget, $currentStart, $currentEnd, $accounts);
}
echo $name.': '.$sum.'<br>';
}
// do something for all budgets.
// jump to next year.

View File

@ -60,6 +60,12 @@ Route::bind(
->whereIn('budgets.id', $ids)
->where('budgets.user_id', Auth::user()->id)
->get(['budgets.*']);
// add empty budget if applicable.
if(in_array('0', $ids)) {
$object->push(new Budget);
}
if ($object->count() > 0) {
return $object;
}