mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Cleaning up the relevantTags thing [skip ci]
This commit is contained in:
@@ -4,6 +4,7 @@ namespace FireflyIII\Support\Twig;
|
|||||||
|
|
||||||
|
|
||||||
use App;
|
use App;
|
||||||
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Twig_Extension;
|
use Twig_Extension;
|
||||||
@@ -124,35 +125,72 @@ class Journal extends Twig_Extension
|
|||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
$count = $journal->tags->count();
|
||||||
|
$string = '';
|
||||||
|
|
||||||
|
if ($count === 0) {
|
||||||
|
$string = $this->relevantTagsNoTags($journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($count === 1) {
|
||||||
|
$string = $this->relevantTagsSingle($journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($count > 1) {
|
||||||
|
$string = $this->relevantTagsMulti($journal);
|
||||||
|
}
|
||||||
|
|
||||||
if ($journal->tags->count() == 0) {
|
|
||||||
$string = App::make('amount')->formatJournal($journal);
|
|
||||||
$cache->store($string);
|
$cache->store($string);
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function relevantTagsNoTags(TransactionJournal $journal)
|
||||||
|
{
|
||||||
|
return App::make('amount')->formatJournal($journal);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($journal->tags as $tag) {
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function relevantTagsSingle(TransactionJournal $journal)
|
||||||
|
{
|
||||||
|
$tag = $journal->tags()->first();
|
||||||
|
|
||||||
|
return $this->formatJournalByTag($journal, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @param Tag $tag
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function formatJournalByTag(TransactionJournal $journal, Tag $tag)
|
||||||
|
{
|
||||||
if ($tag->tagMode == 'balancingAct') {
|
if ($tag->tagMode == 'balancingAct') {
|
||||||
// return tag formatted for a "balancing act", even if other
|
// return tag formatted for a "balancing act", even if other
|
||||||
// tags are present.
|
// tags are present.
|
||||||
$amount = App::make('amount')->format($journal->actual_amount, false);
|
$amount = App::make('amount')->format($journal->actual_amount, false);
|
||||||
$string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
|
$string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
|
||||||
. '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
|
. '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
|
||||||
$cache->store($string);
|
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* AdvancePayment with a deposit will show the tag instead of the amount:
|
|
||||||
*/
|
|
||||||
if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') {
|
if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') {
|
||||||
$amount = App::make('amount')->formatJournal($journal, false);
|
$amount = App::make('amount')->formatJournal($journal, false);
|
||||||
$string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
|
$string = '<a href="' . route('tags.show', [$tag->id]) . '" class="label label-success" title="' . $amount
|
||||||
. '"><i class="fa fa-fw fa-sort-numeric-desc"></i> ' . $tag->tag . '</a>';
|
. '"><i class="fa fa-fw fa-sort-numeric-desc"></i> ' . $tag->tag . '</a>';
|
||||||
$cache->store($string);
|
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
@@ -164,24 +202,38 @@ class Journal extends Twig_Extension
|
|||||||
$amount = App::make('amount')->formatJournal($journal);
|
$amount = App::make('amount')->formatJournal($journal);
|
||||||
|
|
||||||
$string = '<a href="' . route('tags.show', [$tag->id]) . '">' . $amount . '</a>';
|
$string = '<a href="' . route('tags.show', [$tag->id]) . '">' . $amount . '</a>';
|
||||||
$cache->store($string);
|
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($tag->tagMode == 'nothing') {
|
return $this->relevantTagsNoTags($journal);
|
||||||
// return the amount:
|
|
||||||
$string = App::make('amount')->formatJournal($journal);
|
|
||||||
$cache->store($string);
|
|
||||||
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
return 'TODO: ' . $journal->amount;
|
* If a transaction journal has multiple tags, we'll have to gamble. FF3
|
||||||
|
* does not yet block adding multiple 'special' tags so we must wing it.
|
||||||
|
*
|
||||||
|
* We grab the first special tag (for advancePayment and for balancingAct
|
||||||
|
* and try to format those. If they're not present (it's all normal tags),
|
||||||
|
* we can format like any other journal.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function relevantTagsMulti(TransactionJournal $journal)
|
||||||
|
{
|
||||||
|
$firstBalancingAct = $journal->tags()->where('tagMode', 'balancingAct')->first();
|
||||||
|
if ($firstBalancingAct) {
|
||||||
|
return $this->formatJournalByTag($journal, $firstBalancingAct);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
$firstAdvancePayment = $journal->tags()->where('tagMode', 'advancePayment')->first();
|
||||||
|
if ($firstAdvancePayment) {
|
||||||
|
return $this->formatJournalByTag($journal, $firstAdvancePayment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->relevantTagsNoTags($journal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user