From 3299188edfa6620a0ae5ea692a40fed2cdd2c4ad Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 28 Nov 2014 14:41:58 +0100 Subject: [PATCH] New report --- app/controllers/ReportController.php | 63 ++++++++++++++++---------- app/views/reports/unbalanced.blade.php | 58 +++++++++--------------- 2 files changed, 60 insertions(+), 61 deletions(-) diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 98b9c4010c..2ec832c34a 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -157,7 +157,14 @@ class ReportController extends BaseController /** @var \FireflyIII\Database\TransactionJournal $journalRepository */ $journalRepository = App::make('FireflyIII\Database\TransactionJournal'); - $journals = $journalRepository->getInDateRange($start, $end); + /* + * Get all journals from this month: + */ + $journals = $journalRepository->getInDateRange($start, $end); + + /* + * Filter withdrawals: + */ $withdrawals = $journals->filter( function (TransactionJournal $journal) { if ($journal->transactionType->type == 'Withdrawal' && count($journal->budgets) == 0) { @@ -165,8 +172,19 @@ class ReportController extends BaseController } } ); - - // filter again for transfers + /* + * Filter deposits. + */ + $deposits = $journals->filter( + function (TransactionJournal $journal) { + if ($journal->transactionType->type == 'Withdrawal' && count($journal->budgets) == 0) { + return $journal; + } + } + ); + /* + * Filter transfers: + */ $transfers = $journals->filter( function (TransactionJournal $journal) { if ($journal->transactionType->type == 'Transfer') { @@ -175,54 +193,51 @@ class ReportController extends BaseController } ); - $withdrawals->each( + /* + * Filter withdrawals without a counter-transfer (into this account) + */ + $withdrawals = $withdrawals->filter( function (TransactionJournal $journal) { - $collection = new Collection; - /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { if (floatval($transaction->amount) < 0) { $account = $transaction->account; // find counter transfer: $counters = $account->transactions()->where('amount', floatval($transaction->amount) * -1) + ->where('account_id', '=', $transaction->account_id) ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%') - ->get(['transactions.*']); - /** @var Transaction $ct */ - foreach ($counters as $ct) { - $collection->push($ct->transactionjournal); + ->count(); + if($counters == 0) { + return $journal; } } } - $journal->counters = $collection; } ); - // same for transfers but the other way around! Yay! - $transfers->each( + /* + * Filter deposits without a counter-transfer (away from this account) + */ + $deposits = $deposits->filter( function (TransactionJournal $journal) { - $collection = new Collection; - /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { if (floatval($transaction->amount) < 0) { $account = $transaction->account; - // TODO this has to be the most lame way of filtering ever. - $descr = trim(str_replace('Geld voor','',$journal->description)); // find counter transfer: $counters = $account->transactions()->where('amount', floatval($transaction->amount)) + ->where('account_id', '=', $transaction->account_id) ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->where('transaction_journals.description', 'LIKE', '%' . $descr . '%') - ->get(['transactions.*']); - /** @var Transaction $ct */ - foreach ($counters as $ct) { - $collection->push($ct->transactionjournal); + ->where('transaction_journals.description', 'LIKE', '%' . e($journal->description) . '%') + ->count(); + if($counters == 0) { + return $journal; } } } - $journal->counters = $collection; } ); - return View::make('reports.unbalanced', compact('start','transfers', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals')); + return View::make('reports.unbalanced', compact('start', 'end', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon', 'withdrawals','deposits')); } /** diff --git a/app/views/reports/unbalanced.blade.php b/app/views/reports/unbalanced.blade.php index 3816c935ef..e310258967 100644 --- a/app/views/reports/unbalanced.blade.php +++ b/app/views/reports/unbalanced.blade.php @@ -1,74 +1,58 @@ @extends('layouts.default') @section('content') +@if(count($withdrawals) == 0 && count($deposits) == 0)
-

Transactions

+

Everything accounted for.

+
+
+@endif +@if(count($withdrawals) > 0) +
+
+

Withdrawals

@foreach($withdrawals as $journal)
-
+

Spent {{mf($journal->getAmount())}}

- @if($journal->counters->count() > 0) +

No counter transaction!

- - @foreach($journal->counters as $counter) - - - - - - - @endforeach -
{{$counter->description}}{{mf($counter->getAmount())}}
- @else -

No counter transaction!

-
- @endif
@endforeach
+@endif +@if(count($deposits) > 0)
-

Transfers

+

Deposits

-
- @foreach($transfers as $journal) + @foreach($deposits as $journal)
-
+
- {{{$journal->description}}} + {{{$journal->description}}}
- Bla bla? +

Received {{mf($journal->getAmount())}}

+

No counter transaction!

-
-
@endforeach
+@endif +