Cleaned up some code and added a small feature for transaction views.

This commit is contained in:
James Cole 2014-08-23 10:01:40 +02:00
parent a6b89879c5
commit d56c00915c
6 changed files with 119 additions and 72 deletions

View File

@ -1,6 +1,7 @@
<?php
use Carbon\Carbon;
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
/**
@ -149,9 +150,22 @@ class TransactionController extends BaseController
*/
public function index()
{
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
if ($start <= $end && !is_null($start) && !is_null($end)) {
$journals = $this->_repository->paginate(25, $start, $end);
$filtered = true;
$filters = ['start' => $start, 'end' => $end];
} else {
$journals = $this->_repository->paginate(25);
$filtered = false;
$filters = null;
}
return View::make('transactions.index')->with('journals', $journals);
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
'filters', $filters
);
}
/**

View File

@ -24,6 +24,7 @@ class Budget implements BudgetInterface
foreach ($budgets as $budget) {
foreach ($budget->limits as $limit) {
/** @var \LimitRepetition $rep */
foreach ($limit->limitrepetitions as $rep) {
$periodOrder = $rep->periodOrder();
$period = $rep->periodShow();
@ -31,6 +32,8 @@ class Budget implements BudgetInterface
? $return[$periodOrder]
: ['date' => $period,
'dateObject' => $rep->startdate,
'start' => $rep->startdate,
'end' => $rep->enddate,
'budget_id' => $limit->budget_id];
}
@ -92,6 +95,7 @@ class Budget implements BudgetInterface
/**
* @param \Budget $budget
* @param bool $useSessionDates
*
* @return array|mixed
* @throws \Firefly\Exception\FireflyException
*/
@ -105,8 +109,9 @@ class Budget implements BudgetInterface
// get the limits:
if ($useSessionDates) {
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->
where('startdate', '<=', $sessionEnd->format('Y-m-d'))->get();
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->where(
'startdate', '<=', $sessionEnd->format('Y-m-d')
)->get();
} else {
$limits = $budget->limits;
}

View File

@ -121,7 +121,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$fromTransaction->description = null;
$fromTransaction->amount = $amountFrom;
if (!$fromTransaction->validate()) {
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first());
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
));
}
$fromTransaction->save();
@ -230,7 +231,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
*
* @return mixed
*/
public function paginate($count = 25)
public function paginate($count = 25, Carbon $start = null, Carbon $end = null)
{
$query = \Auth::user()->transactionjournals()->with(
[
@ -244,10 +245,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
]
)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC')
->paginate($count);
->orderBy('transaction_journals.id', 'DESC');
if (!is_null($start)) {
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d'));
}
if (!is_null($end)) {
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
}
return $query;
$result = $query->paginate($count);
return $result;
}
/**
@ -328,12 +336,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
$connected = true;
$transaction->piggybank()->associate($piggyBank);
$transaction->save();
\Event::fire('piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]);
\Event::fire(
'piggybanks.createRelatedTransfer', [$piggyBank, $transactionJournal, $transaction]
);
break;
}
}
if ($connected === false) {
\Session::flash('warning', 'Piggy bank "' . e($piggyBank->name) . '" is not set to draw money from any of the accounts in this transfer');
\Session::flash(
'warning', 'Piggy bank "' . e($piggyBank->name)
. '" is not set to draw money from any of the accounts in this transfer'
);
}
}
}
@ -462,7 +475,10 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
}
}
if ($connected === false) {
\Session::flash('warning', 'Piggy bank "' . e($piggyBank->name) . '" is not set to draw money from any of the accounts in this transfer');
\Session::flash(
'warning', 'Piggy bank "' . e($piggyBank->name)
. '" is not set to draw money from any of the accounts in this transfer'
);
}
}
}

View File

@ -73,6 +73,6 @@ interface TransactionJournalRepositoryInterface
*
* @return mixed
*/
public function paginate($count = 25);
public function paginate($count = 25, Carbon $start = null, Carbon $end = null);
}

View File

@ -34,7 +34,7 @@
@foreach($budgets as $date => $entry)
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<h3><a href="#transactions-in-this-period">{{$entry['date']}}</a>
<h3><a href="{{route('transactions.index')}}?startdate={{$entry['start']->format('Y-m-d')}}&amp;enddate={{$entry['end']->format('Y-m-d')}}">{{$entry['date']}}</a>
<a class="btn btn-default btn-xs" href ="{{route('budgets.limits.create')}}?startdate={{$entry['dateObject']->format('Y-m-d')}}"><span class="glyphicon glyphicon-plus-sign"></span> Create a new envelope for {{$entry['date']}}</a>
</h3>
<table class="table table-bordered table-striped">

View File

@ -1,6 +1,18 @@
@extends('layouts.default')
@section('content')
@if($filtered === true)
<p class="bg-primary" style="padding:15px;">
This view is filtered to show only the transactions between
{{$filters['start']->format('M jS, Y')}} and {{$filters['end']->format('M jS, Y')}}.
</p>
<p class="bg-info" style="padding:15px;">
<a href="{{route('transactions.index')}}" class="text-info">Reset the filter.</a>
</p>
@endif
@include('paginated.transactions')