mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +00:00
Include chart with report
This commit is contained in:
@@ -152,6 +152,43 @@ class CategoryController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*/
|
||||
public function reportPeriod(CRI $repository, Category $category, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('category-period-chart');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
$cache->addProperty($category);
|
||||
if ($cache->has()) {
|
||||
|
||||
return $cache->get();
|
||||
}
|
||||
$report = $repository->getCategoryPeriodReport(new Collection([$category]), $accounts, $start, $end, true);
|
||||
$periods = Navigation::listOfPeriods($start, $end);
|
||||
|
||||
|
||||
// join them:
|
||||
$result = [];
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$nice = $periods[$period];
|
||||
$result[$nice] = [
|
||||
'earned' => $report['income'][$category->id]['entries'][$period] ?? '0',
|
||||
'spent' => $report['expense'][$category->id]['entries'][$period] ?? '0',
|
||||
];
|
||||
}
|
||||
$data = $this->generator->reportPeriod($result);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
|
Reference in New Issue
Block a user