From c619b8730b5d421160277cc9e65049c4a3fd7e9a Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 7 Jun 2016 12:22:46 +0200 Subject: [PATCH] Implemented #264 --- app/Http/Controllers/BudgetController.php | 2 ++ app/Repositories/Budget/BudgetRepository.php | 12 ++++++++++++ .../Budget/BudgetRepositoryInterface.php | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index a858e82252..e6f517c9a8 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -164,6 +164,8 @@ class BudgetController extends Controller */ public function index(BudgetRepositoryInterface $repository, AccountCrudInterface $crud) { + $repository->cleanupBudgets(); + $budgets = $repository->getActiveBudgets(); $inactive = $repository->getInactiveBudgets(); $spent = '0'; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 04d63893a5..b104c8f292 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -156,6 +156,18 @@ class BudgetRepository implements BudgetRepositoryInterface return $set; } + /** + * @return bool + */ + public function cleanupBudgets(): bool + { + // delete limits with amount 0: + BudgetLimit::where('amount', 0)->delete(); + + return true; + + } + /** * @return Collection */ diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 6feeb5336c..31bf8d4ed2 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -111,6 +111,11 @@ interface BudgetRepositoryInterface */ public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end) : string; + /** + * @return bool + */ + public function cleanupBudgets(): bool; + /** * @param array $data *