From 49066c282a30ed840d9735062488055f8519f36a Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 23 Feb 2015 21:55:52 +0100 Subject: [PATCH] Updates --- app/Http/Controllers/PiggyBankController.php | 16 +++ .../Controllers/TransactionController.php | 69 +++++++++ app/Http/routes.php | 14 +- .../Account/AccountRepository.php | 12 +- app/Repositories/Budget/BudgetRepository.php | 7 +- resources/views/list/journals-full.blade.php | 8 +- resources/views/transactions/create.blade.php | 96 +++++++++++++ resources/views/transactions/delete.blade.php | 43 ++++++ resources/views/transactions/edit.blade.php | 96 +++++++++++++ resources/views/transactions/index.blade.php | 16 +++ resources/views/transactions/show.blade.php | 131 ++++++++++++++++++ 11 files changed, 482 insertions(+), 26 deletions(-) create mode 100644 app/Http/Controllers/PiggyBankController.php create mode 100644 app/Http/Controllers/TransactionController.php create mode 100644 resources/views/transactions/create.blade.php create mode 100644 resources/views/transactions/delete.blade.php create mode 100644 resources/views/transactions/edit.blade.php create mode 100644 resources/views/transactions/index.blade.php create mode 100644 resources/views/transactions/show.blade.php diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php new file mode 100644 index 0000000000..0a83fb239e --- /dev/null +++ b/app/Http/Controllers/PiggyBankController.php @@ -0,0 +1,16 @@ +_repository->getWithdrawalsPaginated(50); + $types = ['Withdrawal']; + break; + case 'revenue': + case 'deposit': + $subTitleIcon = 'fa-long-arrow-right'; + $subTitle = 'Revenue, income and deposits'; + // $journals = $this->_repository->getDepositsPaginated(50); + $types = ['Deposit']; + break; + case 'transfer': + case 'transfers': + $subTitleIcon = 'fa-arrows-h'; + $subTitle = 'Transfers'; + //$journals = $this->_repository->getTransfersPaginated(50); + $types = ['Transfer']; + break; + } + + $page = intval(\Input::get('page')); + $offset = $page > 0 ? ($page - 1) * 50 : 0; + + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)->orderBy('date', 'DESC')->get( + ['transaction_journals.*'] + ); + $count = Auth::user()->transactionJournals()->transactionTypes($types)->count(); + $journals = new LengthAwarePaginator($set, $count, 50, $page); + $journals->setPath('transactions/' . $what); + + return View::make('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals')); + + } + +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 955a9e6867..35290611d2 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -161,13 +161,13 @@ Route::group( * Piggy Bank Controller */ // piggy bank controller - Route::get('/piggy_banks', ['uses' => 'PiggyBankController@index', 'as' => 'piggy_banks.index']); - //Route::get('/piggy_banks/add/{piggyBank}', ['uses' => 'PiggyBankController@add']); # add money - //Route::get('/piggy_banks/remove/{piggyBank}', ['uses' => 'PiggyBankController@remove']); #remove money - //Route::get('/piggy_banks/create', ['uses' => 'PiggyBankController@create', 'as' => 'piggy_banks.create']); - //Route::get('/piggy_banks/edit/{piggyBank}', ['uses' => 'PiggyBankController@edit', 'as' => 'piggy_banks.edit']); - //Route::get('/piggy_banks/delete/{piggyBank}', ['uses' => 'PiggyBankController@delete', 'as' => 'piggy_banks.delete']); - //Route::get('/piggy_banks/show/{piggyBank}', ['uses' => 'PiggyBankController@show', 'as' => 'piggy_banks.show']); + Route::get('/piggy-banks', ['uses' => 'PiggyBankController@index', 'as' => 'piggy_banks.index']); + //Route::get('/piggy-banks/add/{piggyBank}', ['uses' => 'PiggyBankController@add']); # add money + //Route::get('/piggy-banks/remove/{piggyBank}', ['uses' => 'PiggyBankController@remove']); #remove money + //Route::get('/piggy-banks/create', ['uses' => 'PiggyBankController@create', 'as' => 'piggy_banks.create']); + //Route::get('/piggy-banks/edit/{piggyBank}', ['uses' => 'PiggyBankController@edit', 'as' => 'piggy_banks.edit']); + //Route::get('/piggy-banks/delete/{piggyBank}', ['uses' => 'PiggyBankController@delete', 'as' => 'piggy_banks.delete']); + //Route::get('/piggy-banks/show/{piggyBank}', ['uses' => 'PiggyBankController@show', 'as' => 'piggy_banks.show']); /** * Preferences Controller diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 309b41a694..d62e6c36dd 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -46,7 +46,6 @@ class AccountRepository implements AccountRepositoryInterface public function getJournals(Account $account, $page, $range = 'session') { $offset = $page * 50; - $items = []; $query = Auth::user() ->transactionJournals() ->withRelevantData() @@ -58,14 +57,9 @@ class AccountRepository implements AccountRepositoryInterface $query->before(Session::get('end', Carbon::now()->startOfMonth())); $query->after(Session::get('start', Carbon::now()->startOfMonth())); } - $count = $query->count(); - $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']); - - foreach ($set as $entry) { - $items[] = $entry; - } - - $paginator = new LengthAwarePaginator($items, $count, 50, $page); + $count = $query->count(); + $set = $query->take(50)->offset($offset)->get(['transaction_journals.*']); + $paginator = new LengthAwarePaginator($set, $count, 50, $page); return $paginator; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 8723e9675e..ba09cdb9e5 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -54,12 +54,7 @@ class BudgetRepository implements BudgetRepositoryInterface $set = $setQuery->get(['transaction_journals.*']); $count = $countQuery->count(); - $items = []; - foreach ($set as $entry) { - $items[] = $entry; - } - - return new LengthAwarePaginator($items, $count, $take, $offset); + return new LengthAwarePaginator($set, $count, $take, $offset); } /** diff --git a/resources/views/list/journals-full.blade.php b/resources/views/list/journals-full.blade.php index b9c4908852..804690c354 100644 --- a/resources/views/list/journals-full.blade.php +++ b/resources/views/list/journals-full.blade.php @@ -1,5 +1,5 @@ -@if(is_object($journals) && method_exists($journals, 'links')) -{{$journals->links()}} +@if(is_object($journals) && method_exists($journals, 'render')) +{!! $journals->render() !!} @endif @@ -115,6 +115,6 @@ @endforeach
-@if(is_object($journals) && method_exists($journals, 'links')) -{{$journals->links()}} +@if(is_object($journals) && method_exists($journals, 'render')) +{!! $journals->render() !!} @endif diff --git a/resources/views/transactions/create.blade.php b/resources/views/transactions/create.blade.php new file mode 100644 index 0000000000..5585ddb4c6 --- /dev/null +++ b/resources/views/transactions/create.blade.php @@ -0,0 +1,96 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) }} +{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('transactions.store',$what)])}} +{{Form::hidden('reminder',Input::get('reminder_id'))}} + +
+
+ +
+
+ Mandatory fields +
+
+ + {{Form::ffText('description')}} + @if($what == 'deposit' || $what == 'withdrawal') + {{Form::ffSelect('account_id',$accounts)}} + @endif + + + + @if($what == 'withdrawal') + {{Form::ffText('expense_account')}} + @endif + + + @if($what == 'deposit') + {{Form::ffText('revenue_account')}} + @endif + + + + @if($what == 'transfer') + {{Form::ffSelect('account_from_id',$accounts)}} + {{Form::ffSelect('account_to_id',$accounts)}} + @endif + + + + {{Form::ffAmount('amount')}} + + + {{Form::ffDate('date', date('Y-m-d'))}} +
+
+

