diff --git a/app/Api/V1/Controllers/Models/Transaction/UpdateController.php b/app/Api/V1/Controllers/Models/Transaction/UpdateController.php index 351a78851f..246666f0e0 100644 --- a/app/Api/V1/Controllers/Models/Transaction/UpdateController.php +++ b/app/Api/V1/Controllers/Models/Transaction/UpdateController.php @@ -54,7 +54,7 @@ class UpdateController extends Controller $this->middleware( function ($request, $next) { /** @var User $admin */ - $admin = auth()->user(); + $admin = auth()->user(); $this->groupRepository = app(TransactionGroupRepositoryInterface::class); $this->groupRepository->setUser($admin); @@ -73,47 +73,48 @@ class UpdateController extends Controller public function update(UpdateRequest $request, TransactionGroup $transactionGroup): JsonResponse { app('log')->debug('Now in update routine for transaction group'); - $data = $request->getAll(); - $oldAmount = $this->groupRepository->getTotalAmount($transactionGroup); + $data = $request->getAll(); + $oldAmount = $this->groupRepository->getTotalAmount($transactionGroup); $transactionGroup = $this->groupRepository->update($transactionGroup, $data); - $newAmount = $this->groupRepository->getTotalAmount($transactionGroup); - $manager = $this->getManager(); + $newAmount = $this->groupRepository->getTotalAmount($transactionGroup); + $manager = $this->getManager(); Log::debug(sprintf('Old amount: %s, new amount: %s', $oldAmount, $newAmount)); app('preferences')->mark(); - $applyRules = $data['apply_rules'] ?? true; - $fireWebhooks = $data['fire_webhooks'] ?? true; - $amountChanged = 0 !== bccomp($oldAmount, $newAmount); + $applyRules = $data['apply_rules'] ?? true; + $fireWebhooks = $data['fire_webhooks'] ?? true; + $amountChanged = 0 !== bccomp($oldAmount, $newAmount); event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged)); /** @var User $admin */ - $admin = auth()->user(); + $admin = auth()->user(); // use new group collector: /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $collector ->setUser($admin) // filter on transaction group. ->setTransactionGroup($transactionGroup) // all info needed for the API: - ->withAPIInformation(); + ->withAPIInformation() + ; - $selectedGroup = $collector->getGroups()->first(); + $selectedGroup = $collector->getGroups()->first(); if (null === $selectedGroup) { throw new NotFoundHttpException(); } // enrich - $enrichment = new TransactionGroupEnrichment(); + $enrichment = new TransactionGroupEnrichment(); $enrichment->setUser($admin); - $selectedGroup = $enrichment->enrichSingle($selectedGroup); + $selectedGroup = $enrichment->enrichSingle($selectedGroup); /** @var TransactionGroupTransformer $transformer */ - $transformer = app(TransactionGroupTransformer::class); + $transformer = app(TransactionGroupTransformer::class); $transformer->setParameters($this->parameters); - $resource = new Item($selectedGroup, $transformer, 'transactions'); + $resource = new Item($selectedGroup, $transformer, 'transactions'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } diff --git a/app/Api/V2/Controllers/Model/Transaction/UpdateController.php b/app/Api/V2/Controllers/Model/Transaction/UpdateController.php index f7997c47f6..bdb751fa56 100644 --- a/app/Api/V2/Controllers/Model/Transaction/UpdateController.php +++ b/app/Api/V2/Controllers/Model/Transaction/UpdateController.php @@ -69,7 +69,7 @@ class UpdateController extends Controller $transactionGroup = $this->groupRepository->update($transactionGroup, $data); $applyRules = $data['apply_rules'] ?? true; $fireWebhooks = $data['fire_webhooks'] ?? true; - $amountChanged = true; + $amountChanged = true; event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged)); app('preferences')->mark(); diff --git a/app/Console/Commands/Correction/CorrectsIbans.php b/app/Console/Commands/Correction/CorrectsIbans.php index 8502350322..93062e1c8c 100644 --- a/app/Console/Commands/Correction/CorrectsIbans.php +++ b/app/Console/Commands/Correction/CorrectsIbans.php @@ -54,8 +54,8 @@ class CorrectsIbans extends Command { /** @var Account $account */ foreach ($accounts as $account) { - $iban = (string) $account->iban; - $newIban = app('steam')->filterSpaces($iban); + $iban = (string) $account->iban; + $newIban = app('steam')->filterSpaces($iban); if ('' !== $iban && $iban !== $newIban) { $account->iban = $newIban; $account->save(); @@ -64,8 +64,8 @@ class CorrectsIbans extends Command } // same for account number: $accountNumber = $account->accountMeta->where('name', 'account_number')->first(); - if(null !== $accountNumber) { - $number = (string) $accountNumber->value; + if (null !== $accountNumber) { + $number = (string) $accountNumber->value; $newNumber = app('steam')->filterSpaces($number); if ('' !== $number && $number !== $newNumber) { $accountNumber->value = $newNumber; diff --git a/app/Factory/AccountMetaFactory.php b/app/Factory/AccountMetaFactory.php index 6193dc4147..95bbd45955 100644 --- a/app/Factory/AccountMetaFactory.php +++ b/app/Factory/AccountMetaFactory.php @@ -42,9 +42,9 @@ class AccountMetaFactory $entry = $account->accountMeta()->where('name', $field)->first(); // must not be an empty string: if ('' !== $value) { - if('account_number' === $field) { + if ('account_number' === $field) { $value = Steam::filterSpaces($value); - $value = trim(str_replace([' ',"\t", "\n", "\r"], '', $value)); + $value = trim(str_replace([' ', "\t", "\n", "\r"], '', $value)); } // if $data has field and $entry is null, create new one: if (null === $entry) { diff --git a/app/Handlers/Events/UpdatedGroupEventHandler.php b/app/Handlers/Events/UpdatedGroupEventHandler.php index 0024cae510..d15e159584 100644 --- a/app/Handlers/Events/UpdatedGroupEventHandler.php +++ b/app/Handlers/Events/UpdatedGroupEventHandler.php @@ -60,19 +60,20 @@ class UpdatedGroupEventHandler */ public function unifyAccounts(UpdatedTransactionGroup $updatedGroupEvent): void { - $group = $updatedGroupEvent->transactionGroup; + $group = $updatedGroupEvent->transactionGroup; if (1 === $group->transactionJournals->count()) { return; } // first journal: /** @var null|TransactionJournal $first */ - $first = $group->transactionJournals() + $first = $group->transactionJournals() ->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.order', 'ASC') ->orderBy('transaction_journals.id', 'DESC') ->orderBy('transaction_journals.description', 'DESC') - ->first(); + ->first() + ; if (null === $first) { Log::warning(sprintf('Group #%d has no transaction journals.', $group->id)); @@ -80,24 +81,26 @@ class UpdatedGroupEventHandler return; } - $all = $group->transactionJournals()->get()->pluck('id')->toArray(); + $all = $group->transactionJournals()->get()->pluck('id')->toArray(); /** @var Account $sourceAccount */ $sourceAccount = $first->transactions()->where('amount', '<', '0')->first()->account; /** @var Account $destAccount */ - $destAccount = $first->transactions()->where('amount', '>', '0')->first()->account; + $destAccount = $first->transactions()->where('amount', '>', '0')->first()->account; - $type = $first->transactionType->type; + $type = $first->transactionType->type; if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::WITHDRAWAL->value === $type) { // set all source transactions to source account: Transaction::whereIn('transaction_journal_id', $all) - ->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id]); + ->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id]) + ; } if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::DEPOSIT->value === $type) { // set all destination transactions to destination account: Transaction::whereIn('transaction_journal_id', $all) - ->where('amount', '>', 0)->update(['account_id' => $destAccount->id]); + ->where('amount', '>', 0)->update(['account_id' => $destAccount->id]) + ; } } @@ -112,24 +115,24 @@ class UpdatedGroupEventHandler return; } - $journals = $updatedGroupEvent->transactionGroup->transactionJournals; - $array = []; + $journals = $updatedGroupEvent->transactionGroup->transactionJournals; + $array = []; /** @var TransactionJournal $journal */ foreach ($journals as $journal) { $array[] = $journal->id; } - $journalIds = implode(',', $array); + $journalIds = implode(',', $array); Log::debug(sprintf('Add local operator for journal(s): %s', $journalIds)); // collect rules: $ruleGroupRepository = app(RuleGroupRepositoryInterface::class); $ruleGroupRepository->setUser($updatedGroupEvent->transactionGroup->user); - $groups = $ruleGroupRepository->getRuleGroupsWithRules('update-journal'); + $groups = $ruleGroupRepository->getRuleGroupsWithRules('update-journal'); // file rule engine. - $newRuleEngine = app(RuleEngineInterface::class); + $newRuleEngine = app(RuleEngineInterface::class); $newRuleEngine->setUser($updatedGroupEvent->transactionGroup->user); $newRuleEngine->addOperator(['type' => 'journal_id', 'value' => $journalIds]); $newRuleEngine->setRuleGroups($groups); @@ -138,7 +141,7 @@ class UpdatedGroupEventHandler private function recalculateCredit(UpdatedTransactionGroup $event): void { - $group = $event->transactionGroup; + $group = $event->transactionGroup; /** @var CreditRecalculateService $object */ $object = app(CreditRecalculateService::class); @@ -149,13 +152,13 @@ class UpdatedGroupEventHandler private function triggerWebhooks(UpdatedTransactionGroup $updatedGroupEvent): void { Log::debug(__METHOD__); - $group = $updatedGroupEvent->transactionGroup; + $group = $updatedGroupEvent->transactionGroup; if (false === $updatedGroupEvent->fireWebhooks) { Log::info(sprintf('Will not fire webhooks for transaction group #%d', $group->id)); return; } - $user = $group->user; + $user = $group->user; /** @var MessageGeneratorInterface $engine */ $engine = app(MessageGeneratorInterface::class); diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 3bbb4e3c7c..ce96edf102 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -86,7 +86,7 @@ class GroupCollector implements GroupCollectorInterface $this->hasJoinedAttTables = false; $this->expandGroupSearch = false; $this->hasJoinedMetaTables = false; - $this->booleanFields = ['source_balance_dirty','destination_balance_dirty']; + $this->booleanFields = ['source_balance_dirty', 'destination_balance_dirty']; $this->integerFields = [ 'transaction_group_id', 'user_id', diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index a57cefd565..dfc7e4510a 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -191,15 +191,15 @@ class MassController extends Controller */ private function updateJournal(int $journalId, MassEditJournalRequest $request): void { - $journal = $this->repository->find($journalId); + $journal = $this->repository->find($journalId); if (!$journal instanceof TransactionJournal) { throw new FireflyException(sprintf('Trying to edit non-existent or deleted journal #%d', $journalId)); } - $service = app(JournalUpdateService::class); + $service = app(JournalUpdateService::class); // for each field, call the update service. $service->setTransactionJournal($journal); - $data = [ + $data = [ 'date' => $this->getDateFromRequest($request, $journal->id, 'date'), 'description' => $this->getStringFromRequest($request, $journal->id, 'description'), 'source_id' => $this->getIntFromRequest($request, $journal->id, 'source_id'), diff --git a/app/Repositories/TransactionGroup/TransactionGroupRepository.php b/app/Repositories/TransactionGroup/TransactionGroupRepository.php index 185c98a074..3c8ad4a8ed 100644 --- a/app/Repositories/TransactionGroup/TransactionGroupRepository.php +++ b/app/Repositories/TransactionGroup/TransactionGroupRepository.php @@ -436,15 +436,17 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface, public function getTotalAmount(TransactionGroup $group): string { $sum = '0'; + /** @var TransactionJournal $journal */ - foreach($group->transactionJournals as $journal) { + foreach ($group->transactionJournals as $journal) { /** @var Transaction $transaction */ - foreach($journal->transactions as $transaction) { - if(-1 === bccomp('0', (string) $transaction->amount)) { + foreach ($journal->transactions as $transaction) { + if (-1 === bccomp('0', (string) $transaction->amount)) { $sum = bcadd($sum, $transaction->amount); } } } + return $sum; } } diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php index be730906c6..32cdb7c9f1 100644 --- a/app/Services/Internal/Update/JournalUpdateService.php +++ b/app/Services/Internal/Update/JournalUpdateService.php @@ -76,19 +76,19 @@ class JournalUpdateService */ public function __construct() { - $this->destinationAccount = null; + $this->destinationAccount = null; $this->destinationTransaction = null; - $this->sourceAccount = null; - $this->sourceTransaction = null; - $this->transactionGroup = null; - $this->transactionJournal = null; - $this->billRepository = app(BillRepositoryInterface::class); - $this->categoryRepository = app(CategoryRepositoryInterface::class); - $this->budgetRepository = app(BudgetRepositoryInterface::class); - $this->tagFactory = app(TagFactory::class); - $this->accountRepository = app(AccountRepositoryInterface::class); - $this->currencyRepository = app(CurrencyRepositoryInterface::class); - $this->metaString = [ + $this->sourceAccount = null; + $this->sourceTransaction = null; + $this->transactionGroup = null; + $this->transactionJournal = null; + $this->billRepository = app(BillRepositoryInterface::class); + $this->categoryRepository = app(CategoryRepositoryInterface::class); + $this->budgetRepository = app(BudgetRepositoryInterface::class); + $this->tagFactory = app(TagFactory::class); + $this->accountRepository = app(AccountRepositoryInterface::class); + $this->currencyRepository = app(CurrencyRepositoryInterface::class); + $this->metaString = [ 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id', @@ -103,8 +103,8 @@ class JournalUpdateService 'external_id', 'external_url', ]; - $this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', - 'invoice_date',]; + $this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', + 'invoice_date', ]; } public function setData(array $data): void @@ -114,16 +114,16 @@ class JournalUpdateService public function setTransactionGroup(TransactionGroup $transactionGroup): void { - $this->transactionGroup = $transactionGroup; + $this->transactionGroup = $transactionGroup; $this->billRepository->setUser($transactionGroup->user); $this->categoryRepository->setUser($transactionGroup->user); $this->budgetRepository->setUser($transactionGroup->user); $this->tagFactory->setUser($transactionGroup->user); $this->accountRepository->setUser($transactionGroup->user); - $this->destinationAccount = null; + $this->destinationAccount = null; $this->destinationTransaction = null; - $this->sourceAccount = null; - $this->sourceTransaction = null; + $this->sourceAccount = null; + $this->sourceTransaction = null; } public function setTransactionJournal(TransactionJournal $transactionJournal): void @@ -183,14 +183,14 @@ class JournalUpdateService private function hasValidSourceAccount(): bool { - $sourceId = $this->data['source_id'] ?? null; - $sourceName = $this->data['source_name'] ?? null; + $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(); - $sourceId = $origSourceAccount->id; - $sourceName = $origSourceAccount->name; + $sourceId = $origSourceAccount->id; + $sourceName = $origSourceAccount->name; } // make new account validator. @@ -199,11 +199,11 @@ class JournalUpdateService // make a new validator. /** @var AccountValidator $validator */ - $validator = app(AccountValidator::class); + $validator = app(AccountValidator::class); $validator->setTransactionType($expectedType); $validator->setUser($this->transactionJournal->user); - $result = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]); + $result = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]); Log::debug( sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true)) ); @@ -228,7 +228,7 @@ class JournalUpdateService private function getOriginalSourceAccount(): Account { if (!$this->sourceAccount instanceof Account) { - $source = $this->getSourceTransaction(); + $source = $this->getSourceTransaction(); $this->sourceAccount = $source->account; } @@ -239,7 +239,7 @@ class JournalUpdateService { if (!$this->sourceTransaction instanceof Transaction) { /** @var null|Transaction $result */ - $result = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first(); + $result = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first(); $this->sourceTransaction = $result; } Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount)); @@ -267,27 +267,27 @@ class JournalUpdateService private function hasValidDestinationAccount(): bool { Log::debug('Now in hasValidDestinationAccount().'); - $destId = $this->data['destination_id'] ?? null; - $destName = $this->data['destination_name'] ?? null; + $destId = $this->data['destination_id'] ?? null; + $destName = $this->data['destination_name'] ?? null; if (!$this->hasFields(['destination_id', 'destination_name'])) { Log::debug('No destination info submitted, grab the original data.'); $destination = $this->getOriginalDestinationAccount(); - $destId = $destination->id; - $destName = $destination->name; + $destId = $destination->id; + $destName = $destination->name; } // make new account validator. - $expectedType = $this->getExpectedType(); + $expectedType = $this->getExpectedType(); Log::debug(sprintf('(b) Expected type (new or unchanged) is %s', $expectedType)); // make a new validator. /** @var AccountValidator $validator */ - $validator = app(AccountValidator::class); + $validator = app(AccountValidator::class); $validator->setTransactionType($expectedType); $validator->setUser($this->transactionJournal->user); $validator->source = $this->getValidSourceAccount(); - $result = $validator->validateDestination(['id' => $destId, 'name' => $destName]); + $result = $validator->validateDestination(['id' => $destId, 'name' => $destName]); Log::debug( sprintf( 'hasValidDestinationAccount(%d, "%s") will return %s', @@ -306,7 +306,7 @@ class JournalUpdateService private function getOriginalDestinationAccount(): Account { if (!$this->destinationAccount instanceof Account) { - $destination = $this->getDestinationTransaction(); + $destination = $this->getDestinationTransaction(); $this->destinationAccount = $destination->account; } @@ -320,7 +320,7 @@ class JournalUpdateService { if (!$this->destinationTransaction instanceof Transaction) { /** @var null|Transaction $result */ - $result = $this->transactionJournal->transactions()->where('amount', '>', 0)->first(); + $result = $this->transactionJournal->transactions()->where('amount', '>', 0)->first(); $this->destinationTransaction = $result; } @@ -338,12 +338,12 @@ class JournalUpdateService return $this->getOriginalSourceAccount(); } - $sourceInfo = [ - 'id' => (int)($this->data['source_id'] ?? null), - 'name' => $this->data['source_name'] ?? null, - 'iban' => $this->data['source_iban'] ?? null, + $sourceInfo = [ + 'id' => (int)($this->data['source_id'] ?? null), + 'name' => $this->data['source_name'] ?? null, + 'iban' => $this->data['source_iban'] ?? null, 'number' => $this->data['source_number'] ?? null, - 'bic' => $this->data['source_bic'] ?? null, + 'bic' => $this->data['source_bic'] ?? null, ]; $expectedType = $this->getExpectedType(); @@ -366,8 +366,8 @@ class JournalUpdateService */ private function updateAccounts(): void { - $source = $this->getValidSourceAccount(); - $destination = $this->getValidDestinationAccount(); + $source = $this->getValidSourceAccount(); + $destination = $this->getValidDestinationAccount(); // cowardly refuse to update if both accounts are the same. if ($source->id === $destination->id) { @@ -380,7 +380,7 @@ class JournalUpdateService $origSourceTransaction->account()->associate($source); $origSourceTransaction->save(); - $destTransaction = $this->getDestinationTransaction(); + $destTransaction = $this->getDestinationTransaction(); $destTransaction->account()->associate($destination); $destTransaction->save(); @@ -402,12 +402,12 @@ class JournalUpdateService return $this->getOriginalDestinationAccount(); } - $destInfo = [ - 'id' => (int)($this->data['destination_id'] ?? null), - 'name' => $this->data['destination_name'] ?? null, - 'iban' => $this->data['destination_iban'] ?? null, + $destInfo = [ + 'id' => (int)($this->data['destination_id'] ?? null), + 'name' => $this->data['destination_name'] ?? null, + 'iban' => $this->data['destination_iban'] ?? null, 'number' => $this->data['destination_number'] ?? null, - 'bic' => $this->data['destination_bic'] ?? null, + 'bic' => $this->data['destination_bic'] ?? null, ]; // make new account validator. @@ -431,7 +431,7 @@ class JournalUpdateService { Log::debug('Now in updateType()'); if ($this->hasFields(['type'])) { - $type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type']; + $type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type']; Log::debug( sprintf( 'Trying to change journal #%d from a %s to a %s.', @@ -443,7 +443,7 @@ class JournalUpdateService /** @var TransactionTypeFactory $typeFactory */ $typeFactory = app(TransactionTypeFactory::class); - $result = $typeFactory->find($this->data['type']); + $result = $typeFactory->find($this->data['type']); if (null !== $result) { Log::debug('Changed transaction type!'); $this->transactionJournal->transaction_type_id = $result->id; @@ -464,14 +464,14 @@ class JournalUpdateService { $type = $this->transactionJournal->transactionType->type; if (( - array_key_exists('bill_id', $this->data) + array_key_exists('bill_id', $this->data) || array_key_exists('bill_name', $this->data) - ) + ) && TransactionTypeEnum::WITHDRAWAL->value === $type ) { - $billId = (int)($this->data['bill_id'] ?? 0); - $billName = (string)($this->data['bill_name'] ?? ''); - $bill = $this->billRepository->findBill($billId, $billName); + $billId = (int)($this->data['bill_id'] ?? 0); + $billName = (string)($this->data['bill_name'] ?? ''); + $bill = $this->billRepository->findBill($billId, $billName); $this->transactionJournal->bill_id = $bill?->id; Log::debug('Updated bill ID'); } @@ -483,7 +483,7 @@ class JournalUpdateService private function updateField(string $fieldName): void { if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) { - $value = $this->data[$fieldName]; + $value = $this->data[$fieldName]; if ('date' === $fieldName) { if (!$value instanceof Carbon) { @@ -588,10 +588,10 @@ class JournalUpdateService if ($this->hasFields([$field])) { $value = '' === $this->data[$field] ? null : $this->data[$field]; Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value)); - $set = [ + $set = [ 'journal' => $this->transactionJournal, - 'name' => $field, - 'data' => $value, + 'name' => $field, + 'data' => $value, ]; $factory->updateOrCreate($set); } @@ -615,15 +615,15 @@ class JournalUpdateService Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value)); $set = [ 'journal' => $this->transactionJournal, - 'name' => $field, - 'data' => $value, + 'name' => $field, + 'data' => $value, ]; $factory->updateOrCreate($set); // also set date with timezone. $set = [ 'journal' => $this->transactionJournal, - 'name' => sprintf('%s_tz', $field), - 'data' => $value?->format('e'), + 'name' => sprintf('%s_tz', $field), + 'data' => $value?->format('e'), ]; $factory->updateOrCreate($set); } @@ -636,19 +636,19 @@ class JournalUpdateService if (!$this->hasFields(['currency_id', 'currency_code'])) { return; } - $currencyId = $this->data['currency_id'] ?? null; - $currencyCode = $this->data['currency_code'] ?? null; - $currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode); + $currencyId = $this->data['currency_id'] ?? null; + $currencyCode = $this->data['currency_code'] ?? null; + $currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode); // update currency everywhere. $this->transactionJournal->transaction_currency_id = $currency->id; $this->transactionJournal->save(); - $source = $this->getSourceTransaction(); - $source->transaction_currency_id = $currency->id; + $source = $this->getSourceTransaction(); + $source->transaction_currency_id = $currency->id; $source->save(); - $dest = $this->getDestinationTransaction(); - $dest->transaction_currency_id = $currency->id; + $dest = $this->getDestinationTransaction(); + $dest->transaction_currency_id = $currency->id; $dest->save(); // refresh transactions. @@ -664,7 +664,7 @@ class JournalUpdateService return; } - $value = $this->data['amount'] ?? ''; + $value = $this->data['amount'] ?? ''; Log::debug(sprintf('Amount is now "%s"', $value)); try { @@ -674,14 +674,14 @@ class JournalUpdateService return; } - $origSourceTransaction = $this->getSourceTransaction(); - $this->amountChanged = 0 !== bccomp($origSourceTransaction->amount, app('steam')->negative($amount)); - $origSourceTransaction->amount = app('steam')->negative($amount); + $origSourceTransaction = $this->getSourceTransaction(); + $this->amountChanged = 0 !== bccomp($origSourceTransaction->amount, app('steam')->negative($amount)); + $origSourceTransaction->amount = app('steam')->negative($amount); $origSourceTransaction->balance_dirty = true; $origSourceTransaction->save(); - $destTransaction = $this->getDestinationTransaction(); - $destTransaction->amount = app('steam')->positive($amount); - $destTransaction->balance_dirty = true; + $destTransaction = $this->getDestinationTransaction(); + $destTransaction->amount = app('steam')->positive($amount); + $destTransaction->balance_dirty = true; $destTransaction->save(); // refresh transactions. $this->sourceTransaction->refresh(); @@ -696,15 +696,15 @@ class JournalUpdateService return; } - $amount = $this->data['foreign_amount'] ?? null; - $foreignAmount = $this->getForeignAmount($amount); - $source = $this->getSourceTransaction(); - $dest = $this->getDestinationTransaction(); + $amount = $this->data['foreign_amount'] ?? null; + $foreignAmount = $this->getForeignAmount($amount); + $source = $this->getSourceTransaction(); + $dest = $this->getDestinationTransaction(); $foreignCurrency = $source->foreignCurrency; // find currency in data array - $newForeignId = $this->data['foreign_currency_id'] ?? null; - $newForeignCode = $this->data['foreign_currency_code'] ?? null; + $newForeignId = $this->data['foreign_currency_id'] ?? null; + $newForeignCode = $this->data['foreign_currency_code'] ?? null; $foreignCurrency = $this->currencyRepository->findCurrencyNull($newForeignId, $newForeignCode) ?? $foreignCurrency; @@ -718,26 +718,26 @@ class JournalUpdateService // add foreign currency info to source and destination if possible. if (null !== $foreignCurrency && null !== $foreignAmount) { $source->foreign_currency_id = $foreignCurrency->id; - $source->foreign_amount = app('steam')->negative($foreignAmount); + $source->foreign_amount = app('steam')->negative($foreignAmount); $source->save(); // if the transaction is a TRANSFER, and the foreign amount and currency are set (like they seem to be) // the correct fields to update in the destination transaction are NOT the foreign amount and currency // but rather the normal amount and currency. This is new behavior. - $isTransfer = TransactionTypeEnum::TRANSFER->value === $this->transactionJournal->transactionType->type; + $isTransfer = TransactionTypeEnum::TRANSFER->value === $this->transactionJournal->transactionType->type; // also check if it is not between an asset account and a liability, because then the same rule applies. - $isBetween = $this->isBetweenAssetAndLiability(); + $isBetween = $this->isBetweenAssetAndLiability(); if ($isTransfer || $isBetween) { Log::debug('Switch amounts, store in amount and not foreign_amount'); $dest->transaction_currency_id = $foreignCurrency->id; - $dest->amount = app('steam')->positive($foreignAmount); - $dest->foreign_amount = app('steam')->positive($source->amount); - $dest->foreign_currency_id = $source->transaction_currency_id; + $dest->amount = app('steam')->positive($foreignAmount); + $dest->foreign_amount = app('steam')->positive($source->amount); + $dest->foreign_currency_id = $source->transaction_currency_id; } if (!$isTransfer && !$isBetween) { $dest->foreign_currency_id = $foreignCurrency->id; - $dest->foreign_amount = app('steam')->positive($foreignAmount); + $dest->foreign_amount = app('steam')->positive($foreignAmount); } $dest->save(); @@ -759,11 +759,11 @@ class JournalUpdateService } if ('0' === $amount) { $source->foreign_currency_id = null; - $source->foreign_amount = null; + $source->foreign_amount = null; $source->save(); - $dest->foreign_currency_id = null; - $dest->foreign_amount = null; + $dest->foreign_currency_id = null; + $dest->foreign_amount = null; $dest->save(); Log::debug(sprintf('Foreign amount is "%s" so remove foreign amount info.', $amount)); } @@ -777,7 +777,7 @@ class JournalUpdateService private function isBetweenAssetAndLiability(): bool { /** @var Transaction $sourceTransaction */ - $sourceTransaction = $this->transactionJournal->transactions()->where('amount', '<', 0)->first(); + $sourceTransaction = $this->transactionJournal->transactions()->where('amount', '<', 0)->first(); /** @var Transaction $destinationTransaction */ $destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first(); @@ -792,15 +792,15 @@ class JournalUpdateService return false; } - $source = $sourceTransaction->account; - $destination = $destinationTransaction->account; + $source = $sourceTransaction->account; + $destination = $destinationTransaction->account; if (null === $source || null === $destination) { Log::warning('Either is false, stop.'); return false; } - $sourceTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]; + $sourceTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]; // source is liability, destination is asset if (in_array($source->accountType->type, $sourceTypes, true) && AccountTypeEnum::ASSET->value === $destination->accountType->type) { @@ -822,5 +822,4 @@ class JournalUpdateService { return $this->amountChanged; } - } diff --git a/app/Support/JsonApi/Enrichments/TransactionGroupEnrichment.php b/app/Support/JsonApi/Enrichments/TransactionGroupEnrichment.php index c3a28f1144..afd96bcf59 100644 --- a/app/Support/JsonApi/Enrichments/TransactionGroupEnrichment.php +++ b/app/Support/JsonApi/Enrichments/TransactionGroupEnrichment.php @@ -66,7 +66,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface $this->locations = []; $this->attachmentCount = []; $this->dateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date']; - $this->nativeCurrency = Amount::getNativeCurrency(); + $this->nativeCurrency = Amount::getNativeCurrency(); } #[Override] @@ -196,7 +196,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface $metaData = $this->metaData; $locations = $this->locations; $attachmentCount = $this->attachmentCount; - $nativeCurrency = $this->nativeCurrency; + $nativeCurrency = $this->nativeCurrency; $this->collection = $this->collection->map(function (array $item) use ($nativeCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) { foreach ($item['transactions'] as $index => $transaction) { diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php index c9868bba83..8685c0246a 100644 --- a/app/Transformers/TransactionGroupTransformer.php +++ b/app/Transformers/TransactionGroupTransformer.php @@ -155,24 +155,24 @@ class TransactionGroupTransformer extends AbstractTransformer 'native_amount' => $transaction['native_amount'] ?? null, // native currency, always present. - 'native_currency_id' => $transaction['native_currency']['id'] ?? null, - 'native_currency_code' => $transaction['native_currency']['code'] ?? null, - 'native_currency_name' => $transaction['native_currency']['name'] ?? null, - 'native_currency_symbol' => $transaction['native_currency']['symbol'] ?? null, - 'native_currency_decimal_places' => $transaction['native_currency']['decimal_places'] ?? null, + 'native_currency_id' => $transaction['native_currency']['id'] ?? null, + 'native_currency_code' => $transaction['native_currency']['code'] ?? null, + 'native_currency_name' => $transaction['native_currency']['name'] ?? null, + 'native_currency_symbol' => $transaction['native_currency']['symbol'] ?? null, + 'native_currency_decimal_places' => $transaction['native_currency']['decimal_places'] ?? null, // source balance after - 'source_balance_after' => $transaction['source_balance_after'] ?? null, - 'source_balance_dirty' => $transaction['source_balance_dirty'], + 'source_balance_after' => $transaction['source_balance_after'] ?? null, + 'source_balance_dirty' => $transaction['source_balance_dirty'], // destination balance after - 'destination_balance_after' => $transaction['destination_balance_after'] ?? null, - 'destination_balance_dirty' => $transaction['destination_balance_dirty'], + 'destination_balance_after' => $transaction['destination_balance_after'] ?? null, + 'destination_balance_dirty' => $transaction['destination_balance_dirty'], // balance before and after, if not dirty. - //'running_balance_dirty' => $transaction['balance_dirty'] ?? false, - //'running_balance_before' => $transaction['balance_before'] ?? null, - //'running_balance_after' => $transaction['balance_after'] ?? null, + // 'running_balance_dirty' => $transaction['balance_dirty'] ?? false, + // 'running_balance_before' => $transaction['balance_before'] ?? null, + // 'running_balance_after' => $transaction['balance_after'] ?? null, diff --git a/composer.lock b/composer.lock index 4f70022618..0325e957d8 100644 --- a/composer.lock +++ b/composer.lock @@ -11670,21 +11670,21 @@ }, { "name": "rector/rector", - "version": "2.0.16", + "version": "2.0.17", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2" + "reference": "caa4ffda1d48bde44434e6ba95d132ec32e7fd40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2", - "reference": "f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/caa4ffda1d48bde44434e6ba95d132ec32e7fd40", + "reference": "caa4ffda1d48bde44434e6ba95d132ec32e7fd40", "shasum": "" }, "require": { "php": "^7.4|^8.0", - "phpstan/phpstan": "^2.1.14" + "phpstan/phpstan": "^2.1.17" }, "conflict": { "rector/rector-doctrine": "*", @@ -11717,7 +11717,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/2.0.16" + "source": "https://github.com/rectorphp/rector/tree/2.0.17" }, "funding": [ { @@ -11725,7 +11725,7 @@ "type": "github" } ], - "time": "2025-05-12T16:37:16+00:00" + "time": "2025-05-30T10:59:08+00:00" }, { "name": "sebastian/cli-parser", diff --git a/config/firefly.php b/config/firefly.php index 73b18409bf..c572811a5e 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -78,7 +78,7 @@ return [ 'running_balance_column' => env('USE_RUNNING_BALANCE', false), // see cer.php for exchange rates feature flag. ], - 'version' => 'develop/2025-05-29', + 'version' => 'develop/2025-05-31', 'api_version' => '2.1.0', // field is no longer used. 'db_version' => 25, diff --git a/package-lock.json b/package-lock.json index c11befa3cd..dcc8f9faea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,9 +53,9 @@ } }, "node_modules/@babel/core": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.27.3.tgz", - "integrity": "sha512-hyrN8ivxfvJ4i0fIJuV4EOlV0WDMz5Ui4StRTgVaAvWeiRCilXgwVvxJKtFQ3TKtHgJscB2YiXKGNJuVwhQMtA==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.27.4.tgz", + "integrity": "sha512-bXYxrXFubeYdvB0NhD/NBB3Qi6aZeV20GOWVI47t2dkecCEoneR4NPVcb7abpXDEvejgrUfFtG6vG/zxAKmg+g==", "dev": true, "license": "MIT", "dependencies": { @@ -64,10 +64,10 @@ "@babel/generator": "^7.27.3", "@babel/helper-compilation-targets": "^7.27.2", "@babel/helper-module-transforms": "^7.27.3", - "@babel/helpers": "^7.27.3", - "@babel/parser": "^7.27.3", + "@babel/helpers": "^7.27.4", + "@babel/parser": "^7.27.4", "@babel/template": "^7.27.2", - "@babel/traverse": "^7.27.3", + "@babel/traverse": "^7.27.4", "@babel/types": "^7.27.3", "convert-source-map": "^2.0.0", "debug": "^4.1.0", @@ -392,9 +392,9 @@ } }, "node_modules/@babel/helpers": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.3.tgz", - "integrity": "sha512-h/eKy9agOya1IGuLaZ9tEUgz+uIRXcbtOhRtUyyMf8JFmn1iT13vnl/IGVWSkdOCG/pC57U4S1jnAabAavTMwg==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.4.tgz", + "integrity": "sha512-Y+bO6U+I7ZKaM5G5rDUZiYfUvQPUibYmAFe7EnKdnKBbVXDZxvp+MWOH5gYciY0EPk4EScsuFMQBbEfpdRKSCQ==", "dev": true, "license": "MIT", "dependencies": { @@ -406,9 +406,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.3.tgz", - "integrity": "sha512-xyYxRj6+tLNDTWi0KCBcZ9V7yg3/lwL9DWh9Uwh/RIVlIfFidggcgxKX3GCXwCiswwcGRawBKbEg2LG/Y8eJhw==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.4.tgz", + "integrity": "sha512-BRmLHGwpUqLFR2jzx9orBuX/ABDkj2jLKOXrHDTN2aOKL+jFDDKaRNo9nyYsIl9h/UE/7lMKdDjKQQyxKKDZ7g==", "dev": true, "license": "MIT", "dependencies": { @@ -1255,9 +1255,9 @@ } }, "node_modules/@babel/plugin-transform-regenerator": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.27.1.tgz", - "integrity": "sha512-B19lbbL7PMrKr52BNPjCqg1IyNUIjTcxKj8uX9zHO+PmWN93s19NDr/f69mIkEp2x9nmDJ08a7lgHaTTzvW7mw==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.27.4.tgz", + "integrity": "sha512-Glp/0n8xuj+E1588otw5rjJkTXfzW7FjH3IIUrfqiZOPQCd2vbg8e+DQE8jK9g4V5/zrxFW+D9WM9gboRPELpQ==", "dev": true, "license": "MIT", "dependencies": { @@ -1304,9 +1304,9 @@ } }, "node_modules/@babel/plugin-transform-runtime": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.27.3.tgz", - "integrity": "sha512-bA9ZL5PW90YwNgGfjg6U+7Qh/k3zCEQJ06BFgAGRp/yMjw9hP9UGbGPtx3KSOkHGljEPCCxaE+PH4fUR2h1sDw==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.27.4.tgz", + "integrity": "sha512-D68nR5zxU64EUzV8i7T3R5XP0Xhrou/amNnddsRQssx6GrTLdZl1rLxyjtVZBd+v/NVX4AbTPOB5aU8thAZV1A==", "dev": true, "license": "MIT", "dependencies": { @@ -1592,9 +1592,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.3.tgz", - "integrity": "sha512-7EYtGezsdiDMyY80+65EzwiGmcJqpmcZCojSXaRgdrBaGtWTgDZKq69cPIVped6MkIM78cTQ2GOiEYjwOlG4xw==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.4.tgz", + "integrity": "sha512-t3yaEOuGu9NlIZ+hIeGbBjFtZT7j2cb2tg0fuaJKeGotchRjjLfrBA9Kwf8quhpP1EUuxModQg04q/mBwyg8uA==", "license": "MIT", "engines": { "node": ">=6.9.0" @@ -1616,15 +1616,15 @@ } }, "node_modules/@babel/traverse": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.3.tgz", - "integrity": "sha512-lId/IfN/Ye1CIu8xG7oKBHXd2iNb2aW1ilPszzGcJug6M8RCKfVNcYhpI5+bMvFYjK7lXIM0R+a+6r8xhHp2FQ==", + "version": "7.27.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.4.tgz", + "integrity": "sha512-oNcu2QbHqts9BtOWJosOVJapWjBDSxGCpFvikNR5TGDYDQf3JwpIoMzIKrvfoti93cLfPJEG4tH9SPVeyCGgdA==", "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.27.3", - "@babel/parser": "^7.27.3", + "@babel/parser": "^7.27.4", "@babel/template": "^7.27.2", "@babel/types": "^7.27.3", "debug": "^4.3.1", @@ -3108,9 +3108,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.15.24", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.24.tgz", - "integrity": "sha512-w9CZGm9RDjzTh/D+hFwlBJ3ziUaVw7oufKA3vOFSOZlzmW9AkZnfjPb+DLnrV6qtgL/LNmP0/2zBNCFHL3F0ng==", + "version": "22.15.29", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.29.tgz", + "integrity": "sha512-LNdjOkUDlU1RZb8e1kOIUpN1qQUlzGkEtbVNo53vbrwDg5om6oduhm4SiUaPW5ASTXhAiP0jInWG8Qx9fVlOeQ==", "dev": true, "license": "MIT", "dependencies": { @@ -10064,9 +10064,9 @@ "license": "MIT" }, "node_modules/sass": { - "version": "1.89.0", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.89.0.tgz", - "integrity": "sha512-ld+kQU8YTdGNjOLfRWBzewJpU5cwEv/h5yyqlSeJcj6Yh8U4TDA9UA5FPicqDz/xgRPWRSYIQNiFks21TbA9KQ==", + "version": "1.89.1", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.89.1.tgz", + "integrity": "sha512-eMLLkl+qz7tx/0cJ9wI+w09GQ2zodTkcE/aVfywwdlRcI3EO19xGnbmJwg/JMIm+5MxVJ6outddLZ4Von4E++Q==", "dev": true, "license": "MIT", "dependencies": {