mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix issue with piggies.
This commit is contained in:
parent
e53eb48ecc
commit
c0099262ea
@ -88,14 +88,15 @@ trait ModifiesPiggyBanks
|
||||
*/
|
||||
public function canAddAmount(PiggyBank $piggyBank, string $amount): bool
|
||||
{
|
||||
$leftOnAccount = $this->leftOnAccount($piggyBank, today(config('app.timezone')));
|
||||
$today = today(config('app.timezone'));
|
||||
$leftOnAccount = $this->leftOnAccount($piggyBank, $today);
|
||||
$savedSoFar = (string)$this->getRepetition($piggyBank)->currentamount;
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
|
||||
Log::debug(sprintf('Left on account: %s', $leftOnAccount));
|
||||
Log::debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d')));
|
||||
Log::debug(sprintf('Saved so far: %s', $savedSoFar));
|
||||
Log::debug(sprintf('Left to save: %s', $leftToSave));
|
||||
Log::debug(sprintf('Maximum amount: %s', $maxAmount));
|
||||
|
@ -57,12 +57,18 @@ class UpdatePiggybank implements ActionInterface
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
Log::debug(sprintf('Triggered rule action UpdatePiggybank on journal #%d', $journal['transaction_journal_id']));
|
||||
|
||||
// refresh the transaction type.
|
||||
$user = User::find($journal['user_id']);
|
||||
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
|
||||
$type = TransactionType::find((int)$journalObj->transaction_type_id);
|
||||
$journal['transaction_type_type'] = $type->type;
|
||||
|
||||
if (TransactionType::TRANSFER !== $journal['transaction_type_type']) {
|
||||
Log::info(sprintf('Journal #%d is a "%s" so skip this action.', $journal['transaction_journal_id'], $journal['transaction_type_type']));
|
||||
|
||||
return false;
|
||||
}
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
$piggyBank = $this->findPiggybank($user);
|
||||
if (null === $piggyBank) {
|
||||
@ -92,7 +98,7 @@ class UpdatePiggybank implements ActionInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
Log::info('Piggy bank is not linked to source or destination, so no action will be taken.');
|
||||
Log::info(sprintf('Piggy bank is not linked to source ("#%d") or destination ("#%d"), so no action will be taken.', $source->account_id, $destination->account_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user