From a00f46faa9ccb7408741683693e7093b1990e153 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 14 Mar 2020 15:18:32 +0100 Subject: [PATCH] Also create initial budget limit. --- app/Repositories/Budget/BudgetRepository.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index ab32906687..84a7608399 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -321,6 +321,23 @@ class BudgetRepository implements BudgetRepositoryInterface $autoBudget->period = $data['auto_budget_period'] ?? 'monthly'; $autoBudget->save(); + // create initial budget limit. + $today = new Carbon; + $start = app('navigation')->startOfPeriod($today, $autoBudget->period); + $end = app('navigation')->startOfPeriod($start, $autoBudget->period); + + $limitRepos = app(BudgetLimitRepositoryInterface::class); + $limitRepos->setUser($this->user); + $limitRepos->store( + [ + 'budget_id' => $newBudget->id, + 'transaction_currency_id' => $autoBudget->transaction_currency_id, + 'start_date' => $start->format('Y-m-d'), + 'end_date' => $end->format('Y-m-d'), + 'amount' => $autoBudget->amount, + ] + ); + return $newBudget; }