Better formatting for split transactions.

This commit is contained in:
James Cole 2016-05-13 19:40:13 +02:00
parent 5166171e5d
commit 5a6967cefd
6 changed files with 77 additions and 16 deletions

View File

@ -163,12 +163,11 @@ class ReportController extends Controller
$exists = false; $exists = false;
$journals = new Collection; $journals = new Collection;
$dayBeforeBalance = Steam::balance($account, $dayBefore); $dayBeforeBalance = Steam::balance($account, $dayBefore);
/* /*
* Is there even activity on this account between the requested dates? * Is there even activity on this account between the requested dates?
*/ */
if ($start->between($first, $last) || $end->between($first, $last)) { if ($start->between($first, $last) || $end->between($first, $last)) {
$exists = true; $exists = true;
$journals = $repos->journalsInPeriod($accounts, [], $start, $end); $journals = $repos->journalsInPeriod($accounts, [], $start, $end);
} }
@ -203,7 +202,6 @@ class ReportController extends Controller
$auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance; $auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance;
} }
$reportType = 'audit'; $reportType = 'audit';
$accountIds = join(',', $accounts->pluck('id')->toArray()); $accountIds = join(',', $accounts->pluck('id')->toArray());

View File

@ -368,13 +368,10 @@ class AccountRepository implements AccountRepositoryInterface
->sortCorrectly() ->sortCorrectly()
->first(['transaction_journals.*']); ->first(['transaction_journals.*']);
if (is_null($journal)) { if (is_null($journal)) {
$date = new Carbon; return new Carbon('1900-01-01');
$date->addYear(); // in the future.
} else {
$date = $journal->date;
} }
return $date; return $journal->date;
} }
/** /**
@ -390,16 +387,15 @@ class AccountRepository implements AccountRepositoryInterface
$journal = TransactionJournal:: $journal = TransactionJournal::
leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'ASC')
->orderBy('transaction_journals.order', 'DESC')
->orderBy('transaction_journals.id', 'ÅSC')
->first(['transaction_journals.*']); ->first(['transaction_journals.*']);
if (is_null($journal)) { if (is_null($journal)) {
$date = new Carbon; return new Carbon('1900-01-01');
$date->addYear(); // in the future.
} else {
$date = $journal->date;
} }
return $date; return $journal->date;
} }
/** /**

View File

@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Twig; namespace FireflyIII\Support\Twig;
use Amount;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
@ -18,6 +19,28 @@ use Twig_SimpleFunction;
*/ */
class Journal extends Twig_Extension class Journal extends Twig_Extension
{ {
/**
* @return Twig_SimpleFunction
*/
public function formatPerspective(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatPerspective', function (TransactionJournal $journal, Account $account) {
// get the account amount:
$transaction = $journal->transactions()->where('transactions.account_id', $account->id)->first();
$amount = $transaction->amount;
if ($journal->isWithdrawal()) {
$amount = bcmul($amount, '-1');
}
$formatted = Amount::format($amount, true);
return $formatted . ' (' . Amount::formatJournal($journal) . ')';
}
);
}
/** /**
* @return Twig_SimpleFunction * @return Twig_SimpleFunction
*/ */
@ -71,6 +94,7 @@ class Journal extends Twig_Extension
$functions = [ $functions = [
$this->getSourceAccount(), $this->getSourceAccount(),
$this->getDestinationAccount(), $this->getDestinationAccount(),
$this->formatPerspective(),
]; ];
return $functions; return $functions;

View File

@ -38,7 +38,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3> <h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{% include 'list.journals' with {sorting:true} %} {% include 'list.journals' with {sorting:true, accountPerspective: account} %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -57,7 +57,11 @@
</td> </td>
<td> <td>
{{ journal|formatJournal }} {% if not accountPerspective %}
{{ journal|formatJournal }}
{% else %}
{{ formatPerspective(journal, accountPerspective)|raw }}
{% endif %}
</td> </td>
<td class="hidden-sm hidden-xs"> <td class="hidden-sm hidden-xs">
{{ journal.date.formatLocalized(monthAndDayFormat) }} {{ journal.date.formatLocalized(monthAndDayFormat) }}

View File

@ -135,6 +135,45 @@
]) }}">{{ 'report_all_time_quick'|_ }}</a> ]) }}">{{ 'report_all_time_quick'|_ }}</a>
</li> </li>
</ul> </ul>
<h4>{{ 'quick_link_audit_report'|_ }}</h4>
<ul>
<li>
<a href="{{ route('reports.report',
['audit',
'currentMonthStart',
'currentMonthEnd',
accountList
]) }}">{{ 'report_this_month_quick'|_ }}</a>
</li>
<li>
<a href="{{ route('reports.report',
['audit',
'currentYearStart',
'currentYearEnd',
accountList
]) }}">{{ 'report_this_year_quick'|_ }}</a>
</li>
{% if customFiscalYear == 1 %}
<li>
<a href="{{ route('reports.report',
['audit',
'currentFiscalYearStart',
'currentFiscalYearEnd',
accountList
]) }}">{{ 'report_this_fiscal_year_quick'|_ }}</a>
</li>
{% endif %}
<li>
<a href="{{ route('reports.report',
['audit',
start.format('Ymd'),
'currentMonthEnd',
accountList
]) }}">{{ 'report_all_time_quick'|_ }}</a>
</li>
</ul>
<p> <p>
<em>{{ 'reports_can_bookmark'|_ }}</em> <em>{{ 'reports_can_bookmark'|_ }}</em>
</p> </p>