mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Some code cleanup.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace FireflyIII\Support\Twig;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
@@ -21,18 +22,25 @@ class Budget extends Twig_Extension
|
||||
{
|
||||
$functions = [];
|
||||
$functions[] = new Twig_SimpleFunction(
|
||||
'spentInRepetitionCorrected', function(LimitRepetition $repetition) {
|
||||
'spentInRepetitionCorrected', function (LimitRepetition $repetition) {
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($repetition->id);
|
||||
$cache->addProperty('spentInRepetitionCorrected');
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
$sum
|
||||
= Auth::user()->transactionjournals()
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
|
||||
->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||
->before($repetition->enddate)
|
||||
->after($repetition->startdate)
|
||||
->where('limit_repetitions.id', '=', $repetition->id)
|
||||
->get(['transaction_journals.*'])->sum('amount');
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
|
||||
->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||
->before($repetition->enddate)
|
||||
->after($repetition->startdate)
|
||||
->where('limit_repetitions.id', '=', $repetition->id)
|
||||
->get(['transaction_journals.*'])->sum('amount');
|
||||
$cache->store($sum);
|
||||
|
||||
return floatval($sum);
|
||||
return $sum;
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -87,8 +87,18 @@ class Journal extends Twig_Extension
|
||||
|
||||
$functions[] = new Twig_SimpleFunction(
|
||||
'relevantTags', function(TransactionJournal $journal) {
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('relevantTags');
|
||||
$cache->addProperty($journal->id);
|
||||
|
||||
if($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if ($journal->tags->count() == 0) {
|
||||
return App::make('amount')->formatJournal($journal);
|
||||
$string = App::make('amount')->formatJournal($journal);
|
||||
$cache->store($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +107,10 @@ class Journal extends Twig_Extension
|
||||
// return tag formatted for a "balancing act", even if other
|
||||
// tags are present.
|
||||
$amount = App::make('amount')->format($journal->actual_amount, false);
|
||||
|
||||
return '<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>';
|
||||
$cache->store($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -107,9 +118,10 @@ class Journal extends Twig_Extension
|
||||
*/
|
||||
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
|
||||
$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>';
|
||||
$cache->store($string);
|
||||
return $string;
|
||||
}
|
||||
/*
|
||||
* AdvancePayment with a withdrawal will show the amount with a link to
|
||||
@@ -118,13 +130,17 @@ class Journal extends Twig_Extension
|
||||
if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Withdrawal') {
|
||||
$amount = App::make('amount')->formatJournal($journal);
|
||||
|
||||
return '<a href="' . route('tags.show', [$tag->id]) . '">' . $amount . '</a>';
|
||||
$string = '<a href="' . route('tags.show', [$tag->id]) . '">' . $amount . '</a>';
|
||||
$cache->store($string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
if ($tag->tagMode == 'nothing') {
|
||||
// return the amount:
|
||||
return App::make('amount')->formatJournal($journal);
|
||||
$string = App::make('amount')->formatJournal($journal);
|
||||
$cache->store($string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user