Various report updates and code cleanup.

This commit is contained in:
James Cole
2016-12-04 18:02:19 +01:00
parent 905a2432c6
commit f4b9b7ae84
32 changed files with 592 additions and 450 deletions

View File

@@ -252,6 +252,48 @@ class BudgetController extends Controller
return Response::json($data);
}
/**
* @param BudgetRepositoryInterface $repository
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return \Illuminate\Http\JsonResponse
*/
public function periodNoBudget(BudgetRepositoryInterface $repository, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
$cache->addProperty('no-budget');
$cache->addProperty('period');
if ($cache->has()) {
return Response::json($cache->get());
}
// the expenses:
$periods = Navigation::listOfPeriods($start, $end);
$entries = $repository->getNoBudgetPeriodReport($accounts, $start, $end);
// join them:
$result = [];
foreach (array_keys($periods) as $period) {
$nice = $periods[$period];
$result[$nice] = [
'spent' => isset($entries['entries'][$period]) ? $entries['entries'][$period] : '0',
];
}
$data = $this->generator->periodNoBudget($result);
$cache->store($data);
return Response::json($data);
}
/**
* @param Collection $repetitions
* @param Budget $budget