processRepetitionChange($event->budgetLimit, $event->end); } /** * Updates, if present the budget limit repetition part of a budget limit. * * @param UpdatedBudgetLimit $event * * @return bool */ public function updateRepetition(UpdatedBudgetLimit $event): bool { return $this->processRepetitionChange($event->budgetLimit, $event->end); } /** * @param BudgetLimit $budgetLimit * @param Carbon $date * * @return bool */ private function processRepetitionChange(BudgetLimit $budgetLimit, Carbon $date):bool { $set = $budgetLimit->limitrepetitions() ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) ->where('enddate', $date->format('Y-m-d 00:00:00')) ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; $repetition->enddate = $date; $repetition->amount = $budgetLimit->amount; $repetition->budgetLimit()->associate($budgetLimit); try { $repetition->save(); } catch (QueryException $e) { Log::error('Trying to save new LimitRepetition failed: ' . $e->getMessage()); } } if ($set->count() == 1) { $repetition = $set->first(); $repetition->amount = $budgetLimit->amount; $repetition->save(); } return true; } }