From 9e54eecfaa468ae6b1583e167bdbc0a9057dac56 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 20 May 2015 07:20:02 +0200 Subject: [PATCH] Fixed some views. --- app/Helpers/Collection/Expense.php | 4 +- app/Helpers/Collection/Income.php | 4 +- app/Helpers/Report/ReportHelper.php | 8 +-- app/Helpers/Report/ReportQuery.php | 54 ++++++++++++++----- resources/twig/partials/reports/expenses.twig | 4 +- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php index 3c0d908ab6..65f254b38d 100644 --- a/app/Helpers/Collection/Expense.php +++ b/app/Helpers/Collection/Expense.php @@ -37,14 +37,14 @@ class Expense $accountId = $entry->account_id; if (!$this->expenses->has($accountId)) { $newObject = new stdClass; - $newObject->amount = floatval($entry->queryAmount); + $newObject->amount = floatval($entry->amount); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; $this->expenses->put($accountId, $newObject); } else { $existing = $this->expenses->get($accountId); - $existing->amount += floatval($entry->queryAmount); + $existing->amount += floatval($entry->amount); $existing->count++; $this->expenses->put($accountId, $existing); } diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php index c3e60e0cf7..420105209a 100644 --- a/app/Helpers/Collection/Income.php +++ b/app/Helpers/Collection/Income.php @@ -38,14 +38,14 @@ class Income $accountId = $entry->account_id; if (!$this->incomes->has($accountId)) { $newObject = new stdClass; - $newObject->amount = floatval($entry->queryAmount); + $newObject->amount = floatval($entry->amount); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; $this->incomes->put($accountId, $newObject); } else { $existing = $this->incomes->get($accountId); - $existing->amount += floatval($entry->queryAmount); + $existing->amount += floatval($entry->amount); $existing->count++; $this->incomes->put($accountId, $existing); } diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index deefb7d899..0329bf1dbe 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -332,9 +332,9 @@ class ReportHelper implements ReportHelperInterface public function getExpenseReport($start, $end, $shared) { $object = new Expense; - $set = $this->query->expenseInPeriod($start, $end, $shared); + $set = $this->query->expenseInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->queryAmount); + $object->addToTotal($entry->amount); $object->addOrCreateExpense($entry); } @@ -353,9 +353,9 @@ class ReportHelper implements ReportHelperInterface public function getIncomeReport($start, $end, $shared) { $object = new Income; - $set = $this->query->incomeInPeriod($start, $end, $shared); + $set = $this->query->incomeInPeriodCorrected($start, $end, $shared); foreach ($set as $entry) { - $object->addToTotal($entry->queryAmount); + $object->addToTotal($entry->amount); $object->addOrCreateIncome($entry); } diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 26b056e449..851968d08f 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -113,7 +113,22 @@ class ReportQuery implements ReportQueryInterface $query->orderBy('transaction_journals.date'); // get everything - $data = $query->get(['transaction_journals.*',]); + $data = $query->get(['transaction_journals.*', 'transaction_types.type', 'ac_from.name as name', 'ac_from.encrypted as account_encrypted']); + + $data->each( + function (TransactionJournal $journal) { + if (intval($journal->account_encrypted) == 1) { + $journal->name = Crypt::decrypt($journal->name); + } + } + ); + $data = $data->filter( + function (TransactionJournal $journal) { + if ($journal->amount != 0) { + return $journal; + } + } + ); return $data; } @@ -270,7 +285,22 @@ class ReportQuery implements ReportQueryInterface $query->orderBy('transaction_journals.date'); // get everything - $data = $query->get(['transaction_journals.*',]); + $data = $query->get(['transaction_journals.*', 'transaction_types.type', 'ac_from.name as name', 'ac_from.encrypted as account_encrypted']); + + $data->each( + function (TransactionJournal $journal) { + if (intval($journal->account_encrypted) == 1) { + $journal->name = Crypt::decrypt($journal->name); + } + } + ); + $data = $data->filter( + function (TransactionJournal $journal) { + if ($journal->amount != 0) { + return $journal; + } + } + ); return $data; } @@ -314,16 +344,16 @@ class ReportQuery implements ReportQueryInterface { 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') - ->transactionTypes(['Withdrawal']) - ->where('transactions.account_id', $account->id) - ->before($end) - ->after($start) - ->where('budget_transaction_journal.budget_id', $budget->id) - ->get(['transaction_journals.*'])->sum('amount') - ) * -1; + 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') + ->transactionTypes(['Withdrawal']) + ->where('transactions.account_id', $account->id) + ->before($end) + ->after($start) + ->where('budget_transaction_journal.budget_id', $budget->id) + ->get(['transaction_journals.*'])->sum('amount') + ) * -1; } /** diff --git a/resources/twig/partials/reports/expenses.twig b/resources/twig/partials/reports/expenses.twig index c4e588e731..ad9176e878 100644 --- a/resources/twig/partials/reports/expenses.twig +++ b/resources/twig/partials/reports/expenses.twig @@ -16,7 +16,7 @@
{{ expense.count }} {{ 'transactions'|_|lower }} {% endif %} - {{ (expense.amount*-1)|formatAmountPlain }} + {{ (expense.amount)|formatAmountPlain }} {% endfor %} {% if expenses.getExpenses|length > expenseTopLength %} @@ -28,7 +28,7 @@ {% endif %} {{ 'sum'|_ }} - {{ (expenses.getTotal * -1)|formatAmountPlain }} + {{ (expenses.getTotal)|formatAmountPlain }} \ No newline at end of file