Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Improve view for transactions.
James Colec2dfbcba1025
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.phpindex d6be82467f..e5aea753ad 100644--- a/app/Http/Controllers/TransactionController.php+++ b/app/Http/Controllers/TransactionController.php@@ -33,10 +33,12 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\Journal\JournalTaskerInterface;use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;use FireflyIII\Support\CacheProperties;+use FireflyIII\Transformers\TransactionTransformer;use Illuminate\Http\Request;use Illuminate\Support\Collection;use Log;use Preferences;+use Symfony\Component\HttpFoundation\ParameterBag;use View;/**@@ -177,6 +179,7 @@ class TransactionController extends Controller* @param JournalTaskerInterface $tasker* @param LinkTypeRepositoryInterface $linkTypeRepository*+ * @throws FireflyException* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View*/public function show(TransactionJournal $journal, JournalTaskerInterface $tasker, LinkTypeRepositoryInterface $linkTypeRepository)@@ -184,15 +187,32 @@ class TransactionController extends Controllerif ($this->isOpeningBalance($journal)) {return $this->redirectToAccount($journal);}- if (TransactionType::RECONCILIATION === $journal->transactionType->type) {+ $transactionType = $journal->transactionType->type;+ if (TransactionType::RECONCILIATION === $transactionType) {return redirect(route('accounts.reconcile.show', [$journal->id])); // @codeCoverageIgnore}- $linkTypes = $linkTypeRepository->get();- $links = $linkTypeRepository->getLinks($journal);- $events = $tasker->getPiggyBankEvents($journal);- $transactions = $tasker->getTransactionsOverview($journal);- $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);- $subTitle = trans('firefly.' . $what) . ' "' . $journal->description . '"';+ $linkTypes = $linkTypeRepository->get();+ $links = $linkTypeRepository->getLinks($journal);++ // get transactions using the collector:+ // needs a lot of extra data to match the journal collector. Or just expand that one.+ // collect transactions using the journal collector+ $collector = app(JournalCollectorInterface::class);+ $collector->setUser(auth()->user());+ $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();+ // filter on specific journals.+ $collector->setJournals(new Collection([$journal]));+ $set = $collector->getJournals();+ $transactions = [];+ $transformer = new TransactionTransformer(new ParameterBag);+ /** @var Transaction $transaction */+ foreach ($set as $transaction) {+ $transactions[] = $transformer->transform($transaction);+ }++ $events = $tasker->getPiggyBankEvents($journal);+ $what = strtolower($transactionType);+ $subTitle = trans('firefly.' . $what) . ' "' . $journal->description . '"';return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'linkTypes', 'links'));}diff --git a/app/Support/Models/TransactionJournalTrait.php b/app/Support/Models/TransactionJournalTrait.phpindex a782e669a1..943d5d9568 100644--- a/app/Support/Models/TransactionJournalTrait.php+++ b/app/Support/Models/TransactionJournalTrait.php@@ -24,11 +24,9 @@ namespace FireflyIII\Support\Models;use Carbon\Carbon;use FireflyIII\Models\Transaction;-use FireflyIII\Models\TransactionJournalMeta;use FireflyIII\Models\TransactionType;use FireflyIII\Support\CacheProperties;use Illuminate\Database\Eloquent\Builder;-use Illuminate\Database\Eloquent\Relations\BelongsToMany;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Support\Collection;@@ -63,16 +61,6 @@ trait TransactionJournalTraitreturn false;}- /**- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany- */- abstract public function budgets(): BelongsToMany;-- /**- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany- */- abstract public function categories(): BelongsToMany;-/*** @deprecated* @return Collection@@ -117,79 +105,6 @@ trait TransactionJournalTraitreturn $list;}- /**- * @deprecated- * @param string $name- *- * @return string- */- abstract public function getMeta(string $name);-- /**- *- * @return bool- */- abstract public function isDeposit(): bool;-- /**- * @return bool- */- abstract public function isOpeningBalance(): bool;-- /**- * @return bool- */- abstract public function isTransfer(): bool;-- /**- * @return bool- */- abstract public function isWithdrawal(): bool;-- /**- * @return \Illuminate\Database\Eloquent\Relations\HasMany- */- abstract public function piggyBankEvents(): HasMany;-- /**- * @deprecated- * @return int- */- public function piggyBankId(): int- {- if ($this->piggyBankEvents()->count() > 0) {- return $this->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;- }-- return 0;- }-- /**- * @deprecated- * @return Transaction- */- public function positiveTransaction(): Transaction- {- return $this->transactions()->where('amount', '>', 0)->first();- }-- /**- * Save the model to the database.- *- * @param array $options- *- * @return bool- */- abstract public function save(array $options = []): bool;-- /**- * @param string $name- * @param $value- *- * @return TransactionJournalMeta- */- abstract public function setMeta(string $name, $value): TransactionJournalMeta;-/*** @deprecated* @return Collectiondiff --git a/app/Support/Twig/Extension/Transaction.php b/app/Support/Twig/Extension/Transaction.phpindex 2d8bb0d66b..9e8c7bb071 100644--- a/app/Support/Twig/Extension/Transaction.php+++ b/app/Support/Twig/Extension/Transaction.php@@ -101,17 +101,15 @@ class Transaction extends Twig_Extensionpublic function amountArray(array $transaction): string{// first display amount:- $amount = TransactionType::WITHDRAWAL === $transaction['journal_type'] ? $transaction['source_amount']- : $transaction['destination_amount'];+ $amount = strval($transaction['amount']);$fakeCurrency = new TransactionCurrency;- $fakeCurrency->decimal_places = $transaction['transaction_currency_dp'];- $fakeCurrency->symbol = $transaction['transaction_currency_symbol'];+ $fakeCurrency->decimal_places = $transaction['currency_dp'];+ $fakeCurrency->symbol = $transaction['currency_symbol'];$string = app('amount')->formatAnything($fakeCurrency, $amount, true);// then display (if present) the foreign amount:- if (null !== $transaction['foreign_source_amount']) {- $amount = TransactionType::WITHDRAWAL === $transaction['journal_type'] ? $transaction['foreign_source_amount']- : $transaction['foreign_destination_amount'];+ if (null !== $transaction['foreign_amount']) {+ $amount = strval($transaction['foreign_amount']);$fakeCurrency = new TransactionCurrency;$fakeCurrency->decimal_places = $transaction['foreign_currency_dp'];$fakeCurrency->symbol = $transaction['foreign_currency_symbol'];diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twigindex d0cd6c494e..0867e62dcb 100644--- a/resources/views/transactions/show.twig+++ b/resources/views/transactions/show.twig@@ -88,10 +88,13 @@{{ journal|journalTotalAmount }}{# if more transactions, list each one: #}- {% if transactions|length > 1 %}- ({% for transaction in transactions %}{{ transaction|transactionArrayAmount }}{% if loop.index != loop.length %}, {% endif %}{% endfor %})- {% endif %}+ {% if transactions|length > 2 %}+ ({% for transaction in transactions %}+ {{ transaction|transactionArrayAmount }}+ {% if loop.index != loop.length %}, {% endif %}+ {% endfor %})+ {% endif %}</td></tr><tr>@@ -366,64 +369,73 @@<div class="box-header with-border"><h3 class="box-title">{{ 'transactions'|_ }}</h3></div>- <table class="table table-bordered table-striped">- <thead>- <tr>- <th class="hidden-md hidden-sm hidden-xs">{{ trans('list.description') }}</th>- <th>{{ trans('list.source_account') }}</th>- <th class="hidden-sm hidden-xs">Δ</th>- <th>{{ trans('list.destination_account') }}</th>- <th class="hidden-sm hidden-xs">Δ</th>- <th>{{ trans('list.amount') }}</th>- <th class="hidden-md hidden-xs">{{ trans('list.budget') }}</th>- <th class="hidden-md hidden-xs">{{ trans('list.category') }}</th>- </tr>- </thead>- <tbody>- {% for transaction in transactions %}+ <div class="box-body no-padding">+ <table class="table table-bordered table-striped">+ <thead><tr>- <td class="hidden-md hidden-sm hidden-xs">- {% if transaction.description == "" %}- {{ journal.description }}- {% else %}- {{ transaction.description }}- {% endif %}- </td>- <td>- {% if transaction.source_account_type == 'Cash account' %}- <span class="text-success">({{ 'cash'|_ }})</span>- {% else %}- <a href="{{ route('accounts.show', transaction.source_account_id) }}">{{ transaction.source_account_name }}</a>- {% endif %}+ <th class="hidden-md hidden-sm hidden-xs">{{ trans('list.description') }}</th>+ <th>{{ trans('list.source_account') }}</th>+ <th>{{ trans('list.destination_account') }}</th>+ <th>{{ trans('list.amount') }}</th>+ <th class="hidden-md hidden-xs">{{ trans('list.budget') }}</th>+ <th class="hidden-md hidden-xs">{{ trans('list.category') }}</th>+ </tr>+ </thead>+ <tbody>- </td>- <td class="hidden-sm hidden-xs">- {{ formatSourceBefore(transaction) }} → {{ formatSourceAfter(transaction) }}- </td>- <td>- {% if transaction.destination_account_type == 'Cash account' %}- <span class="text-success">({{ 'cash'|_ }})</span>- {% else %}- <a href="{{ route('accounts.show', transaction.destination_account_id) }}">{{ transaction.destination_account_name }}</a>- {% endif %}+ {% set maxIdentifier = ((transactions|length) / 2) -1 %}+ {% for x in 0..maxIdentifier %}+ <tr>+ {# loop each transaction in the array.#}+ {% for transaction in transactions %}+ {% if+ ((transaction.type == 'Withdrawal') and transaction.identifier == x and transaction.amount < 0)+ or+ ((transaction.type == 'Deposit' or transaction.type == 'Transfer') and transaction.identifier == x and transaction.amount > 0)+ %}+ <td class="hidden-md hidden-sm hidden-xs">+ {% if transaction.description == "" %}+ {{ journal.description }}+ {% else %}+ {{ transaction.description }}+ {% endif %}+ </td>+ <td>+ {% if transaction.source_type == 'Cash account' %}+ <span class="text-success">({{ 'cash'|_ }})</span>+ {% else %}+ <a href="{{ route('accounts.show', transaction.source_id) }}">{{ transaction.source_name }}</a>+ {% endif %}+ </td>+ <td>+ {% if transaction.destination_type == 'Cash account' %}+ <span class="text-success">({{ 'cash'|_ }})</span>+ {% else %}+ <a href="{{ route('accounts.show', transaction.destination_id) }}">{{ transaction.destination_name }}</a>+ {% endif %}- </td>- <td class="hidden-sm hidden-xs">- {{ formatDestinationBefore(transaction) }} → {{ formatDestinationAfter(transaction) }}- </td>- <td>- {{ transaction|transactionArrayAmount }}- </td>- <td class="hidden-md hidden-xs">- {{ transaction.source|transactionBudgets }}- </td>- <td class="hidden-md hidden-xs">- {{ transaction.source|transactionCategories }}- </td>- </tr>- {% endfor %}- </tbody>- </table>+ </td>+ <td>+ {{ transaction|transactionArrayAmount }}+ </td>+ <td class="hidden-md hidden-xs">+ {% if transaction.budget_id %}+ <a href="{{ route('budgets.show', transaction.budget_id) }}" title="{{ transaction.budget_name }}">{{ transaction.budget_name }}</a>+ {% endif %}+ </td>+ <td class="hidden-md hidden-xs">+ {% if transaction.category_id %}+ <a href="{{ route('categories.show', transaction.category_id) }}" title="{{ transaction.category_name }}">{{ transaction.category_name }}</a>+ {% endif %}+ </td>+ {% endif %}+ {% endfor %}++ </tr>+ {% endfor %}+ </tbody>+ </table>+ </div></div></div></div>