Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expanded the amount thing.
James Cole4b2dcc74d480
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex a102244030..fc98ff41be 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -64,14 +64,43 @@ class TransactionJournal extends Model*/public function getAmountAttribute(){+ $amount = 0;/** @var Transaction $t */foreach ($this->transactions as $t) {if ($t->amount > 0) {- return floatval($t->amount);+ $amount = floatval($t->amount);}}- return 0;+ /*+ * If the journal has tags, it gets complicated.+ */+ if ($this->tags->count() == 0) {+ return $amount;+ }+ // if journal is part of advancePayment AND journal is a withdrawal,+ // then journal is being repaid by other journals, so the actual amount will lower:+ /** @var Tag $tag */+ $tag = $this->tags()->where('tagMode', 'advancePayment')->first();+ if ($tag && $this->transactionType->type == 'Withdrawal') {+ // loop other deposits, remove from our amount.+ $others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get();+ foreach ($others as $other) {+ $amount -= $other->amount;+ }+ return $amount;+ }++ return $amount;+ }++ /**+ * @codeCoverageIgnore+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany+ */+ public function tags()+ {+ return $this->belongsToMany('FireflyIII\Models\Tag');}/**@@ -97,7 +126,6 @@ class TransactionJournal extends Modelreturn $this->transactions()->first()->account;}-/*** @codeCoverageIgnore* @return \Illuminate\Database\Eloquent\Relations\HasMany@@ -275,15 +303,6 @@ class TransactionJournal extends Model$this->attributes['encrypted'] = true;}- /**- * @codeCoverageIgnore- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany- */- public function tags()- {- return $this->belongsToMany('FireflyIII\Models\Tag');- }-/*** @codeCoverageIgnore* @return \Illuminate\Database\Eloquent\Relations\BelongsTodiff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex 583b7e73a9..8a1916e9ca 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -84,32 +84,20 @@ class Amount*/public function formatJournal(TransactionJournal $journal, $coloured = true){- $showPositive = true;if (is_null($journal->symbol)) {$symbol = $journal->transactionCurrency->symbol;} else {$symbol = $journal->symbol;}- $amount = 0;-- if (is_null($journal->type)) {- $type = $journal->transactionType->type;- } else {- $type = $journal->type;+ $amount = $journal->amount;+ if ($journal->transactionType->type == 'Withdrawal') {+ $amount = $amount * -1;}-- if ($type == 'Withdrawal') {- $showPositive = false;+ if ($journal->transactionType->type == 'Transfer' && $coloured) {+ return '<span class="text-info">' . $this->formatWithSymbol($symbol, $amount, false) . '</span>';}-- foreach ($journal->transactions as $t) {- if (floatval($t->amount) > 0 && $showPositive === true) {- $amount = floatval($t->amount);- break;- }- if (floatval($t->amount) < 0 && $showPositive === false) {- $amount = floatval($t->amount);- }+ if ($journal->transactionType->type == 'Transfer' && !$coloured) {+ return $this->formatWithSymbol($symbol, $amount, false);}return $this->formatWithSymbol($symbol, $amount, $coloured);diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.phpindex 093f617084..b1c7eac663 100644--- a/app/Support/Twig/Journal.php+++ b/app/Support/Twig/Journal.php@@ -78,16 +78,36 @@ class Journal extends Twig_Extensionif ($journal->tags->count() == 0) {return App::make('amount')->formatJournal($journal);}++foreach ($journal->tags as $tag) {if ($tag->tagMode == 'balancingAct') {// return tag formatted for a "balancing act", even if other// tags are present.$amount = App::make('amount')->formatJournal($journal, false);+ return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount+ . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';+ }+ /*+ * AdvancePayment with a deposit will show the tag instead of the amount:+ */+ if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') {+ $amount = App::make('amount')->formatJournal($journal, false);return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount- . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</span>';+ . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';+ }+ /*+ * AdvancePayment with a withdrawal will show the amount with a link to+ * the tag. The TransactionJournal should properly calculate the amount.+ */+ if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Withdrawal') {+ $amount = App::make('amount')->formatJournal($journal);+ return '<a href="' . route('tags.show', $tag->id) . '">' . $amount . '</a>';}- if($tag->tagMode == 'nothing') {+++ if ($tag->tagMode == 'nothing') {// return the amount:return App::make('amount')->formatJournal($journal);}