From 40d8e7d1ad8826ea0022e4ee292781fa9d2225e4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 24 Apr 2015 12:06:13 +0200 Subject: [PATCH] Fixed a bug where transfers away from a piggy bank's account would not properly reflect the piggy bank. --- .../Events/ConnectJournalToPiggyBank.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index 81152e3d97..7278d49691 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -65,6 +65,22 @@ class ConnectJournalToPiggyBank } Log::debug('Found rep! ' . $repetition->id); + + /* + * Add amount when + */ + /** @var Transaction $transaction */ + foreach ($journal->transactions()->get() as $transaction) { + if ($transaction->account_id == $piggyBank->account_id) { + if ($transaction->amount < 0) { + $amount = $amount * -1; + Log::debug('Transaction is away from piggy, so amount becomes ' . $amount); + } else { + Log::debug('Transaction is to from piggy, so amount stays ' . $amount); + } + } + } + $repetition->currentamount += $amount; $repetition->save();