From 0a627f6f9e24df21346763835e540b5a59e9eef0 Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Wed, 12 Nov 2014 15:22:01 +0100 Subject: [PATCH] More work done for the transaction controller. --- app/controllers/GoogleTableController.php | 102 ++++++++++++++++++ app/controllers/TransactionController.php | 71 ++++++------ .../Database/TransactionJournal.php | 32 ++++++ app/routes.php | 1 + app/views/transactions/index.blade.php | 10 +- .../assets/javascript/firefly/transactions.js | 4 +- 6 files changed, 184 insertions(+), 36 deletions(-) diff --git a/app/controllers/GoogleTableController.php b/app/controllers/GoogleTableController.php index 555440e380..2480dd786c 100644 --- a/app/controllers/GoogleTableController.php +++ b/app/controllers/GoogleTableController.php @@ -216,6 +216,107 @@ class GoogleTableController extends BaseController return Response::json($chart->getData()); } + /** + * @param $what + * + * @return \Illuminate\Http\JsonResponse + */ + public function transactionsList($what) + { + /** @var \Grumpydictator\Gchart\GChart $chart */ + $chart = App::make('gchart'); + $chart->addColumn('ID', 'number'); + $chart->addColumn('ID_Edit', 'string'); + $chart->addColumn('ID_Delete', 'string'); + $chart->addColumn('Date', 'date'); + $chart->addColumn('Description_URL', 'string'); + $chart->addColumn('Description', 'string'); + $chart->addColumn('Amount', 'number'); + $chart->addColumn('From_URL', 'string'); + $chart->addColumn('From', 'string'); + $chart->addColumn('To_URL', 'string'); + $chart->addColumn('To', 'string'); + $chart->addColumn('Budget_URL', 'string'); + $chart->addColumn('Budget', 'string'); + $chart->addColumn('Category_URL', 'string'); + $chart->addColumn('Category', 'string'); + + /** @var \FireflyIII\Database\TransactionJournal $repository */ + $repository = App::make('FireflyIII\Database\TransactionJournal'); + + switch ($what) { + case 'expenses': + case 'withdrawal': + $list = $repository->getWithdrawals(); + break; + case 'revenue': + case 'deposit': + $list = $repository->getDeposits(); + break; + case 'transfer': + case 'transfers': + $list = $repository->getTransfers(); + break; + } + + /** @var Transaction $transaction */ + foreach ($list as $transaction) { + $date = $transaction->transactionJournal->date; + $descriptionURL = route('transactions.show', $transaction->transaction_journal_id); + $description = $transaction->transactionJournal->description; + $amount = floatval($transaction->amount); + + if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) { + $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id); + $opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name; + } else { + $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id); + $opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name; + } + if (isset($transaction->transactionJournal->budgets[0])) { + $budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id); + $budget = $transaction->transactionJournal->budgets[0]->name; + } else { + $budgetURL = ''; + $budget = ''; + } + + if (isset($transaction->transactionJournal->categories[0])) { + $categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id); + $category = $transaction->transactionJournal->categories[0]->name; + } else { + $categoryURL = ''; + $category = ''; + } + + + if ($amount < 0) { + $from = $account->name; + $fromURL = route('accounts.show', $account->id); + + $to = $opposingAccountName; + $toURL = $opposingAccountURI; + } else { + $to = $account->name; + $toURL = route('accounts.show', $account->id); + + $from = $opposingAccountName; + $fromURL = $opposingAccountURI; + } + + $id = $transaction->transactionJournal->id; + $edit = route('transactions.edit', $transaction->transactionJournal->id); + $delete = route('transactions.delete', $transaction->transactionJournal->id); + $chart->addRow( + $id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category + ); + } + + + $chart->generate(); + return Response::json($chart->getData()); + } + /** * @param Account $account */ @@ -239,6 +340,7 @@ class GoogleTableController extends BaseController $chart->addColumn('Category_URL', 'string'); $chart->addColumn('Category', 'string'); + /* * Find transactions: */ diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 26154381ed..58a205af53 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -12,6 +12,7 @@ use Illuminate\Support\MessageBag; class TransactionController extends BaseController { + /** * Construct a new transaction controller with two of the most often used helpers. * @@ -22,6 +23,36 @@ class TransactionController extends BaseController View::share('mainTitleIcon', 'fa-repeat'); } + /** + * @param $what + * + * @return $this + */ + public function index($what) + { + + switch ($what) { + case 'expenses': + case 'withdrawal': + $subTitleIcon = 'fa-long-arrow-left'; + $subTitle = 'Expenses'; + break; + case 'revenue': + case 'deposit': + $subTitleIcon = 'fa-long-arrow-right'; + $subTitle = 'Revenue, income and deposits'; + break; + case 'transfer': + case 'transfers': + $subTitleIcon = 'fa-arrows-h'; + $subTitle = 'Transfers'; + break; + } + + return View::make('transactions.index', compact('subTitle', 'subTitleIcon'))->with('what', $what); + + } + /** * Shows the view helping the user to create a new transaction journal. * @@ -46,7 +77,7 @@ class TransactionController extends BaseController /** @var \FireflyIII\Database\Piggybank $piggyRepository */ $piggyRepository = App::make('FireflyIII\Database\Piggybank'); - // get asset accounts with names and id's. + // get asset accounts with names and id's . $assetAccounts = $form->makeSelectList($accountRepository->getAssetAccounts()); // get budgets as a select list. @@ -222,33 +253,14 @@ class TransactionController extends BaseController ); } - /** - * @return $this - */ - public function expenses() - { - return View::make('transactions.list')->with('subTitle', 'Expenses')->with( - 'subTitleIcon', 'fa-long-arrow-left' - )->with('what', 'expenses'); - } - - /** - * @return $this - */ - public function revenue() - { - return View::make('transactions.list')->with('subTitle', 'Revenue')->with( - 'subTitleIcon', 'fa-long-arrow-right' - )->with('what', 'revenue'); - } - /** * @param TransactionJournal $journal * * @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 . '"' ); @@ -260,8 +272,7 @@ class TransactionController extends BaseController * @return $this|\Illuminate\Http\RedirectResponse * @throws FireflyException */ - public function store($what) - { + public function store($what) { throw new NotImplementedException; /* * Collect data to process: @@ -314,19 +325,13 @@ class TransactionController extends BaseController } } - public function index($what) - { - return View::make('transactions.index')->with('subTitle', 'Bla bla')->with('subTitleIcon', 'fa-arrows-h')->with('what', $what); - - } /** * @param TransactionJournal $journal * * @throws FireflyException */ - public function update(TransactionJournal $journal) - { + public function update(TransactionJournal $journal) { throw new NotImplementedException; switch (Input::get('post_submit_action')) { case 'update': @@ -370,4 +375,4 @@ class TransactionController extends BaseController } -} \ No newline at end of file +} \ No newline at end of file diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index 8f26645ade..57639de92f 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -327,6 +327,38 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $this->getUser()->transactionjournals()->get(); } + /** + * Some objects. + * + * @return Collection + */ + public function getTransfers() + { + return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Transfer'])->get(['transaction_journals.*']); + } + + /** + * Some objects. + * + * @return Collection + */ + public function getDeposits() + { + return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Deposit'])->get(['transaction_journals.*']); + } + + /** + * Some objects. + * + * @return Collection + */ + public function getWithdrawals() + { + return $this->getUser()->transactionjournals()->withRelevantData()->transactionTypes(['Withdrawal'])->get(['transaction_journals.*']); + } + + + /** * Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc. * diff --git a/app/routes.php b/app/routes.php index 983c2f318d..eb112edd04 100644 --- a/app/routes.php +++ b/app/routes.php @@ -164,6 +164,7 @@ Route::group( Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']); Route::get('/table/categories', ['uses' => 'GoogleTableController@categoryList']); Route::get('/table/recurring', ['uses' => 'GoogleTableController@recurringList']); + Route::get('/table/transactions/{what}', ['uses' => 'GoogleTableController@transactionsList'])->where(['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers']); // google table for components (categories + budgets) Route::get('/table/component/{component}/{limitrepetition}/transactions', ['uses' => 'GoogleTableController@transactionsByComponent']); diff --git a/app/views/transactions/index.blade.php b/app/views/transactions/index.blade.php index f96f23b171..d01b0bb15d 100644 --- a/app/views/transactions/index.blade.php +++ b/app/views/transactions/index.blade.php @@ -7,7 +7,7 @@ {{{$subTitle}}}
-
+
+ +{{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 diff --git a/public/assets/javascript/firefly/transactions.js b/public/assets/javascript/firefly/transactions.js index 39bb0507ec..7f65416544 100644 --- a/public/assets/javascript/firefly/transactions.js +++ b/public/assets/javascript/firefly/transactions.js @@ -15,5 +15,7 @@ if ($('input[name="category"]').length > 0) { } $(document).ready(function () { - + if(typeof googleTable != 'undefined') { + googleTable('table/transactions/' + what,'transaction-table'); + } }); \ No newline at end of file