mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-17 03:49:22 +00:00
Add amount event.
This commit is contained in:
@@ -78,9 +78,7 @@ class GroupUpdateService
|
||||
if (1 === count($transactions) && 1 === $transactionGroup->transactionJournals()->count()) {
|
||||
/** @var TransactionJournal $first */
|
||||
$first = $transactionGroup->transactionJournals()->first();
|
||||
Log::debug(
|
||||
sprintf('Will now update journal #%d (only journal in group #%d)', $first->id, $transactionGroup->id)
|
||||
);
|
||||
Log::debug(sprintf('Will now update journal #%d (only journal in group #%d)', $first->id, $transactionGroup->id));
|
||||
$this->updateTransactionJournal($transactionGroup, $first, reset($transactions));
|
||||
$transactionGroup->touch();
|
||||
$transactionGroup->refresh();
|
||||
|
||||
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidDateException;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
@@ -47,6 +46,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Support\JournalServiceTrait;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use FireflyIII\Validation\AccountValidator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -66,9 +66,11 @@ class JournalUpdateService
|
||||
private array $data;
|
||||
private ?Account $destinationAccount = null;
|
||||
private ?Transaction $destinationTransaction = null;
|
||||
private array $metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||
'invoice_date', ];
|
||||
private array $metaString = [
|
||||
private array $metaDate
|
||||
= ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||
'invoice_date',];
|
||||
private array $metaString
|
||||
= [
|
||||
'sepa_cc',
|
||||
'sepa_ct_op',
|
||||
'sepa_ct_id',
|
||||
@@ -214,7 +216,7 @@ class JournalUpdateService
|
||||
|
||||
private function hasFields(array $fields): bool
|
||||
{
|
||||
return array_any($fields, fn ($field): bool => array_key_exists($field, $this->data));
|
||||
return array_any($fields, fn($field): bool => array_key_exists($field, $this->data));
|
||||
}
|
||||
|
||||
private function getOriginalSourceAccount(): Account
|
||||
@@ -492,15 +494,7 @@ class JournalUpdateService
|
||||
Log::debug(sprintf('Create date value from string "%s".', $value));
|
||||
$this->transactionJournal->date_tz = $value->format('e');
|
||||
}
|
||||
event(
|
||||
new TriggeredAuditLog(
|
||||
$this->transactionJournal->user,
|
||||
$this->transactionJournal,
|
||||
sprintf('update_%s', $fieldName),
|
||||
$this->transactionJournal->{$fieldName}, // @phpstan-ignore-line
|
||||
$value
|
||||
)
|
||||
);
|
||||
event(new TriggeredAuditLog($this->transactionJournal->user, $this->transactionJournal, sprintf('update_%s', $fieldName), $this->transactionJournal->{$fieldName}, $value));
|
||||
|
||||
$this->transactionJournal->{$fieldName} = $value; // @phpstan-ignore-line
|
||||
Log::debug(sprintf('Updated %s', $fieldName));
|
||||
@@ -599,7 +593,7 @@ class JournalUpdateService
|
||||
if ($this->hasFields([$field])) {
|
||||
try {
|
||||
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
|
||||
} catch (InvalidDateException|InvalidFormatException $e) { // @phpstan-ignore-line
|
||||
} catch (InvalidDateException | InvalidFormatException $e) { // @phpstan-ignore-line
|
||||
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));
|
||||
|
||||
return;
|
||||
@@ -671,6 +665,7 @@ class JournalUpdateService
|
||||
$origSourceTransaction->balance_dirty = true;
|
||||
$origSourceTransaction->save();
|
||||
$destTransaction = $this->getDestinationTransaction();
|
||||
$originalAmount = $destTransaction->amount;
|
||||
$destTransaction->amount = app('steam')->positive($amount);
|
||||
$destTransaction->balance_dirty = true;
|
||||
$destTransaction->save();
|
||||
@@ -678,6 +673,20 @@ class JournalUpdateService
|
||||
$this->sourceTransaction->refresh();
|
||||
$this->destinationTransaction->refresh();
|
||||
Log::debug(sprintf('Updated amount to "%s"', $amount));
|
||||
|
||||
event(new TriggeredAuditLog($this->transactionGroup->user, $this->transactionGroup, 'update_amount',
|
||||
[
|
||||
'currency_symbol' => $destTransaction->transactionCurrency->symbol,
|
||||
'decimal_places' => $destTransaction->transactionCurrency->decimal_places,
|
||||
'amount' => $originalAmount,
|
||||
],
|
||||
[
|
||||
'currency_symbol' => $destTransaction->transactionCurrency->symbol,
|
||||
'decimal_places' => $destTransaction->transactionCurrency->decimal_places,
|
||||
'amount' => $value,
|
||||
]
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
private function updateForeignAmount(): void
|
||||
|
||||
Reference in New Issue
Block a user