mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-07-22 03:48:41 -07:00
Merge pull request #11787 from R1DEN/main
Fix chart API balance carry-forward bug
This commit is contained in:
@@ -142,23 +142,30 @@ class AccountController extends Controller
|
||||
}
|
||||
// create array of values to collect.
|
||||
|
||||
while ($currentStart <= $params['end']) {
|
||||
$format = $currentStart->format('Y-m-d');
|
||||
$label = $currentStart->toAtomString();
|
||||
$balance = array_key_exists($format, $range) ? $range[$format]['balance'] : $previous;
|
||||
$previous = $balance;
|
||||
$currentSet['entries'][$label] = $balance;
|
||||
$rangeDates = array_keys($range);
|
||||
$rangeIdx = 0;
|
||||
$rangeCount = count($rangeDates);
|
||||
|
||||
// do the same for the primary currency balance, if relevant:
|
||||
while ($currentStart <= $params['end']) {
|
||||
$format = $currentStart->format('Y-m-d');
|
||||
$label = $currentStart->toAtomString();
|
||||
|
||||
// Advance through all range entries up to current chart date
|
||||
while ($rangeIdx < $rangeCount && $rangeDates[$rangeIdx] <= $format) {
|
||||
$previous = $range[$rangeDates[$rangeIdx]]['balance'];
|
||||
if ($this->convertToPrimary) {
|
||||
$pcPrevious = $range[$rangeDates[$rangeIdx]]['pc_balance'];
|
||||
}
|
||||
++$rangeIdx;
|
||||
}
|
||||
|
||||
$currentSet['entries'][$label] = $previous;
|
||||
$pcBalance = null;
|
||||
if ($this->convertToPrimary) {
|
||||
$pcBalance = array_key_exists($format, $range) ? $range[$format]['pc_balance'] : $pcPrevious;
|
||||
$pcPrevious = $pcBalance;
|
||||
$currentSet['pc_entries'][$label] = $pcBalance;
|
||||
$currentSet['pc_entries'][$label] = $pcPrevious;
|
||||
}
|
||||
$currentStart = Navigation::addPeriod($currentStart, $period);
|
||||
|
||||
// $currentStart->addDay();
|
||||
$currentStart = Navigation::addPeriod($currentStart, $period);
|
||||
}
|
||||
$this->chartData[] = $currentSet;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ class Steam
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
|
||||
->where('transaction_journals.date', $inclusive ? '<=' : '<', $date->format('Y-m-d H:i:s'))
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->groupBy(['transactions.account_id', 'transaction_currencies.code'])
|
||||
->get(['transactions.account_id', 'transaction_currencies.code', DB::raw('SUM(transactions.amount) as sum_of_amount')])
|
||||
->toArray()
|
||||
@@ -469,7 +470,7 @@ class Steam
|
||||
->transactions()
|
||||
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d H:i:s'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d H:i:s'))
|
||||
->groupBy('transaction_journals.date')
|
||||
->groupBy('transactions.transaction_currency_id')
|
||||
->orderBy('transaction_journals.date', 'ASC')
|
||||
|
||||
Reference in New Issue
Block a user