From 127b6ea5152cf1cd48294ce76631ec736ceab7ed Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 14 Oct 2023 14:52:21 +0200 Subject: [PATCH] Add more rounded debug --- .../Internal/Support/CreditRecalculateService.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 115c717459..c221ab4131 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -196,7 +196,9 @@ class CreditRecalculateService } $startOfDebt = $this->repository->getOpeningBalanceAmount($account) ?? '0'; $leftOfDebt = app('steam')->positive($startOfDebt); - app('log')->debug(sprintf('Start of debt is "%s", so initial left of debt is "%s"', $startOfDebt, $leftOfDebt)); + $currency = $this->repository->getAccountCurrency($account); + $decimals = (int)($currency?->decimal_places ?? 2); + app('log')->debug(sprintf('Start of debt is "%s", so initial left of debt is "%s"', app('steam')->bcround($startOfDebt, $decimals), app('steam')->bcround($leftOfDebt, $decimals))); /** @var AccountMetaFactory $factory */ $factory = app(AccountMetaFactory::class); @@ -268,17 +270,20 @@ class CreditRecalculateService */ private function processTransaction(Account $account, string $direction, Transaction $transaction, string $leftOfDebt): string { - app('log')->debug(sprintf('Left of debt is: %s', $leftOfDebt)); $journal = $transaction->transactionJournal; $foreignCurrency = $transaction->foreignCurrency; $accountCurrency = $this->repository->getAccountCurrency($account); $groupId = $journal->transaction_group_id; + $decimals = (int)$accountCurrency->decimal_places; $type = $journal->transactionType->type; /** @var Transaction $destTransaction */ $destTransaction = $journal->transactions()->where('amount', '>', '0')->first(); /** @var Transaction $sourceTransaction */ $sourceTransaction = $journal->transactions()->where('amount', '<', '0')->first(); + + app('log')->debug(sprintf('Left of debt is: %s', app('steam')->bcround($leftOfDebt, $decimals))); + if ('' === $direction) { app('log')->warning('Direction is empty, so do nothing.'); return $leftOfDebt; @@ -289,7 +294,6 @@ class CreditRecalculateService } // amount to use depends on the currency: - $decimals = (int)$accountCurrency->decimal_places; $usedAmount = $transaction->amount; app('log')->debug(sprintf('Amount of transaction is %s', app('steam')->bcround($usedAmount, $decimals))); if (null !== $foreignCurrency && $foreignCurrency->id === $accountCurrency->id) {