addProperty($journal->id); $cache->addProperty('typeIcon'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } $type = $journal->transactionType->type; switch ($type) { case 'Withdrawal': $txt = ''; break; case 'Deposit': $txt = ''; break; case 'Transfer': $txt = ''; break; case 'Opening balance': $txt = ''; break; default: $txt = ''; break; } $cache->store($txt); return $txt; }, ['is_safe' => ['html']] ); return $filters; } /** * @SuppressWarnings(PHPMD.CyclomaticComplexity) * * @return array */ public function getFunctions() { $functions = []; $functions[] = new Twig_SimpleFunction( 'invalidJournal', function(TransactionJournal $journal) { if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) { return true; } return false; } ); $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) { $string = App::make('amount')->formatJournal($journal); $cache->store($string); return $string; } 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')->format($journal->actual_amount, false); $string = ' ' . $tag->tag . ''; $cache->store($string); return $string; } /* * 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); $string = ' ' . $tag->tag . ''; $cache->store($string); return $string; } /* * 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); $string = '' . $amount . ''; $cache->store($string); return $string; } if ($tag->tagMode == 'nothing') { // return the amount: $string = App::make('amount')->formatJournal($journal); $cache->store($string); return $string; } } return 'TODO: ' . $journal->amount; } ); return $functions; } /** * Returns the name of the extension. * * @return string The extension name */ public function getName() { return 'FireflyIII\Support\Twig\Journals'; } }