mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-23 15:40:32 -06:00
Fix #7572
This commit is contained in:
parent
4334e9bed7
commit
c764ddd3be
@ -264,11 +264,16 @@ class BasicController extends Controller
|
||||
* Since both this method and the chart use the exact same data, we can suffice
|
||||
* with calling the one method in the bill repository that will get this amount.
|
||||
*/
|
||||
$paidAmount = $this->billRepository->getBillsPaidInRangePerCurrency($start, $end);
|
||||
$unpaidAmount = $this->billRepository->getBillsUnpaidInRangePerCurrency($start, $end);
|
||||
$return = [];
|
||||
foreach ($paidAmount as $currencyId => $amount) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
$paidAmount = $this->billRepository->sumPaidInRange($start, $end);
|
||||
$unpaidAmount = $this->billRepository->sumUnpaidInRange($start, $end);
|
||||
|
||||
$return = [];
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var array $info
|
||||
*/
|
||||
foreach ($paidAmount as $currencyId => $info) {
|
||||
$amount = bcmul($info['sum'], '-1');
|
||||
$currency = $this->currencyRepos->find((int)$currencyId);
|
||||
if (null === $currency) {
|
||||
continue;
|
||||
@ -287,8 +292,12 @@ class BasicController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($unpaidAmount as $currencyId => $amount) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var array $info
|
||||
*/
|
||||
foreach ($unpaidAmount as $currencyId => $info) {
|
||||
$amount = bcmul($info['sum'], '-1');
|
||||
$currency = $this->currencyRepos->find((int)$currencyId);
|
||||
if (null === $currency) {
|
||||
continue;
|
||||
|
@ -851,17 +851,25 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Collection $set */
|
||||
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
|
||||
$currency = $bill->transactionCurrency;
|
||||
if ($set->count() > 0) {
|
||||
$journalIds = $set->pluck('id')->toArray();
|
||||
$amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount');
|
||||
$return[$currency->id] = $return[$currency->id] ?? [
|
||||
'id' => (string)$currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
'code' => $currency->code,
|
||||
'decimal_places' => $currency->decimal_places,
|
||||
'sum' => '0',
|
||||
];
|
||||
|
||||
$return[$currency->id] = $return[$currency->id] ?? [
|
||||
'id' => (string)$currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
'code' => $currency->code,
|
||||
'decimal_places' => $currency->decimal_places,
|
||||
'sum' => '0',
|
||||
];
|
||||
|
||||
/** @var TransactionJournal $transactionJournal */
|
||||
foreach ($set as $transactionJournal) {
|
||||
/** @var Transaction $sourceTransaction */
|
||||
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||
$amount = (string)$sourceTransaction->amount;
|
||||
if ((int)$sourceTransaction->foreign_currency_id === (int)$currency->id) {
|
||||
// use foreign amount instead!
|
||||
$amount = (string)$sourceTransaction->foreign_amount;
|
||||
}
|
||||
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user