Fixed split journals views.

This commit is contained in:
James Cole
2016-05-17 16:00:27 +02:00
parent 65ecea3b1c
commit 4cbb0d9716
8 changed files with 119 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ namespace FireflyIII\Support\Twig;
use Amount;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties;
@@ -21,6 +22,31 @@ use Twig_SimpleFunction;
class Journal extends Twig_Extension
{
/**
* @return Twig_SimpleFunction
*/
public function formatBudgetPerspective(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatBudgetPerspective', function (TransactionJournal $journal, Budget $budget) {
// get the account amount:
$transactions = $journal->transactions()->where('transactions.amount', '<', 0)->get(['transactions.*']);
$amount = '0';
foreach ($transactions as $transaction) {
$currentBudget = $transaction->budgets->first();
if (!is_null($currentBudget) && $currentBudget->id === $budget->id) {
$amount = bcadd($amount, strval($transaction->amount));
}
}
$formatted = Amount::format($amount, true);
return $formatted . ' (' . Amount::formatJournal($journal) . ')';
}
);
}
/**
* @return Twig_SimpleFunction
*/
@@ -30,8 +56,12 @@ class Journal extends Twig_Extension
'formatPerspective', function (TransactionJournal $journal, Account $account) {
// get the account amount:
$transaction = $journal->transactions()->where('transactions.account_id', $account->id)->first();
$amount = $transaction->amount;
$transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);
$amount = '0';
foreach ($transactions as $transaction) {
$amount = bcadd($amount, strval($transaction->amount));
}
if ($journal->isWithdrawal()) {
$amount = bcmul($amount, '-1');
}
@@ -97,6 +127,7 @@ class Journal extends Twig_Extension
$this->getSourceAccount(),
$this->getDestinationAccount(),
$this->formatPerspective(),
$this->formatBudgetPerspective(),
$this->journalBudgets(),
$this->journalCategories(),
$this->transactionBudgets(),