diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 6ff1bb3eb8..24e318e979 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -163,12 +163,11 @@ class ReportController extends Controller $exists = false; $journals = new Collection; $dayBeforeBalance = Steam::balance($account, $dayBefore); - /* * Is there even activity on this account between the requested dates? */ if ($start->between($first, $last) || $end->between($first, $last)) { - $exists = true; + $exists = true; $journals = $repos->journalsInPeriod($accounts, [], $start, $end); } @@ -203,7 +202,6 @@ class ReportController extends Controller $auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance; } - $reportType = 'audit'; $accountIds = join(',', $accounts->pluck('id')->toArray()); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index ec420ba87f..169b3fcae1 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -368,13 +368,10 @@ class AccountRepository implements AccountRepositoryInterface ->sortCorrectly() ->first(['transaction_journals.*']); if (is_null($journal)) { - $date = new Carbon; - $date->addYear(); // in the future. - } else { - $date = $journal->date; + return new Carbon('1900-01-01'); } - return $date; + return $journal->date; } /** @@ -390,16 +387,15 @@ class AccountRepository implements AccountRepositoryInterface $journal = TransactionJournal:: leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.date', 'ASC') + ->orderBy('transaction_journals.order', 'DESC') + ->orderBy('transaction_journals.id', 'ÅSC') ->first(['transaction_journals.*']); if (is_null($journal)) { - $date = new Carbon; - $date->addYear(); // in the future. - } else { - $date = $journal->date; + return new Carbon('1900-01-01'); } - return $date; + return $journal->date; } /** diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index ff505f0e12..262c5be668 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -4,6 +4,7 @@ declare(strict_types = 1); namespace FireflyIII\Support\Twig; +use Amount; use FireflyIII\Models\Account; use FireflyIII\Models\TransactionJournal; use FireflyIII\Support\CacheProperties; @@ -18,6 +19,28 @@ use Twig_SimpleFunction; */ class Journal extends Twig_Extension { + /** + * @return Twig_SimpleFunction + */ + public function formatPerspective(): Twig_SimpleFunction + { + return new Twig_SimpleFunction( + 'formatPerspective', function (TransactionJournal $journal, Account $account) { + + // get the account amount: + $transaction = $journal->transactions()->where('transactions.account_id', $account->id)->first(); + $amount = $transaction->amount; + if ($journal->isWithdrawal()) { + $amount = bcmul($amount, '-1'); + } + + $formatted = Amount::format($amount, true); + + return $formatted . ' (' . Amount::formatJournal($journal) . ')'; + } + ); + } + /** * @return Twig_SimpleFunction */ @@ -71,6 +94,7 @@ class Journal extends Twig_Extension $functions = [ $this->getSourceAccount(), $this->getDestinationAccount(), + $this->formatPerspective(), ]; return $functions; diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig index b623f6adaa..f6456825d1 100644 --- a/resources/views/accounts/show.twig +++ b/resources/views/accounts/show.twig @@ -38,7 +38,7 @@