diff --git a/app/Handlers/Events/Model/BudgetLimitHandler.php b/app/Handlers/Events/Model/BudgetLimitHandler.php index d0e872dcb1..31d09c4293 100644 --- a/app/Handlers/Events/Model/BudgetLimitHandler.php +++ b/app/Handlers/Events/Model/BudgetLimitHandler.php @@ -63,18 +63,6 @@ class BudgetLimitHandler private function updateAvailableBudget(BudgetLimit $budgetLimit): void { Log::debug(sprintf('Now in updateAvailableBudget(#%d)', $budgetLimit->id)); - - // based on the view range of the user (month week quarter etc) the budget limit could - // either overlap multiple available budget periods or be contained in a single one. - // all have to be created or updated. - try { - $viewRange = app('preferences')->get('viewRange', '1M')->data; - } catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) { - $viewRange = '1M'; - } - $start = app('navigation')->startOfPeriod($budgetLimit->start_date, $viewRange); - $end = app('navigation')->startOfPeriod($budgetLimit->end_date, $viewRange); - $end = app('navigation')->endOfPeriod($end, $viewRange); $budget = Budget::find($budgetLimit->budget_id); if (null === $budget) { Log::warning('Budget is null, probably deleted, find deleted version.'); @@ -94,8 +82,23 @@ class BudgetLimitHandler return; } + // based on the view range of the user (month week quarter etc) the budget limit could + // either overlap multiple available budget periods or be contained in a single one. + // all have to be created or updated. + try { + $viewRange = app('preferences')->getForUser($user, 'viewRange', '1M')->data; + } catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) { + app('log')->error($e->getMessage()); + $viewRange = '1M'; + } + + $start = app('navigation')->startOfPeriod($budgetLimit->start_date, $viewRange); + $end = app('navigation')->startOfPeriod($budgetLimit->end_date, $viewRange); + $end = app('navigation')->endOfPeriod($end, $viewRange); + // limit period in total is: $limitPeriod = Period::make($start, $end, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE()); + app('log')->debug(sprintf('Limit period is from %s to %s', $start->format('Y-m-d'), $end->format('Y-m-d'))); // from the start until the end of the budget limit, need to loop! $current = clone $start; @@ -181,8 +184,8 @@ class BudgetLimitHandler ); // overlap in days: $limitPeriod = Period::make( - $budgetLimit->start_date, - $budgetLimit->end_date, + $budgetLimit->start_date, + $budgetLimit->end_date, precision : Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE() ); @@ -227,8 +230,8 @@ class BudgetLimitHandler return '0'; } $limitPeriod = Period::make( - $budgetLimit->start_date, - $budgetLimit->end_date, + $budgetLimit->start_date, + $budgetLimit->end_date, precision : Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE() ); diff --git a/app/Support/Cronjobs/AutoBudgetCronjob.php b/app/Support/Cronjobs/AutoBudgetCronjob.php index 6ac950a1f8..bc540fa8b2 100644 --- a/app/Support/Cronjobs/AutoBudgetCronjob.php +++ b/app/Support/Cronjobs/AutoBudgetCronjob.php @@ -78,7 +78,7 @@ class AutoBudgetCronjob extends AbstractCronjob { Log::info(sprintf('Will now fire auto budget cron job task for date "%s".', $this->date->format('Y-m-d'))); /** @var CreateAutoBudgetLimits $job */ - $job = app(CreateAutoBudgetLimits::class); + $job = app(CreateAutoBudgetLimits::class, [$this->date]); $job->setDate($this->date); $job->handle(); diff --git a/app/Support/Http/Controllers/RuleManagement.php b/app/Support/Http/Controllers/RuleManagement.php index ab382afa21..a80b8e48a8 100644 --- a/app/Support/Http/Controllers/RuleManagement.php +++ b/app/Support/Http/Controllers/RuleManagement.php @@ -54,7 +54,7 @@ trait RuleManagement 'rules.partials.action', [ 'oldAction' => $oldAction['type'], - 'oldValue' => $oldAction['value'], + 'oldValue' => $oldAction['value'] ?? '', 'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'), 'count' => $index + 1, ]