mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-10 23:45:48 -06:00
Fixed something in the reports.
This commit is contained in:
parent
ff5bf0c6e5
commit
9f29a2e04f
@ -56,6 +56,19 @@ class AccountReportHelper implements AccountReportHelperInterface
|
||||
->groupBy('accounts.id')
|
||||
->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);
|
||||
|
||||
// a special consideration for accounts that did exist on this exact day.
|
||||
// we also grab the balance from today just in case, to see if that changes things.
|
||||
// it's a fall back for users who (rightly so) start keeping score at the first of
|
||||
// the month and find the first report lacking / broken.
|
||||
$backupSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->whereIn('accounts.id', $ids)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->where('transaction_journals.date', '<=', $start->format('Y-m-d'))
|
||||
->groupBy('accounts.id')
|
||||
->get(['accounts.id', DB::raw('SUM(`transactions`.`amount`) as `balance`')]);
|
||||
|
||||
// and end:
|
||||
$endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
@ -68,7 +81,7 @@ class AccountReportHelper implements AccountReportHelperInterface
|
||||
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($startSet, $endSet) {
|
||||
function (Account $account) use ($startSet, $endSet, $backupSet) {
|
||||
/**
|
||||
* The balance for today always incorporates transactions
|
||||
* made on today. So to get todays "start" balance, we sub one
|
||||
@ -82,8 +95,20 @@ class AccountReportHelper implements AccountReportHelperInterface
|
||||
return $account->id == $entry->id;
|
||||
}
|
||||
);
|
||||
// grab entry from current backup as well:
|
||||
$currentBackup = $backupSet->filter(
|
||||
function (Account $entry) use ($account) {
|
||||
return $account->id == $entry->id;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if ($currentStart->first()) {
|
||||
$account->startBalance = $currentStart->first()->balance;
|
||||
} else {
|
||||
if (is_null($currentStart->first()) && !is_null($currentBackup->first())) {
|
||||
$account->startBalance = $currentBackup->first()->balance;
|
||||
}
|
||||
}
|
||||
|
||||
$currentEnd = $endSet->filter(
|
||||
|
Loading…
Reference in New Issue
Block a user