Small fix for opening balance issues in reports.

This commit is contained in:
James Cole
2017-02-12 10:58:37 +01:00
parent 0fe4273d4d
commit 1a204d31e7

View File

@@ -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']);