[ 'FireflyIII\Handlers\Events\ScanForBillsAfterUpdate', 'FireflyIII\Handlers\Events\UpdateJournalConnection', 'FireflyIII\Handlers\Events\FireRulesForUpdate', ], 'FireflyIII\Events\TransactionJournalStored' => [ 'FireflyIII\Handlers\Events\ScanForBillsAfterStore', 'FireflyIII\Handlers\Events\ConnectJournalToPiggyBank', 'FireflyIII\Handlers\Events\FireRulesForStore', ], 'Illuminate\Auth\Events\Logout' => [ 'FireflyIII\Handlers\Events\UserEventListener@onUserLogout', ], 'FireflyIII\Events\UserRegistration' => [ 'FireflyIII\Handlers\Events\SendRegistrationMail', 'FireflyIII\Handlers\Events\AttachUserRole', 'FireflyIII\Handlers\Events\UserConfirmation@sendConfirmation', ], 'FireflyIII\Events\ResendConfirmation' => [ 'FireflyIII\Handlers\Events\UserConfirmation@resendConfirmation', ], ]; /** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); $this->registerDeleteEvents(); $this->registerCreateEvents(); BudgetLimit::saved( function (BudgetLimit $budgetLimit) { $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); $set = $budgetLimit->limitrepetitions() ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) ->where('enddate', $end->format('Y-m-d 00:00:00')) ->get(); if ($set->count() == 0) { $repetition = new LimitRepetition; $repetition->startdate = $budgetLimit->startdate; $repetition->enddate = $end; $repetition->amount = $budgetLimit->amount; $repetition->budgetLimit()->associate($budgetLimit); try { $repetition->save(); } catch (QueryException $e) { Log::error('Trying to save new LimitRepetition failed: ' . $e->getMessage()); } } else { if ($set->count() == 1) { $repetition = $set->first(); $repetition->amount = $budgetLimit->amount; $repetition->save(); } } } ); // } /** * */ protected function registerCreateEvents() { // move this routine to a filter // in case of repeated piggy banks and/or other problems. PiggyBank::created( function (PiggyBank $piggyBank) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate; $repetition->targetdate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate; $repetition->currentamount = 0; $repetition->save(); } ); } /** * */ protected function registerDeleteEvents() { TransactionJournal::deleted( function (TransactionJournal $journal) { /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { $transaction->delete(); } } ); Account::deleted( function (Account $account) { /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { $journal = $transaction->transactionJournal()->first(); $journal->delete(); } } ); } }