From af466a1d752c6ab2d457c0b2626dc8230cb17a99 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 5 Jan 2017 08:33:22 +0100 Subject: [PATCH] Refactor code to verify these methods work #524 --- app/Http/Controllers/Chart/CategoryController.php | 9 +++++---- app/Http/Controllers/Report/CategoryController.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 6ba325636a..15c807412f 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -90,7 +90,7 @@ class CategoryController extends Controller while ($start <= $end) { $currentEnd = Navigation::endOfPeriod($start, $range); - $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $currentEnd); + $spent = $repository->spentInPeriodCollector(new Collection([$category]), $accounts, $start, $currentEnd); $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $currentEnd); $label = Navigation::periodShow($start, $range); $chartData[0]['entries'][$label] = bcmul($spent, '-1'); @@ -143,12 +143,13 @@ class CategoryController extends Controller $accounts = $accountRepository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); /** @var Category $category */ foreach ($categories as $category) { - $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end); + $spent = $repository->spentInPeriodCollector(new Collection([$category]), $accounts, $start, $end); if (bccomp($spent, '0') === -1) { $chartData[$category->name] = bcmul($spent, '-1'); } } - $chartData[strval(trans('firefly.no_category'))] = bcmul($repository->spentInPeriodWithoutCategory(new Collection, $start, $end), '-1'); + + $chartData[strval(trans('firefly.no_category'))] = bcmul($repository->spentInPeriodWithoutCategoryCollector(new Collection, $start, $end), '-1'); // sort arsort($chartData); @@ -314,7 +315,7 @@ class CategoryController extends Controller ]; while ($start <= $end) { - $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start); + $spent = $repository->spentInPeriodCollector(new Collection([$category]), $accounts, $start, $start); $earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start); $label = Navigation::periodShow($start, '1D'); diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index 730deeaece..2426dd6ea6 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -123,7 +123,7 @@ class CategoryController extends Controller $report = []; /** @var Category $category */ foreach ($categories as $category) { - $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end); + $spent = $repository->spentInPeriodCollector(new Collection([$category]), $accounts, $start, $end); if (bccomp($spent, '0') !== 0) { $report[$category->id] = ['name' => $category->name, 'spent' => $spent]; }