This commit is contained in:
James Cole
2025-10-01 20:28:24 +02:00
parent 5637573fd0
commit 87d3d14504
4 changed files with 16 additions and 16 deletions

View File

@@ -68,10 +68,6 @@ class UpdateController extends Controller
$data = $request->getAll(); $data = $request->getAll();
$piggyBank = $this->repository->update($piggyBank, $data); $piggyBank = $this->repository->update($piggyBank, $data);
if (array_key_exists('current_amount', $data) && '' !== $data['current_amount']) {
$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);
}
// enrich // enrich
/** @var User $admin */ /** @var User $admin */
$admin = auth()->user(); $admin = auth()->user();

View File

@@ -64,7 +64,7 @@ class UpdateRequest extends FormRequest
*/ */
public function getAll(): array public function getAll(): array
{ {
app('log')->debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$this->integerFields = ['order', 'currency_id', 'foreign_currency_id', 'transaction_journal_id', 'source_id', 'destination_id', 'budget_id', 'category_id', 'bill_id', 'recurrence_id']; $this->integerFields = ['order', 'currency_id', 'foreign_currency_id', 'transaction_journal_id', 'source_id', 'destination_id', 'budget_id', 'category_id', 'bill_id', 'recurrence_id'];
$this->dateFields = ['date', 'interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date']; $this->dateFields = ['date', 'interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
$this->textareaFields = ['notes']; $this->textareaFields = ['notes'];
@@ -97,7 +97,7 @@ class UpdateRequest extends FormRequest
*/ */
private function getTransactionData(): array private function getTransactionData(): array
{ {
app('log')->debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$return = []; $return = [];
/** @var null|array $transactions */ /** @var null|array $transactions */
@@ -181,7 +181,7 @@ class UpdateRequest extends FormRequest
private function getDateData(array $current, array $transaction): array private function getDateData(array $current, array $transaction): array
{ {
foreach ($this->dateFields as $fieldName) { foreach ($this->dateFields as $fieldName) {
app('log')->debug(sprintf('Now at date field %s', $fieldName)); Log::debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) { if (array_key_exists($fieldName, $transaction)) {
Log::debug(sprintf('New value: "%s"', $transaction[$fieldName])); Log::debug(sprintf('New value: "%s"', $transaction[$fieldName]));
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]); $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
@@ -247,7 +247,7 @@ class UpdateRequest extends FormRequest
*/ */
public function rules(): array public function rules(): array
{ {
app('log')->debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$validProtocols = config('firefly.valid_url_protocols'); $validProtocols = config('firefly.valid_url_protocols');
return [ return [
@@ -330,7 +330,7 @@ class UpdateRequest extends FormRequest
*/ */
public function withValidator(Validator $validator): void public function withValidator(Validator $validator): void
{ {
app('log')->debug('Now in withValidator'); Log::debug('Now in withValidator');
/** @var TransactionGroup $transactionGroup */ /** @var TransactionGroup $transactionGroup */
$transactionGroup = $this->route()->parameter('transactionGroup'); $transactionGroup = $this->route()->parameter('transactionGroup');

View File

@@ -242,7 +242,7 @@ class PiggyBankFactory
} }
} }
} }
Log::debug('Looping all accounts.');
/** @var array $info */ /** @var array $info */
foreach ($accounts as $info) { foreach ($accounts as $info) {
$account = $this->accountRepository->find((int)($info['account_id'] ?? 0)); $account = $this->accountRepository->find((int)($info['account_id'] ?? 0));
@@ -251,6 +251,7 @@ class PiggyBankFactory
continue; continue;
} }
Log::debug(sprintf('Working on account #%d', $account->id));
if (array_key_exists('current_amount', $info) && null !== $info['current_amount']) { if (array_key_exists('current_amount', $info) && null !== $info['current_amount']) {
// an amount is set, first check out if there is a difference with the previous amount. // an amount is set, first check out if there is a difference with the previous amount.
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0'; $previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
@@ -258,22 +259,24 @@ class PiggyBankFactory
// create event for difference. // create event for difference.
if (0 !== bccomp($diff, '0')) { if (0 !== bccomp($diff, '0')) {
// 2025-10-01 for issue #10990 disable this event.
Log::debug(sprintf('[a] Will save event for difference %s (previous value was %s)', $diff, $previous)); Log::debug(sprintf('[a] Will save event for difference %s (previous value was %s)', $diff, $previous));
event(new ChangedAmount($piggyBank, $diff, null, null)); // event(new ChangedAmount($piggyBank, $diff, null, null));
} }
$toBeLinked[$account->id] = ['current_amount' => $info['current_amount']]; $toBeLinked[$account->id] = ['current_amount' => $info['current_amount']];
Log::debug(sprintf('[a] Will link account #%d with amount %s', $account->id, $info['current_amount'])); Log::debug(sprintf('[a] Will link account #%d with amount %s', $account->id, $info['current_amount']));
} }
if (array_key_exists('current_amount', $info) && null === $info['current_amount']) { if (array_key_exists('current_amount', $info) && null === $info['current_amount']) {
// an amount is set, first check out if there is a difference with the previous amount. // no amount is set, first check out if there is a difference with the previous amount.
$previous = $toBeLinked[$account->id]['current_amount'] ?? '0'; $previous = $toBeLinked[$account->id]['current_amount'] ?? '0';
$diff = bcsub('0', $previous); $diff = bcsub('0', $previous);
// create event for difference. // create event for difference.
if (0 !== bccomp($diff, '0')) { if (0 !== bccomp($diff, '0')) {
// 2025-10-01 for issue #10990 disable this event.
Log::debug(sprintf('[b] Will save event for difference %s (previous value was %s)', $diff, $previous)); Log::debug(sprintf('[b] Will save event for difference %s (previous value was %s)', $diff, $previous));
event(new ChangedAmount($piggyBank, $diff, null, null)); // event(new ChangedAmount($piggyBank, $diff, null, null));
} }
// no amount set, use previous amount or go to ZERO. // no amount set, use previous amount or go to ZERO.
@@ -282,7 +285,8 @@ class PiggyBankFactory
// create event: // create event:
Log::debug('linkToAccountIds: Trigger change for positive amount [b].'); Log::debug('linkToAccountIds: Trigger change for positive amount [b].');
event(new ChangedAmount($piggyBank, $toBeLinked[$account->id]['current_amount'] ?? '0', null, null)); // 2025-10-01 for issue #10990 disable this event.
// event(new ChangedAmount($piggyBank, $toBeLinked[$account->id]['current_amount'] ?? '0', null, null));
} }
if (!array_key_exists('current_amount', $info)) { if (!array_key_exists('current_amount', $info)) {
$toBeLinked[$account->id] ??= []; $toBeLinked[$account->id] ??= [];

View File

@@ -36,6 +36,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups; use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
use FireflyIII\Support\Facades\Amount; use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Http\Api\ExchangeRateConverter; use FireflyIII\Support\Http\Api\ExchangeRateConverter;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -227,7 +228,6 @@ trait ModifiesPiggyBanks
$factory->user = $this->user; $factory->user = $this->user;
// the piggy bank currency is set or updated FIRST, if it exists. // the piggy bank currency is set or updated FIRST, if it exists.
$factory->linkToAccountIds($piggyBank, $data['accounts'] ?? []); $factory->linkToAccountIds($piggyBank, $data['accounts'] ?? []);
@@ -244,7 +244,7 @@ trait ModifiesPiggyBanks
// question is, from which account(s) to remove the difference? // question is, from which account(s) to remove the difference?
// solution: just start from the top until there is no more money left to remove. // solution: just start from the top until there is no more money left to remove.
$this->removeAmountFromAll($piggyBank, app('steam')->positive($difference)); $this->removeAmountFromAll($piggyBank, Steam::positive($difference));
} }
// update using name: // update using name: