mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Expand piggy bank events
This commit is contained in:
@@ -81,7 +81,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
|
|
||||||
if ($source->account_id === $piggyBank->account_id) {
|
if ($source->account_id === $piggyBank->account_id) {
|
||||||
app('log')->debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
|
app('log')->debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
|
||||||
$this->removeAmount($piggyBank, $journalObj, $destination->amount);
|
$this->removeAmount($piggyBank, $journal, $journalObj, $destination->amount);
|
||||||
|
|
||||||
event(
|
event(
|
||||||
new TriggeredAuditLog(
|
new TriggeredAuditLog(
|
||||||
@@ -102,7 +102,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
}
|
}
|
||||||
if ($destination->account_id === $piggyBank->account_id) {
|
if ($destination->account_id === $piggyBank->account_id) {
|
||||||
app('log')->debug('Piggy bank account is linked to source, so add amount to piggy bank.');
|
app('log')->debug('Piggy bank account is linked to source, so add amount to piggy bank.');
|
||||||
$this->addAmount($piggyBank, $journalObj, $destination->amount);
|
$this->addAmount($piggyBank,$journal, $journalObj, $destination->amount);
|
||||||
|
|
||||||
event(
|
event(
|
||||||
new TriggeredAuditLog(
|
new TriggeredAuditLog(
|
||||||
@@ -115,6 +115,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||||
'amount' => $destination->amount,
|
'amount' => $destination->amount,
|
||||||
'piggy' => $piggyBank->name,
|
'piggy' => $piggyBank->name,
|
||||||
|
'piggy_id' => $piggyBank->id,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -138,7 +139,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
return $user->piggyBanks()->where('piggy_banks.name', $name)->first();
|
return $user->piggyBanks()->where('piggy_banks.name', $name)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeAmount(PiggyBank $piggyBank, TransactionJournal $journal, string $amount): void
|
private function removeAmount(PiggyBank $piggyBank, array $array, TransactionJournal $journal, string $amount): void
|
||||||
{
|
{
|
||||||
$repository = app(PiggyBankRepositoryInterface::class);
|
$repository = app(PiggyBankRepositoryInterface::class);
|
||||||
$repository->setUser($journal->user);
|
$repository->setUser($journal->user);
|
||||||
@@ -154,6 +155,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
// if amount is zero, stop.
|
// if amount is zero, stop.
|
||||||
if (0 === bccomp('0', $amount)) {
|
if (0 === bccomp('0', $amount)) {
|
||||||
app('log')->warning('Amount left is zero, stop.');
|
app('log')->warning('Amount left is zero, stop.');
|
||||||
|
event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_remove_zero_piggy', ['name' => $piggyBank->name])));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,6 +163,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
// make sure we can remove amount:
|
// make sure we can remove amount:
|
||||||
if (false === $repository->canRemoveAmount($piggyBank, $amount)) {
|
if (false === $repository->canRemoveAmount($piggyBank, $amount)) {
|
||||||
app('log')->warning(sprintf('Cannot remove %s from piggy bank.', $amount));
|
app('log')->warning(sprintf('Cannot remove %s from piggy bank.', $amount));
|
||||||
|
event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_remove_from_piggy', ['amount' => $amount,'name' => $piggyBank->name])));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -169,7 +172,7 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
$repository->removeAmount($piggyBank, $amount, $journal);
|
$repository->removeAmount($piggyBank, $amount, $journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addAmount(PiggyBank $piggyBank, TransactionJournal $journal, string $amount): void
|
private function addAmount(PiggyBank $piggyBank, array $array, TransactionJournal $journal, string $amount): void
|
||||||
{
|
{
|
||||||
$repository = app(PiggyBankRepositoryInterface::class);
|
$repository = app(PiggyBankRepositoryInterface::class);
|
||||||
$repository->setUser($journal->user);
|
$repository->setUser($journal->user);
|
||||||
@@ -190,13 +193,14 @@ class UpdatePiggybank implements ActionInterface
|
|||||||
// if amount is zero, stop.
|
// if amount is zero, stop.
|
||||||
if (0 === bccomp('0', $amount)) {
|
if (0 === bccomp('0', $amount)) {
|
||||||
app('log')->warning('Amount left is zero, stop.');
|
app('log')->warning('Amount left is zero, stop.');
|
||||||
|
event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_add_zero_piggy', ['name' => $piggyBank->name])));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we can add amount:
|
// make sure we can add amount:
|
||||||
if (false === $repository->canAddAmount($piggyBank, $amount)) {
|
if (false === $repository->canAddAmount($piggyBank, $amount)) {
|
||||||
app('log')->warning(sprintf('Cannot add %s to piggy bank.', $amount));
|
app('log')->warning(sprintf('Cannot add %s to piggy bank.', $amount));
|
||||||
|
event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_add_to_piggy', ['amount' => $amount,'name' => $piggyBank->name])));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -71,4 +71,8 @@ return [
|
|||||||
'cannot_find_category' => 'Firefly III can\'t find category ":name"',
|
'cannot_find_category' => 'Firefly III can\'t find category ":name"',
|
||||||
'cannot_set_budget' => 'Firefly III can\'t set budget ":name" to a transaction of type ":type"',
|
'cannot_set_budget' => 'Firefly III can\'t set budget ":name" to a transaction of type ":type"',
|
||||||
'journal_invalid_amount' => 'Firefly III can\'t set amount ":amount" because it is not a valid number.',
|
'journal_invalid_amount' => 'Firefly III can\'t set amount ":amount" because it is not a valid number.',
|
||||||
|
'cannot_remove_zero_piggy' => 'Cannot remove zero amount from piggy bank ":name"',
|
||||||
|
'cannot_remove_from_piggy' => 'Cannot remove ":amount" from piggy bank ":name"',
|
||||||
|
'cannot_add_zero_piggy' => 'Cannot add zero amount to piggy bank ":name"',
|
||||||
|
'cannot_add_to_piggy' => 'Cannot add ":amount" to piggy bank ":name"',
|
||||||
];
|
];
|
||||||
|
@@ -93,10 +93,10 @@
|
|||||||
<code>{{ logEntry.after }}</code>
|
<code>{{ logEntry.after }}</code>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'add_to_piggy' == logEntry.action %}
|
{% if 'add_to_piggy' == logEntry.action %}
|
||||||
{{ trans('firefly.ale_action_log_add', {amount: formatAmountBySymbol(logEntry.after.amount, logEntry.after.currency_symbol, logEntry.after.decimal_places, true), name: logEntry.after.name})|raw }}
|
{{ trans('firefly.ale_action_log_add', {amount: formatAmountBySymbol(logEntry.after.amount, logEntry.after.currency_symbol, logEntry.after.decimal_places, true), name: logEntry.after.piggy})|raw }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'remove_from_piggy' == logEntry.action %}
|
{% if 'remove_from_piggy' == logEntry.action %}
|
||||||
{{ trans('firefly.ale_action_log_remove', {amount: formatAmountBySymbol(logEntry.after.amount, logEntry.after.currency_symbol, logEntry.after.decimal_places, true), name: logEntry.after.name})|raw }}
|
{{ trans('firefly.ale_action_log_remove', {amount: formatAmountBySymbol(logEntry.after.amount, logEntry.after.currency_symbol, logEntry.after.decimal_places, true), name: logEntry.after.piggy})|raw }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user