Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Another fix for https://github.com/firefly-iii/firefly-iii/issues/11964
James Colee7a6dd792f1d
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex 8fa7f57ac5..8305626201 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -638,6 +638,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface/** @var Bill $bill */foreach ($bills as $bill) {+ // Log::debug(sprintf('Bill #%d ("%s")', $bill->id, $bill->name));/** @var Collection $set */$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);$currency = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? $primary : $bill->transactionCurrency;@@ -649,13 +650,14 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface'decimal_places' => $currency->decimal_places,'sum' => '0',];- $setAmount = '0';+ // Log::debug(sprintf('Created a new array for currency #%d', $currency->id));/** @var TransactionJournal $transactionJournal */foreach ($set as $transactionJournal) {- // grab currency from transaction.+ // grab currency from journal.$transactionCurrency = $transactionJournal->transactionCurrency;- $return[(int) $transactionCurrency->id] ??= [+ $currencyId = (int) $transactionCurrency->id;+ $return[$currencyId] ??= ['id' => (string) $transactionCurrency->id,'name' => $transactionCurrency->name,'symbol' => $transactionCurrency->symbol,@@ -663,19 +665,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface'decimal_places' => $transactionCurrency->decimal_places,'sum' => '0',];-+ $amountFromJournal = Amount::getAmountFromJournalObject($transactionJournal);+ // Log::debug(sprintf('Created a (new) array for currency #%d', $currencyId));+ // Log::debug(sprintf('Amount to add is %s', $amountFromJournal));// get currency from transaction as well.- $return[(int) $transactionCurrency->id]['sum'] = bcadd(- $return[(int) $transactionCurrency->id]['sum'],- Amount::getAmountFromJournalObject($transactionJournal)- );-- // $setAmount = bcadd($setAmount, Amount::getAmountFromJournalObject($transactionJournal));+ $return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], $amountFromJournal);}-- // Log::debug(sprintf('Bill #%d ("%s") with %d transaction(s) and sum %s %s', $bill->id, $bill->name, $set->count(), $currency->code, $setAmount));- // $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $setAmount);- // Log::debug(sprintf('Total sum is now %s', $return[$currency->id]['sum']));}// remove empty sets$final = [];diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex ffe6974f9d..94a8093610 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -225,21 +225,25 @@ class Amount*/public function getAmountFromJournalObject(TransactionJournal $journal): string{+ // Log::debug(sprintf('Get amount from journal #%d', $journal->id));$convertToPrimary = $this->convertToPrimary();$currency = $this->getPrimaryCurrency();- $field = $convertToPrimary && $currency->id !== $journal->transaction_currency_id ? 'pc_amount' : 'amount';+ $field = $convertToPrimary && $currency->id !== $journal->transaction_currency_id ? 'native_amount' : 'amount';/** @var null|Transaction $sourceTransaction */$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();if (null === $sourceTransaction) {+ // Log::debug('Return zero!');return '0';}$amount = $sourceTransaction->{$field} ?? '0';+ // Log::debug(sprintf('Amount is %s', $amount));if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {// use foreign amount instead!$amount = (string) $sourceTransaction->foreign_amount; // hard coded to be foreign amount.+ // Log::debug(sprintf('Amount is now %s', $amount));}-+ // Log::debug(sprintf('Final return is %s', $amount));return $amount;}