From 374b90fb009a9e719d0e8f5f8fe7f43b965f4421 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 18 May 2015 17:04:10 +0200 Subject: [PATCH] Show correct amount [skip ci] --- app/Models/TransactionJournal.php | 22 ++++++++++++++++++++++ resources/twig/list/journals.twig | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 5dc0b73550..9bbe977e46 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -152,6 +152,28 @@ class TransactionJournal extends Model return $this->hasMany('FireflyIII\Models\Transaction'); } + /** + * @return float + */ + public function getCorrectedActualAmountAttribute() + { + $amount = 0; + $type = $this->transactionType->type; + /** @var Transaction $t */ + foreach ($this->transactions as $t) { + if ($t->amount > 0 && $type != 'Withdrawal') { + $amount = floatval($t->amount); + break; + } + if ($t->amount < 0 && $type == 'Withdrawal') { + $amount = floatval($t->amount); + break; + } + } + + return $amount; + } + /** * @codeCoverageIgnore * @return array diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index c62a069636..78812ceda0 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -57,7 +57,7 @@ {% if not hideTags %} {{ relevantTags(journal)|raw }} {% else %} - {{ journal.actualAmount|formatAmount }} + {{ journal.correctedActualAmount|formatAmount }} {% endif %}