diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index e281f72c43..7b72fcf652 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -142,6 +142,9 @@ trait ModifiesPiggyBanks */ public function createEvent(PiggyBank $piggyBank, string $amount): PiggyBankEvent { + if (0 === bccomp('0', $amount)) { + return new PiggyBankEvent; + } /** @var PiggyBankEvent $event */ $event = PiggyBankEvent::create(['date' => Carbon::now(), 'amount' => $amount, 'piggy_bank_id' => $piggyBank->id]); @@ -219,11 +222,12 @@ trait ModifiesPiggyBanks if (1 === bccomp($amount, $max)) { $amount = $max; } + $difference = bcsub($amount, $repetition->currentamount); $repetition->currentamount = $amount; $repetition->save(); // create event - $this->createEvent($piggyBank, $amount); + $this->createEvent($piggyBank, $difference); return $piggyBank; } @@ -343,4 +347,4 @@ trait ModifiesPiggyBanks return true; } -} \ No newline at end of file +}