diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index 686cdc9760..b683171ae8 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -21,6 +21,7 @@ use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; +use Log; use Navigation; /** @@ -40,7 +41,16 @@ class CategoryController extends Controller */ public function categoryPeriodReport(Carbon $start, Carbon $end, Collection $accounts) { + $cache = new CacheProperties; + $cache->addProperty($start); + $cache->addProperty($end); + $cache->addProperty('category-period-report'); + $cache->addProperty($accounts->pluck('id')->toArray()); + if ($cache->has()) { + Log::debug('Return report from cache'); + return $cache->get(); + } /** @var CategoryRepositoryInterface $repository */ $repository = app(CategoryRepositoryInterface::class); $categories = $repository->getCategories(); @@ -50,6 +60,8 @@ class CategoryController extends Controller $result = view('reports.partials.category-period', compact('categories', 'periods', 'report'))->render(); + $cache->store($result); + return $result; } @@ -90,23 +102,24 @@ class CategoryController extends Controller */ private function filterCategoryPeriodReport(array $data): array { - foreach ($data as $key => $set) { - /** - * @var int $categoryId - * @var array $set - */ - foreach ($set as $categoryId => $info) { + /** + * @var string $type + * @var array $report + */ + foreach ($data as $type => $report) { + foreach ($report as $categoryId => $set) { $sum = '0'; - foreach ($info['entries'] as $amount) { + foreach ($set['entries'] as $amount) { $sum = bcadd($amount, $sum); } - $data[$key][$categoryId]['sum'] = $sum; + $data[$type][$categoryId]['sum'] = $sum; if (bccomp('0', $sum) === 0) { - unset($data[$key][$categoryId]); + unset($data[$type][$categoryId]); } } } + return $data; } diff --git a/resources/views/reports/partials/category-period.twig b/resources/views/reports/partials/category-period.twig index 17368414ed..77ed5eddb8 100644 --- a/resources/views/reports/partials/category-period.twig +++ b/resources/views/reports/partials/category-period.twig @@ -19,42 +19,57 @@
{% for category in categories %} {% if report.income[category.id] or report.expense[category.id] %} -