Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix https://github.com/firefly-iii/firefly-iii/issues/9492
James Cole91a2a1afc308
diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.phpindex 3488032962..ae7af577ac 100644--- a/app/Services/Internal/Update/JournalUpdateService.php+++ b/app/Services/Internal/Update/JournalUpdateService.php@@ -132,14 +132,14 @@ class JournalUpdateServicepublic function update(): void{- app('log')->debug(sprintf('Now in %s', __METHOD__));- app('log')->debug(sprintf('Now in JournalUpdateService for journal #%d.', $this->transactionJournal->id));+ Log::debug(sprintf('Now in %s', __METHOD__));+ Log::debug(sprintf('Now in JournalUpdateService for journal #%d.', $this->transactionJournal->id));$this->data['reconciled'] = array_key_exists('reconciled', $this->data) ? $this->data['reconciled'] : null;// can we update account data using the new type?if ($this->hasValidAccounts()) {- app('log')->info('Account info is valid, now update.');+ Log::info('Account info is valid, now update.');// update accounts:$this->updateAccounts();@@ -175,14 +175,15 @@ class JournalUpdateServiceprivate function hasValidAccounts(): bool{+ Log::debug('Now in hasValidAccounts().');return $this->hasValidSourceAccount() && $this->hasValidDestinationAccount();}private function hasValidSourceAccount(): bool{- app('log')->debug('Now in hasValidSourceAccount().');$sourceId = $this->data['source_id'] ?? null;$sourceName = $this->data['source_name'] ?? null;+ Log::debug(sprintf('Now in hasValidSourceAccount("%s","%s").', $sourceId, $sourceName));if (!$this->hasFields(['source_id', 'source_name'])) {$origSourceAccount = $this->getOriginalSourceAccount();@@ -192,7 +193,7 @@ class JournalUpdateService// make new account validator.$expectedType = $this->getExpectedType();- app('log')->debug(sprintf('(a) Expected type (new or unchanged) is %s', $expectedType));+ Log::debug(sprintf('(a) Expected type (new or unchanged) is %s', $expectedType));// make a new validator./** @var AccountValidator $validator */@@ -200,8 +201,8 @@ class JournalUpdateService$validator->setTransactionType($expectedType);$validator->setUser($this->transactionJournal->user);- $result = $validator->validateSource(['id' => $sourceId]);- app('log')->debug(+ $result = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]);+ Log::debug(sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true)));@@ -241,7 +242,7 @@ class JournalUpdateService0)->first();}- app('log')->debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));+ Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));return $this->sourceTransaction;}@@ -255,7 +256,7 @@ class JournalUpdateService*/private function getExpectedType(): string{- app('log')->debug('Now in getExpectedType()');+ Log::debug('Now in getExpectedType()');if ($this->hasFields(['type'])) {return ucfirst('opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type']);}@@ -265,12 +266,12 @@ class JournalUpdateServiceprivate function hasValidDestinationAccount(): bool{- app('log')->debug('Now in hasValidDestinationAccount().');+ Log::debug('Now in hasValidDestinationAccount().');$destId = $this->data['destination_id'] ?? null;$destName = $this->data['destination_name'] ?? null;if (!$this->hasFields(['destination_id', 'destination_name'])) {- app('log')->debug('No destination info submitted, grab the original data.');+ Log::debug('No destination info submitted, grab the original data.');$destination = $this->getOriginalDestinationAccount();$destId = $destination->id;$destName = $destination->name;@@ -278,7 +279,7 @@ class JournalUpdateService// make new account validator.$expectedType = $this->getExpectedType();- app('log')->debug(sprintf('(b) Expected type (new or unchanged) is %s', $expectedType));+ Log::debug(sprintf('(b) Expected type (new or unchanged) is %s', $expectedType));// make a new validator./** @var AccountValidator $validator */@@ -287,7 +288,7 @@ class JournalUpdateService$validator->setUser($this->transactionJournal->user);$validator->source = $this->getValidSourceAccount();$result = $validator->validateDestination(['id' => $destId, 'name' => $destName]);- app('log')->debug(+ Log::debug(sprintf('hasValidDestinationAccount(%d, "%s") will return %s',$destId,@@ -329,7 +330,7 @@ class JournalUpdateService*/private function getValidSourceAccount(): Account{- app('log')->debug('Now in getValidSourceAccount().');+ Log::debug('Now in getValidSourceAccount().');if (!$this->hasFields(['source_id', 'source_name'])) {return $this->getOriginalSourceAccount();@@ -348,12 +349,12 @@ class JournalUpdateServicetry {$result = $this->getAccount($expectedType, 'source', $sourceInfo);} catch (FireflyException $e) {- app('log')->error(sprintf('Cant get the valid source account: %s', $e->getMessage()));+ Log::error(sprintf('Cant get the valid source account: %s', $e->getMessage()));$result = $this->getOriginalSourceAccount();}- app('log')->debug(sprintf('getValidSourceAccount() will return #%d ("%s")', $result->id, $result->name));+ Log::debug(sprintf('getValidSourceAccount() will return #%d ("%s")', $result->id, $result->name));return $result;}@@ -368,7 +369,7 @@ class JournalUpdateService// cowardly refuse to update if both accounts are the same.if ($source->id === $destination->id) {- app('log')->error(sprintf('Source + dest accounts are equal (%d, "%s")', $source->id, $source->name));+ Log::error(sprintf('Source + dest accounts are equal (%d, "%s")', $source->id, $source->name));return;}@@ -384,8 +385,8 @@ class JournalUpdateService// refresh transactions.$this->sourceTransaction->refresh();$this->destinationTransaction->refresh();- app('log')->debug(sprintf('Will set source to #%d ("%s")', $source->id, $source->name));- app('log')->debug(sprintf('Will set dest to #%d ("%s")', $destination->id, $destination->name));+ Log::debug(sprintf('Will set source to #%d ("%s")', $source->id, $source->name));+ Log::debug(sprintf('Will set dest to #%d ("%s")', $destination->id, $destination->name));}/**@@ -393,7 +394,7 @@ class JournalUpdateService*/private function getValidDestinationAccount(): Account{- app('log')->debug('Now in getValidDestinationAccount().');+ Log::debug('Now in getValidDestinationAccount().');if (!$this->hasFields(['destination_id', 'destination_name'])) {return $this->getOriginalDestinationAccount();@@ -409,12 +410,12 @@ class JournalUpdateService// make new account validator.$expectedType = $this->getExpectedType();- app('log')->debug(sprintf('(c) Expected type (new or unchanged) is %s', $expectedType));+ Log::debug(sprintf('(c) Expected type (new or unchanged) is %s', $expectedType));try {$result = $this->getAccount($expectedType, 'destination', $destInfo);} catch (FireflyException $e) {- app('log')->error(sprintf('getValidDestinationAccount() threw unexpected error: %s', $e->getMessage()));+ Log::error(sprintf('getValidDestinationAccount() threw unexpected error: %s', $e->getMessage()));$result = $this->getOriginalDestinationAccount();}@@ -426,10 +427,10 @@ class JournalUpdateService*/private function updateType(): void{- app('log')->debug('Now in updateType()');+ Log::debug('Now in updateType()');if ($this->hasFields(['type'])) {$type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type'];- app('log')->debug(+ Log::debug(sprintf('Trying to change journal #%d from a %s to a %s.',$this->transactionJournal->id,@@ -442,7 +443,7 @@ class JournalUpdateService$typeFactory = app(TransactionTypeFactory::class);$result = $typeFactory->find($this->data['type']);if (null !== $result) {- app('log')->debug('Changed transaction type!');+ Log::debug('Changed transaction type!');$this->transactionJournal->transaction_type_id = $result->id;$this->transactionJournal->save();@@ -451,7 +452,7 @@ class JournalUpdateServicereturn;}- app('log')->debug('No type field present.');+ Log::debug('No type field present.');}/**@@ -470,7 +471,7 @@ class JournalUpdateService$billName = (string) ($this->data['bill_name'] ?? '');$bill = $this->billRepository->findBill($billId, $billName);$this->transactionJournal->bill_id = $bill?->id;- app('log')->debug('Updated bill ID');+ Log::debug('Updated bill ID');}}@@ -494,7 +495,7 @@ class JournalUpdateService}// do some parsing.- app('log')->debug(sprintf('Create date value from string "%s".', $value));+ Log::debug(sprintf('Create date value from string "%s".', $value));$this->transactionJournal->date_tz = $value->format('e');}event(@@ -508,7 +509,7 @@ class JournalUpdateService);$this->transactionJournal->{$fieldName} = $value; // @phpstan-ignore-line- app('log')->debug(sprintf('Updated %s', $fieldName));+ Log::debug(sprintf('Updated %s', $fieldName));}}@@ -516,7 +517,7 @@ class JournalUpdateService{// update categoryif ($this->hasFields(['category_id', 'category_name'])) {- app('log')->debug('Will update category.');+ Log::debug('Will update category.');$this->storeCategory($this->transactionJournal, new NullArrayObject($this->data));}@@ -526,7 +527,7 @@ class JournalUpdateService{// update budgetif ($this->hasFields(['budget_id', 'budget_name'])) {- app('log')->debug('Will update budget.');+ Log::debug('Will update budget.');$this->storeBudget($this->transactionJournal, new NullArrayObject($this->data));}// is transfer? remove budget@@ -538,7 +539,7 @@ class JournalUpdateServiceprivate function updateTags(): void{if ($this->hasFields(['tags'])) {- app('log')->debug('Will update tags.');+ Log::debug('Will update tags.');$tags = $this->data['tags'] ?? null;$this->storeTags($this->transactionJournal, $tags);}@@ -565,13 +566,13 @@ class JournalUpdateService// update meta fields.// first stringif ($this->hasFields($this->metaString)) {- app('log')->debug('Meta string fields are present.');+ Log::debug('Meta string fields are present.');$this->updateMetaFields();}// then date fields.if ($this->hasFields($this->metaDate)) {- app('log')->debug('Meta date fields are present.');+ Log::debug('Meta date fields are present.');$this->updateMetaDateFields();}}@@ -584,7 +585,7 @@ class JournalUpdateServiceforeach ($this->metaString as $field) {if ($this->hasFields([$field])) {$value = '' === $this->data[$field] ? null : $this->data[$field];- app('log')->debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));+ Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));$set = ['journal' => $this->transactionJournal,'name' => $field,@@ -605,11 +606,11 @@ class JournalUpdateServicetry {$value = '' === (string) $this->data[$field] ? null : new Carbon($this->data[$field]);} catch (InvalidDateException|InvalidFormatException $e) { // @phpstan-ignore-line- app('log')->debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));+ Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));return;}- app('log')->debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));+ Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));$set = ['journal' => $this->transactionJournal,'name' => $field,@@ -651,23 +652,23 @@ class JournalUpdateService// refresh transactions.$this->sourceTransaction->refresh();$this->destinationTransaction->refresh();- app('log')->debug(sprintf('Updated currency to #%d (%s)', $currency->id, $currency->code));+ Log::debug(sprintf('Updated currency to #%d (%s)', $currency->id, $currency->code));}private function updateAmount(): void{- app('log')->debug(sprintf('Now in %s', __METHOD__));+ Log::debug(sprintf('Now in %s', __METHOD__));if (!$this->hasFields(['amount'])) {return;}$value = $this->data['amount'] ?? '';- app('log')->debug(sprintf('Amount is now "%s"', $value));+ Log::debug(sprintf('Amount is now "%s"', $value));try {$amount = $this->getAmount($value);} catch (FireflyException $e) {- app('log')->debug(sprintf('getAmount("%s") returns error: %s', $value, $e->getMessage()));+ Log::debug(sprintf('getAmount("%s") returns error: %s', $value, $e->getMessage()));return;}@@ -683,7 +684,7 @@ class JournalUpdateService// refresh transactions.$this->sourceTransaction->refresh();$this->destinationTransaction->refresh();- app('log')->debug(sprintf('Updated amount to "%s"', $amount));+ Log::debug(sprintf('Updated amount to "%s"', $amount));}private function updateForeignAmount(): void@@ -707,7 +708,7 @@ class JournalUpdateService// not the same as normal currencyif (null !== $foreignCurrency && $foreignCurrency->id === $this->transactionJournal->transaction_currency_id) {- app('log')->error(sprintf('Foreign currency is equal to normal currency (%s)', $foreignCurrency->code));+ Log::error(sprintf('Foreign currency is equal to normal currency (%s)', $foreignCurrency->code));return;}@@ -736,7 +737,7 @@ class JournalUpdateService$dest->save();- app('log')->debug(+ Log::debug(sprintf('Update foreign info to %s (#%d) %s',$foreignCurrency->code,@@ -759,9 +760,9 @@ class JournalUpdateService$dest->foreign_currency_id = null;$dest->foreign_amount = null;$dest->save();- app('log')->debug(sprintf('Foreign amount is "%s" so remove foreign amount info.', $amount));+ Log::debug(sprintf('Foreign amount is "%s" so remove foreign amount info.', $amount));}- app('log')->info('Not enough info to update foreign currency info.');+ Log::info('Not enough info to update foreign currency info.');// refresh transactions.$this->sourceTransaction->refresh();diff --git a/app/Validation/AccountValidator.php b/app/Validation/AccountValidator.phpindex 1b9734c8b3..6180d7cc84 100644--- a/app/Validation/AccountValidator.php+++ b/app/Validation/AccountValidator.php@@ -23,6 +23,7 @@ declare(strict_types=1);namespace FireflyIII\Validation;+use FireflyIII\Enums\AccountTypeEnum;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Models\TransactionType;@@ -238,7 +239,7 @@ class AccountValidatorprotected function canCreateType(string $accountType): bool{- $canCreate = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT];+ $canCreate = [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::LIABILITY_CREDIT->value];if (in_array($accountType, $canCreate, true)) {return true;}