diff --git a/app/models/Account.php b/app/models/Account.php index 6b67b16b73..846de07a47 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -72,6 +72,20 @@ class Account extends Ardent ); } + public function balanceBeforeJournal(TransactionJournal $journal) + { + return floatval( + $this->transactions() + ->leftJoin( + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + ) + ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) + ->where('transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s')) + ->where('transaction_journals.id','!=',$journal->id) + ->sum('transactions.amount') + ); + } + /** * Transactions. * diff --git a/app/views/transactions/show.blade.php b/app/views/transactions/show.blade.php index 308555683d..b43dabb70f 100644 --- a/app/views/transactions/show.blade.php +++ b/app/views/transactions/show.blade.php @@ -46,12 +46,16 @@

Transactions

@foreach($journal->transactions as $t) -

{{{$t->account->name}}}
{{{$t->account->accounttype->description}}}

+

{{{$t->account->name}}}
{{{$t->account->accounttype->description}}}

+ + + + @if(!is_null($t->description))
Amount {{mf($t->amount)}}
New balance{{mf($t->account->balanceBeforeJournal($journal))}} → {{mf($t->account->balanceBeforeJournal($journal) + $t->amount)}}
Description