Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fixed something in the reports.
James Cole9f29a2e04f3d
diff --git a/app/Helpers/Report/AccountReportHelper.php b/app/Helpers/Report/AccountReportHelper.phpindex 6913553b8e..728d5e11d9 100644--- a/app/Helpers/Report/AccountReportHelper.php+++ b/app/Helpers/Report/AccountReportHelper.php@@ -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 AccountReportHelperInterfacereturn $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(