Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Removed limit repetition events #508
James Cole3f802fe27a0b
diff --git a/app/Events/StoredBudgetLimit.php b/app/Events/StoredBudgetLimit.phpdeleted file mode 100644index 65b7be0008..0000000000--- a/app/Events/StoredBudgetLimit.php+++ /dev/null@@ -1,50 +0,0 @@-<?php-/**- * StoredBudgetLimit.php- * Copyright (C) 2016 [email protected]- *- * This software may be modified and distributed under the terms of the- * Creative Commons Attribution-ShareAlike 4.0 International License.- *- * See the LICENSE file for details.- */--declare(strict_types = 1);--namespace FireflyIII\Events;--use Carbon\Carbon;-use FireflyIII\Models\BudgetLimit;-use Illuminate\Queue\SerializesModels;--/**- * Class StoredBudgetLimit- *- * @package FireflyIII\Events- */-class StoredBudgetLimit extends Event-{-- use SerializesModels;-- /** @var BudgetLimit */- public $budgetLimit;-- /** @var Carbon */- public $end; // the only variable we can't get from the budget limit (if necessary).-- /**- * BudgetLimitEvents constructor.- *- * @param BudgetLimit $budgetLimit- * @param Carbon $end- */- public function __construct(BudgetLimit $budgetLimit, Carbon $end)- {- //- $this->budgetLimit = $budgetLimit;- $this->end = $end;-- }--}diff --git a/app/Events/UpdatedBudgetLimit.php b/app/Events/UpdatedBudgetLimit.phpdeleted file mode 100644index 3642531e75..0000000000--- a/app/Events/UpdatedBudgetLimit.php+++ /dev/null@@ -1,50 +0,0 @@-<?php-/**- * UpdatedBudgetLimit.php- * Copyright (C) 2016 [email protected]- *- * This software may be modified and distributed under the terms of the- * Creative Commons Attribution-ShareAlike 4.0 International License.- *- * See the LICENSE file for details.- */--declare(strict_types = 1);--namespace FireflyIII\Events;--use Carbon\Carbon;-use FireflyIII\Models\BudgetLimit;-use Illuminate\Queue\SerializesModels;--/**- * Class UpdatedBudgetLimit- *- * @package FireflyIII\Events- */-class UpdatedBudgetLimit extends Event-{-- use SerializesModels;-- /** @var BudgetLimit */- public $budgetLimit;-- /** @var Carbon */- public $end; // the only variable we can't get from the budget limit (if necessary).-- /**- * BudgetLimitEvents constructor.- *- * @param BudgetLimit $budgetLimit- * @param Carbon $end- */- public function __construct(BudgetLimit $budgetLimit, Carbon $end)- {- //- $this->budgetLimit = $budgetLimit;- $this->end = $end;-- }--}diff --git a/app/Handlers/Events/BudgetEventHandler.php b/app/Handlers/Events/BudgetEventHandler.phpdeleted file mode 100644index 2acc5a29d9..0000000000--- a/app/Handlers/Events/BudgetEventHandler.php+++ /dev/null@@ -1,93 +0,0 @@-<?php-/**- * BudgetEventHandler.php- * Copyright (C) 2016 [email protected]- *- * This software may be modified and distributed under the terms of the- * Creative Commons Attribution-ShareAlike 4.0 International License.- *- * See the LICENSE file for details.- */--declare(strict_types = 1);--namespace FireflyIII\Handlers\Events;---use Carbon\Carbon;-use FireflyIII\Events\StoredBudgetLimit;-use FireflyIII\Events\UpdatedBudgetLimit;-use FireflyIII\Models\BudgetLimit;-use FireflyIII\Models\LimitRepetition;-use Illuminate\Database\QueryException;-use Log;--/**- * Handles budget related events.- *- * Class BudgetEventHandler- *- * @package FireflyIII\Handlers\Events- */-class BudgetEventHandler-{- /**- * This method creates a new budget limit repetition when a new budget limit has been created.- *- * @param StoredBudgetLimit $budgetLimitEvent- *- * @return bool- */- public function storeRepetition(StoredBudgetLimit $budgetLimitEvent): bool- {- return $this->processRepetitionChange($budgetLimitEvent->budgetLimit, $budgetLimitEvent->end);- }-- /**- * Updates, if present the budget limit repetition part of a budget limit.- *- * @param UpdatedBudgetLimit $budgetLimitEvent- *- * @return bool- */- public function updateRepetition(UpdatedBudgetLimit $budgetLimitEvent): bool- {- return $this->processRepetitionChange($budgetLimitEvent->budgetLimit, $budgetLimitEvent->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;- }-}diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex 61e41f8342..19d79a9fd6 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -45,16 +45,6 @@ class EventServiceProvider extends ServiceProvider'FireflyIII\Events\RequestedNewPassword' => [ // is a User related event.'FireflyIII\Handlers\Events\UserEventHandler@sendNewPassword',],- 'FireflyIII\Events\StoredBudgetLimit' => // is a Budget related event.- [- 'FireflyIII\Handlers\Events\BudgetEventHandler@storeRepetition',- ],-- 'FireflyIII\Events\UpdatedBudgetLimit' => // is a Budget related event.- [- 'FireflyIII\Handlers\Events\BudgetEventHandler@updateRepetition',- ],-'FireflyIII\Events\StoredTransactionJournal' => // is a Transaction Journal related event.['FireflyIII\Handlers\Events\StoredJournalEventHandler@scanBills',