New stuff for transaction edits [skip ci]

This commit is contained in:
James Cole 2014-07-25 07:17:56 +02:00
parent a40b281ea3
commit 03994dd774
6 changed files with 93 additions and 7 deletions

View File

@ -111,6 +111,11 @@ class TransactionController extends BaseController
}
public function index() {
$transactions = $this->_journal->paginate(25);
return View::make('transactions.index')->with('transactions',$transactions);
}
public function show($journalId)
{
$journal = $this->_journal->find($journalId);

View File

@ -4,8 +4,6 @@
namespace Firefly\Storage\TransactionJournal;
use Firefly\Exception\FireflyException;
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
{
@ -167,7 +165,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
}
public function getByAccountInDateRange(\Account $account, $count = 25,\Carbon\Carbon $start, \Carbon\Carbon $end)
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end)
{
$accountID = $account->id;
$query = \Auth::user()->transactionjournals()->with(
@ -180,8 +178,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->where('accounts.id', $accountID)
->where('date','>=',$start->format('Y-m-d'))
->where('date','<=',$end->format('Y-m-d'))
->where('date', '>=', $start->format('Y-m-d'))
->where('date', '<=', $end->format('Y-m-d'))
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC')
->take($count)
@ -189,6 +187,26 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
return $query;
}
public function paginate($count = 25)
{
$query = \Auth::user()->transactionjournals()->with(
[
'transactions' => function ($q) {
return $q->orderBy('amount', 'ASC');
},
'transactions.account',
'transactions.account.accounttype',
'transactioncurrency',
'transactiontype'
]
)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC')
->take($count)
->paginate($count);
return $query;
}
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end)
{
// lets make this simple.

View File

@ -11,10 +11,12 @@ interface TransactionJournalRepositoryInterface
public function find($journalId);
public function getByAccountInDateRange(\Account $account, $count = 25,\Carbon\Carbon $start, \Carbon\Carbon $end);
public function getByAccountInDateRange(\Account $account, $count = 25, \Carbon\Carbon $start, \Carbon\Carbon $end);
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date);
public function getByDateRange(\Carbon\Carbon $start, \Carbon\Carbon $end);
public function paginate($count = 25);
}

View File

@ -48,6 +48,7 @@ Route::group(['before' => 'auth'], function () {
Route::get('/transaction/show/{id}',['uses' => 'TransactionController@show','as' => 'transactions.show']);
Route::get('/transaction/edit/{id}',['uses' => 'TransactionController@edit','as' => 'transactions.edit']);
Route::get('/transaction/delete/{id}',['uses' => 'TransactionController@delete','as' => 'transactions.delete']);
Route::get('/transactions/index',['uses' => 'TransactionController@index','as' => 'transactions.index']);
// migration controller
Route::get('/migrate', ['uses' => 'MigrationController@index', 'as' => 'migrate']);

View File

@ -23,7 +23,7 @@ $r = Route::current()->getName();
<ul class="dropdown-menu" role="menu">
<li><a href="{{route('accounts.index')}}"><span class="glyphicon glyphicon-inbox"></span> Accounts</a></li>
<li><a href="{{route('budgets.index')}}"><span class="glyphicon glyphicon-euro"></span> Budgets</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="{{route('transactions.index')}}"><span class="glyphicon glyphicon-list-alt"></span> Transactions</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>

View File

@ -0,0 +1,60 @@
@extends('layouts.default')
@section('content')
<table class="table">
<tr>
<th></th>
</tr>
@foreach($transactions as $journal)
<tr>
<td>
@if($journal->transactiontype->type == 'Withdrawal')
<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>
@endif
@if($journal->transactiontype->type == 'Deposit')
<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>
@endif
@if($journal->transactiontype->type == 'Transfer')
<span class="glyphicon glyphicon-resize-full" title="Transfer"></span>
@endif
@if($journal->transactiontype->type == 'Opening balance')
<span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>
@endif
</td>
<td>
bud / cat
</td>
<td><a href="#" title="{{{$journal->description}}}">{{{$journal->description}}}</a></td>
<td>
@if($journal->transactiontype->type == 'Withdrawal')
<span class="text-danger">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
@if($journal->transactiontype->type == 'Deposit')
<span class="text-success">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
@if($journal->transactiontype->type == 'Transfer')
<span class="text-info">{{mf($journal->transactions[1]->amount,false)}}</span>
@endif
</td>
<td>
@if($journal->transactions[0]->account->accounttype->description == 'Cash account')
<span class="text-success">(cash)</span>
@else
<a href="#">{{{$journal->transactions[0]->account->name}}}</a>
@endif
</td>
<td>
@if($journal->transactions[1]->account->accounttype->description == 'Cash account')
<span class="text-success">(cash)</span>
@else
<a href="#">{{{$journal->transactions[1]->account->name}}}</a>
@endif
</td>
<td>Edit / delete</td>
</tr>
@endforeach
</table>
{{$transactions->links()}}
@stop