mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expanded the amount thing.
This commit is contained in:
parent
a9254c5c9a
commit
4b2dcc74d4
@ -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 Model
|
||||
return $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\BelongsTo
|
||||
|
@ -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);
|
||||
|
@ -78,16 +78,36 @@ class Journal extends Twig_Extension
|
||||
if ($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 . '</span>';
|
||||
. '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
|
||||
}
|
||||
if($tag->tagMode == 'nothing') {
|
||||
|
||||
/*
|
||||
* 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 . '</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') {
|
||||
// return the amount:
|
||||
return App::make('amount')->formatJournal($journal);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user