+ +

+ +
+
+ +
+
+ Optional fields +
+
+ + @if($what == 'withdrawal') + {{Form::ffSelect('budget_id',$budgets,0)}} + @endif + + {{Form::ffText('category')}} + + + + + + @if($what == 'transfer' && count($piggies) > 0) + {{Form::ffSelect('piggy_bank_id',$piggies)}} + @endif +
+
+ +
+
+ Options +
+
+ {{Form::ffOptionsList('create','transaction')}} +
+
+
+
+ + +{{Form::close()}} + +@stop +@section('scripts') +{{HTML::script('assets/javascript/typeahead/bootstrap3-typeahead.min.js')}} +{{HTML::script('assets/javascript/firefly/transactions.js')}} +@stop diff --git a/resources/views/transactions/delete.blade.php b/resources/views/transactions/delete.blade.php new file mode 100644 index 0000000000..aef2335fc8 --- /dev/null +++ b/resources/views/transactions/delete.blade.php @@ -0,0 +1,43 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }} +{{Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('transactions.destroy',$journal->id)])}} + +
+
+ +
+
+ Destroy "{{{$journal->description}}}" +
+
+

+ Deleting stuff from Firefly is permanent. This action will remove the transaction and all + associated data. +

+

+ This action will not destroy categories, piggy banks, accounts, etc. +

+

+ Are you sure? +

