Improve view for transactions.

This commit is contained in:
James Cole
2018-03-11 14:09:44 +01:00
parent a9870b35be
commit c2dfbcba10
4 changed files with 103 additions and 158 deletions

View File

@@ -33,10 +33,12 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface; use FireflyIII\Repositories\Journal\JournalTaskerInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences; use Preferences;
use Symfony\Component\HttpFoundation\ParameterBag;
use View; use View;
/** /**
@@ -177,6 +179,7 @@ class TransactionController extends Controller
* @param JournalTaskerInterface $tasker * @param JournalTaskerInterface $tasker
* @param LinkTypeRepositoryInterface $linkTypeRepository * @param LinkTypeRepositoryInterface $linkTypeRepository
* *
* @throws FireflyException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/ */
public function show(TransactionJournal $journal, JournalTaskerInterface $tasker, LinkTypeRepositoryInterface $linkTypeRepository) public function show(TransactionJournal $journal, JournalTaskerInterface $tasker, LinkTypeRepositoryInterface $linkTypeRepository)
@@ -184,15 +187,32 @@ class TransactionController extends Controller
if ($this->isOpeningBalance($journal)) { if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($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 return redirect(route('accounts.reconcile.show', [$journal->id])); // @codeCoverageIgnore
} }
$linkTypes = $linkTypeRepository->get(); $linkTypes = $linkTypeRepository->get();
$links = $linkTypeRepository->getLinks($journal); $links = $linkTypeRepository->getLinks($journal);
$events = $tasker->getPiggyBankEvents($journal);
$transactions = $tasker->getTransactionsOverview($journal); // get transactions using the collector:
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type); // needs a lot of extra data to match the journal collector. Or just expand that one.
$subTitle = trans('firefly.' . $what) . ' "' . $journal->description . '"'; // 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')); return view('transactions.show', compact('journal', 'events', 'subTitle', 'what', 'transactions', 'linkTypes', 'links'));
} }

View File

@@ -24,11 +24,9 @@ namespace FireflyIII\Support\Models;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -63,16 +61,6 @@ trait TransactionJournalTrait
return false; return false;
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
abstract public function budgets(): BelongsToMany;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
abstract public function categories(): BelongsToMany;
/** /**
* @deprecated * @deprecated
* @return Collection * @return Collection
@@ -117,79 +105,6 @@ trait TransactionJournalTrait
return $list; return $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 * @deprecated
* @return Collection * @return Collection

View File

@@ -101,17 +101,15 @@ class Transaction extends Twig_Extension
public function amountArray(array $transaction): string public function amountArray(array $transaction): string
{ {
// first display amount: // first display amount:
$amount = TransactionType::WITHDRAWAL === $transaction['journal_type'] ? $transaction['source_amount'] $amount = strval($transaction['amount']);
: $transaction['destination_amount'];
$fakeCurrency = new TransactionCurrency; $fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['transaction_currency_dp']; $fakeCurrency->decimal_places = $transaction['currency_dp'];
$fakeCurrency->symbol = $transaction['transaction_currency_symbol']; $fakeCurrency->symbol = $transaction['currency_symbol'];
$string = app('amount')->formatAnything($fakeCurrency, $amount, true); $string = app('amount')->formatAnything($fakeCurrency, $amount, true);
// then display (if present) the foreign amount: // then display (if present) the foreign amount:
if (null !== $transaction['foreign_source_amount']) { if (null !== $transaction['foreign_amount']) {
$amount = TransactionType::WITHDRAWAL === $transaction['journal_type'] ? $transaction['foreign_source_amount'] $amount = strval($transaction['foreign_amount']);
: $transaction['foreign_destination_amount'];
$fakeCurrency = new TransactionCurrency; $fakeCurrency = new TransactionCurrency;
$fakeCurrency->decimal_places = $transaction['foreign_currency_dp']; $fakeCurrency->decimal_places = $transaction['foreign_currency_dp'];
$fakeCurrency->symbol = $transaction['foreign_currency_symbol']; $fakeCurrency->symbol = $transaction['foreign_currency_symbol'];

View File

@@ -88,10 +88,13 @@
{{ journal|journalTotalAmount }} {{ journal|journalTotalAmount }}
{# if more transactions, list each one: #} {# 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> </td>
</tr> </tr>
<tr> <tr>
@@ -366,64 +369,73 @@
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'transactions'|_ }}</h3> <h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div> </div>
<table class="table table-bordered table-striped"> <div class="box-body no-padding">
<thead> <table class="table table-bordered table-striped">
<tr> <thead>
<th class="hidden-md hidden-sm hidden-xs">{{ trans('list.description') }}</th>
<th>{{ trans('list.source_account') }}</th>
<th class="hidden-sm hidden-xs">&#916;</th>
<th>{{ trans('list.destination_account') }}</th>
<th class="hidden-sm hidden-xs">&#916;</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 %}
<tr> <tr>
<td class="hidden-md hidden-sm hidden-xs"> <th class="hidden-md hidden-sm hidden-xs">{{ trans('list.description') }}</th>
{% if transaction.description == "" %} <th>{{ trans('list.source_account') }}</th>
{{ journal.description }} <th>{{ trans('list.destination_account') }}</th>
{% else %} <th>{{ trans('list.amount') }}</th>
{{ transaction.description }} <th class="hidden-md hidden-xs">{{ trans('list.budget') }}</th>
{% endif %} <th class="hidden-md hidden-xs">{{ trans('list.category') }}</th>
</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 %}
</td>
<td class="hidden-sm hidden-xs">
{{ formatSourceBefore(transaction) }} &rarr; {{ 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 %}
</td>
<td class="hidden-sm hidden-xs">
{{ formatDestinationBefore(transaction) }} &rarr; {{ 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> </tr>
{% endfor %} </thead>
</tbody> <tbody>
</table>
{% 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>
{{ 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> </div>
</div> </div>