Skip to content

Firefly III: a personal finances manager

Small fix for opening balance issues in reports.

James Cole1a204d31e76a
diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php
index d43902e094..e5c81eb211 100644
--- a/app/Repositories/Account/AccountTasker.php
+++ b/app/Repositories/Account/AccountTasker.php
@@ -126,13 +126,15 @@ class AccountTasker implements AccountTaskerInterface
];
// get first journal date:
- $first = $repository->oldestJournal($account);
+ $first = $repository->oldestJournal($account);
+ Log::debug(sprintf('Date of first journal for %s is %s', $account->name, $first->date->format('Y-m-d')));
$entry['start_balance'] = $startSet[$account->id] ?? '0';
$entry['end_balance'] = $endSet[$account->id] ?? '0';
- if (!is_null($first->id) && $yesterday < $first->date && $end >= $first->date) {
- // something about balance?
+
+ // first journal exists, and is on start, then this is the actual opening balance:
+ if (!is_null($first->id) && $first->date->isSameDay($start)) {
$entry['start_balance'] = $first->transactions()->where('account_id', $account->id)->first()->amount;
- Log::debug(sprintf('Account was opened before %s, so opening balance is %f', $yesterday->format('Y-m-d'), $entry['start_balance']));
+ Log::debug(sprintf('Account %s was opened on %s, so opening balance is %f', $account->name, $start->format('Y-m-d'), $entry['start_balance']));
}
$return['start'] = bcadd($return['start'], $entry['start_balance']);
$return['end'] = bcadd($return['end'], $entry['end_balance']);