diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index fd56bead5f..067573c4f7 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -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);