mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix piggy action.
This commit is contained in:
parent
c976149bf1
commit
cb4e5a80b2
@ -83,7 +83,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
Log::debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
|
Log::debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
|
||||||
|
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
|
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
|
||||||
/** @var Transaction $destination */
|
/** @var Transaction $destination */
|
||||||
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
|
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
|
||||||
|
|
||||||
@ -199,12 +199,18 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
$repository->setUser($journal->user);
|
$repository->setUser($journal->user);
|
||||||
|
|
||||||
// how much can we add to the piggy bank?
|
// how much can we add to the piggy bank?
|
||||||
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
|
if (0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||||
Log::debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
|
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
|
||||||
|
Log::debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
|
||||||
|
|
||||||
|
// update amount to fit:
|
||||||
|
$amount = -1 === bccomp($amount, $toAdd) ? $amount : $toAdd;
|
||||||
|
Log::debug(sprintf('Amount is now %s', $amount));
|
||||||
|
}
|
||||||
|
if (0 === bccomp($piggyBank->targetamount, '0')) {
|
||||||
|
Log::debug('Target amount is zero, can add anything.');
|
||||||
|
}
|
||||||
|
|
||||||
// update amount to fit:
|
|
||||||
$amount = -1 === bccomp($amount, $toAdd) ? $amount : $toAdd;
|
|
||||||
Log::debug(sprintf('Amount is now %s', $amount));
|
|
||||||
|
|
||||||
// if amount is zero, stop.
|
// if amount is zero, stop.
|
||||||
if (0 === bccomp('0', $amount)) {
|
if (0 === bccomp('0', $amount)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user