From f9750a64f84ed39adf039256324a492621349446 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 14 Nov 2014 10:28:18 +0100 Subject: [PATCH] Fixed transactions lists. --- app/controllers/TransactionController.php | 13 +++- .../Database/TransactionJournal.php | 75 ++++++++----------- app/views/list/categories.blade.php | 2 +- app/views/transactions/index.blade.php | 14 +--- 4 files changed, 41 insertions(+), 63 deletions(-) diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index aa0aa0a5b5..5e8b103649 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -224,25 +224,31 @@ class TransactionController extends BaseController public function index($what) { + /** @var \FireflyIII\Database\TransactionJournal $repository */ + $repository = App::make('FireflyIII\Database\TransactionJournal'); + switch ($what) { case 'expenses': case 'withdrawal': $subTitleIcon = 'fa-long-arrow-left'; $subTitle = 'Expenses'; + $journals = $repository->getWithdrawalsPaginated(50); break; case 'revenue': case 'deposit': $subTitleIcon = 'fa-long-arrow-right'; $subTitle = 'Revenue, income and deposits'; + $journals = $repository->getDepositsPaginated(50); break; case 'transfer': case 'transfers': $subTitleIcon = 'fa-arrows-h'; $subTitle = 'Transfers'; + $journals = $repository->getTransfersPaginated(50); break; } - return View::make('transactions.index', compact('subTitle', 'subTitleIcon'))->with('what', $what); + return View::make('transactions.index', compact('subTitle', 'subTitleIcon','journals'))->with('what', $what); } @@ -251,9 +257,8 @@ class TransactionController extends BaseController * * @return $this */ - public function show( - TransactionJournal $journal - ) { + public function show(TransactionJournal $journal) + { return View::make('transactions.show')->with('journal', $journal)->with( 'subTitle', $journal->transactionType->type . ' "' . $journal->description . '"' ); diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index 07e13e7144..7837e62b4b 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -505,24 +505,6 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $sum; } - /** - * Some objects. - * - * @return Collection - */ - public function getDeposits($limit = null, $offset = null) - { - $query = $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Deposit']); - if(!is_null($limit)) { - $query->take($limit); - } - if(!is_null($offset) && intval($offset) > 0) { - $query->skip($offset); - } - - return $query->get(['transaction_journals.*']); - } - /** * @param \Account $account * @param int $count @@ -546,39 +528,42 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $query; } - /** - * Some objects. - * - * @return Collection - */ - public function getTransfers($limit = null, $offset = null) - { - $query = $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Transfer']); + public function getWithdrawalsPaginated($limit = 50) { + $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - if(!is_null($limit)) { - $query->take($limit); + $set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->count(); + $items = []; + foreach ($set as $entry) { + $items[] = $entry; } - if(!is_null($offset) && intval($offset) > 0) { - $query->skip($offset); - } - return $query->get(['transaction_journals.*']); + + return \Paginator::make($items, $count, $limit); } - /** - * Some objects. - * - * @return Collection - */ - public function getWithdrawals($limit = null, $offset = null) - { - $query = $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Withdrawal']); + public function getDepositsPaginated($limit = 50) { + $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; - if(!is_null($limit) && intval($limit) > 0) { - $query->take($limit); + $set = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->count(); + $items = []; + foreach ($set as $entry) { + $items[] = $entry; } - if(!is_null($offset) && intval($offset) > 0) { - $query->skip($offset); + + return \Paginator::make($items, $count, $limit); + } + + public function getTransfersPaginated($limit = 50) { + $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; + + $set = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']); + $count = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->count(); + $items = []; + foreach ($set as $entry) { + $items[] = $entry; } - return $query->get(['transaction_journals.*']); + + return \Paginator::make($items, $count, $limit); } } \ No newline at end of file diff --git a/app/views/list/categories.blade.php b/app/views/list/categories.blade.php index ea64100e01..6cfdb19eb2 100644 --- a/app/views/list/categories.blade.php +++ b/app/views/list/categories.blade.php @@ -13,7 +13,7 @@ - {{{$category->name}}} + {{{$category->name}}} lastActionDate(); ?> diff --git a/app/views/transactions/index.blade.php b/app/views/transactions/index.blade.php index 3410db02fe..46f76530df 100644 --- a/app/views/transactions/index.blade.php +++ b/app/views/transactions/index.blade.php @@ -7,7 +7,7 @@ {{{$subTitle}}}
-
+ @include('list.journals-full')
@@ -15,15 +15,3 @@ @stop -@section('scripts') - - - -{{HTML::script('assets/javascript/firefly/gcharts.options.js')}} -{{HTML::script('assets/javascript/firefly/gcharts.js')}} - - -{{HTML::script('assets/javascript/firefly/transactions.js')}} -@stop \ No newline at end of file