Fix category report.

This commit is contained in:
James Cole 2016-12-06 10:42:13 +01:00
parent 2e1f31a7f8
commit fbbbcc4e74
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -124,10 +124,21 @@ class CategoryController extends Controller
$report = [];
/** @var Category $category */
foreach ($categories as $category) {
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
$report[$category->id] = ['name' => $category->name, 'spent' => $spent];
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
if (bccomp($spent, '0') !== 0) {
$report[$category->id] = ['name' => $category->name, 'spent' => $spent];
}
}
// sort the result
// Obtain a list of columns
$sum = [];
foreach ($report as $categoryId => $row) {
$sum[$categoryId] = floatval($row['spent']);
}
array_multisort($sum, SORT_DESC, $report);
$result = view('reports.partials.categories', compact('report'))->render();
$cache->store($result);