From 2e7edd033c0a4275b80535109700104fb807022c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 16 May 2015 16:47:52 +0200 Subject: [PATCH] Some expanded things. --- app/Helpers/Report/ReportHelper.php | 9 ++++++ app/Helpers/Report/ReportQuery.php | 29 ++++++++++++++++++-- app/Helpers/Report/ReportQueryInterface.php | 12 +++++++- resources/twig/partials/reports/balance.twig | 8 +++++- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 100a3fd753..13ea2f58e6 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -136,6 +136,15 @@ class ReportHelper implements ReportHelperInterface } // then a new line for without budget. + $empty = new BalanceLine; + foreach ($accounts as $account) { + $spent = $this->query->spentNoBudget($account, $start, $end); + $balanceEntry = new BalanceEntry; + $balanceEntry->setAccount($account); + $balanceEntry->setSpent($spent); + $empty->addBalanceEntry($balanceEntry); + } + $balance->addBalanceLine($empty); $balance->setBalanceHeader($header); diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index de586af539..fdaed62f68 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -138,7 +138,6 @@ class ReportQuery implements ReportQueryInterface } - /** * This method returns all "income" journals in a certain period, which are both transfers from a shared account * and "ordinary" deposits. The query used is almost equal to ReportQueryInterface::journalsByRevenueAccount but it does @@ -203,7 +202,6 @@ class ReportQuery implements ReportQueryInterface } - /** * Gets a list of expense accounts and the expenses therein, grouped by that expense account. * This result excludes transfers to shared accounts which are expenses, technically. @@ -273,8 +271,9 @@ class ReportQuery implements ReportQueryInterface return floatval( Auth::user()->transactionjournals() - ->leftJoin('transactions' , 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->transactionTypes(['Withdrawal']) ->where('transactions.amount', '<', 0) ->where('transactions.account_id', $account->id) ->before($end) @@ -284,6 +283,30 @@ class ReportQuery implements ReportQueryInterface ); } + /** + * @param Account $account + * @param Carbon $start + * @param Carbon $end + * @param bool $shared + * + * @return float + */ + public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false) + { + return floatval( + Auth::user()->transactionjournals() + ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->where('transactions.amount', '<', 0) + ->transactionTypes(['Withdrawal']) + ->where('transactions.account_id', $account->id) + ->before($end) + ->after($start) + ->whereNull('budget_transaction_journal.budget_id') + ->sum('transactions.amount') + ); + } + /** * @param Carbon $start * @param Carbon $end diff --git a/app/Helpers/Report/ReportQueryInterface.php b/app/Helpers/Report/ReportQueryInterface.php index b189f47ed0..b732337ff4 100644 --- a/app/Helpers/Report/ReportQueryInterface.php +++ b/app/Helpers/Report/ReportQueryInterface.php @@ -65,7 +65,17 @@ interface ReportQueryInterface * * @return float */ - public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end, $shared = false); // I think shared is irrelevant. + public function spentInBudget(Account $account, Budget $budget, Carbon $start, Carbon $end, $shared = false); + + /** + * @param Account $account + * @param Carbon $start + * @param Carbon $end + * @param bool $shared + * + * @return float + */ + public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false); /** diff --git a/resources/twig/partials/reports/balance.twig b/resources/twig/partials/reports/balance.twig index 7456fbb6ad..3536d21e01 100644 --- a/resources/twig/partials/reports/balance.twig +++ b/resources/twig/partials/reports/balance.twig @@ -18,7 +18,13 @@ {% for balanceLine in balance.getBalanceLines %} - {{ balanceLine.getBudget.name }} + + {% if balanceLine.getBudget %} + {{ balanceLine.getBudget.name }} + {% else %} + {{ 'noBudget'|_ }} + {% endif %} + {{ balanceLine.getBudgetAmount|formatAmount }} {% for balanceEntry in balanceLine.getBalanceEntries %}