+
+ + @if($journal->transactiontype->type == 'Withdrawal') + Cancel + @endif + @if($journal->transactiontype->type == 'Deposit') + Cancel + @endif + @if($journal->transactiontype->type == 'Transfer') + Cancel + @endif +
+
+
+
+
+ +{{Form::close()}} + +@stop diff --git a/resources/views/transactions/edit.blade.php b/resources/views/transactions/edit.blade.php new file mode 100644 index 0000000000..0996995257 --- /dev/null +++ b/resources/views/transactions/edit.blade.php @@ -0,0 +1,96 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }} +{{Form::open(['class' => 'form-horizontal','id' => 'update','url' => route('transactions.update',$journal->id)])}} + + +
+
+ +
+
+ Mandatory fields +
+
+ + {{Form::ffText('description',$journal->description)}} + + + @if($what == 'deposit' || $what == 'withdrawal') + {{Form::ffSelect('account_id',$accounts,$data['account_id'])}} + @endif + + + @if($what == 'withdrawal') + {{Form::ffText('expense_account',$data['expense_account'])}} + @endif + + @if($what == 'deposit') + {{Form::ffText('revenue_account',$data['revenue_account'])}} + @endif + + + @if($what == 'transfer') + {{Form::ffSelect('account_from_id',$accounts,$data['account_from_id'])}} + {{Form::ffSelect('account_to_id',$accounts,$data['account_to_id'])}} + @endif + + + {{Form::ffAmount('amount',$data['amount'],['currency' => $journal->transactionCurrency])}} + + + {{Form::ffDate('date',$data['date'])}} +
+
+ +

+ +

+ +
+
+ +
+
+ Optional fields +
+
+ + @if($what == 'withdrawal') + {{Form::ffSelect('budget_id',$budgets,$data['budget_id'])}} + @endif + + {{Form::ffText('category',$data['category'])}} + + + + + @if($what == 'transfer' && count($piggies) > 0) + {{Form::ffSelect('piggy_bank_id',$piggies,$data['piggy_bank_id'])}} + @endif +
+
+ + +
+
+ Options +
+
+ {{Form::ffOptionsList('update','transaction')}} +
+
+
+
+ + +{{Form::close()}} + + +@stop +@section('scripts') +{{HTML::script('assets/javascript/typeahead/bootstrap3-typeahead.min.js')}} +{{HTML::script('assets/javascript/firefly/transactions.js')}} +@stop diff --git a/resources/views/transactions/index.blade.php b/resources/views/transactions/index.blade.php new file mode 100644 index 0000000000..5bce81cde6 --- /dev/null +++ b/resources/views/transactions/index.blade.php @@ -0,0 +1,16 @@ +@extends('layouts.default') +@section('content') +{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $what) !!} +
+
+
+
+ {{{$subTitle}}} +
+ @include('list.journals-full') +
+
+
+ + +@stop diff --git a/resources/views/transactions/show.blade.php b/resources/views/transactions/show.blade.php new file mode 100644 index 0000000000..2bdc086cf1 --- /dev/null +++ b/resources/views/transactions/show.blade.php @@ -0,0 +1,131 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $journal) }} +
+
+
+
+ Metadata +
+
+ + + + + + + + + + + + + + + + + + @foreach($journal->budgets()->get() as $budget) + + + + + @endforeach + @foreach($journal->categories()->get() as $category) + + + + + @endforeach + +
Date{{{$journal->date->format('jS F Y')}}}
Currency{{{$journal->transactioncurrency->code}}}
Type{{{$journal->transactiontype->type}}}
Completed + @if($journal->completed == 1) + Yes + @else + No + @endif +
{{$budget->class}}{{{$budget->name}}}
{{$category->class}}{{{$category->name}}}
+
+
+ + @if(count($journal->piggyBankEvents) > 0) +
+
+ Piggy banks +
+
+ @include('list.piggy-bank-events',['events' => $journal->piggyBankEvents,'showPiggyBank' => true]) +
+
+ @endif +
+
+ Related transactions +
+ @if($members->count() == 0) +
+

+ No related transactions +

+
+ @else + + @foreach($members as $jrnl) + + + + + + @endforeach +
{{{$jrnl->description}}}{{Amount::formatJournal($jrnl, $jrnl->getAmount())}}
+ @endif + +
+
+
+ + @foreach($journal->transactions as $t) +
+
+ {{{$t->account->name}}}
{{{$t->account->accounttype->description}}} +
+
+ + + + + + + + + + @if(!is_null($t->description)) + + + + + @endif +
Amount{{Amount::formatTransaction($t)}}
New balance{{Amount::format($t->before)}} → {{Amount::format($t->after)}}
Description{{{$t->description}}}
+
+
+ @endforeach +
+
+ +
+
+ +
+
+ +@stop +@section('scripts') +{{HTML::script('assets/javascript/firefly/transactions.js')}} +{{HTML::script('assets/javascript/firefly/related-manager.js')}} +@stop