Clean up sql codes.

This commit is contained in:
James Cole 2015-03-20 22:39:07 +01:00
parent 5dc0677599
commit c259a46ed3
4 changed files with 45 additions and 17 deletions

View File

@ -45,7 +45,7 @@ class Reminders
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if ($this->auth->check() && !$request->isJson()) { if ($this->auth->check() && !$request->isXmlHttpRequest()) {
// do reminders stuff. // do reminders stuff.
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
$today = new Carbon; $today = new Carbon;
@ -85,7 +85,6 @@ class Reminders
View::share('reminders', $reminders); View::share('reminders', $reminders);
} }
return $next($request); return $next($request);
} }
} }

View File

@ -64,6 +64,10 @@ class AccountRepository implements AccountRepositoryInterface
} }
/** /**
* This method is used on the front page where (in turn) its viewed journals-tiny.php which (in turn)
* is almost the only place where formatJournal is used. Aka, we can use some custom querying to get some specific.
* fields using left joins.
*
* @param Account $account * @param Account $account
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
@ -74,15 +78,17 @@ class AccountRepository implements AccountRepositoryInterface
{ {
return Auth::user() return Auth::user()
->transactionjournals() ->transactionjournals()
->with(['transactions', 'transactioncurrency', 'transactiontype']) ->with(['transactions'])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id) ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id')
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->before($end) ->before($end)
->after($start) ->after($start)
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC') ->orderBy('transaction_journals.id', 'DESC')
->take(10) ->take(10)
->get(['transaction_journals.*']); ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
} }
/** /**

View File

@ -90,12 +90,23 @@ class Amount
public function formatJournal(TransactionJournal $journal, $coloured = true) public function formatJournal(TransactionJournal $journal, $coloured = true)
{ {
$showPositive = true; $showPositive = true;
$symbol = $journal->transactionCurrency->symbol; if (is_null($journal->symbol)) {
$amount = 0; $symbol = $journal->transactionCurrency->symbol;
switch ($journal->transactionType->type) { } else {
case 'Withdrawal': $symbol = $journal->symbol;
$showPositive = false;
} }
$amount = 0;
if (is_null($journal->type)) {
$type = $journal->transactionType->type;
} else {
$type = $journal->type;
}
if ($type == 'Withdrawal') {
$showPositive = false;
}
foreach ($journal->transactions as $t) { foreach ($journal->transactions as $t) {
if (floatval($t->amount) > 0 && $showPositive === true) { if (floatval($t->amount) > 0 && $showPositive === true) {
$amount = floatval($t->amount); $amount = floatval($t->amount);

View File

@ -2,14 +2,26 @@
@foreach($transactions as $journal) @foreach($transactions as $journal)
<a class="list-group-item" title="{{$journal->date->format('jS M Y')}}" href="{{route('transactions.show',$journal->id)}}"> <a class="list-group-item" title="{{$journal->date->format('jS M Y')}}" href="{{route('transactions.show',$journal->id)}}">
@if($journal->transactiontype->type == 'Withdrawal') @if(is_null($journal->type))
<i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i> @if($journal->transactiontype->type == 'Withdrawal')
@endif <i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i>
@if($journal->transactiontype->type == 'Deposit') @endif
<i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i> @if($journal->transactiontype->type == 'Deposit')
@endif <i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i>
@if($journal->transactiontype->type == 'Transfer') @endif
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i> @if($journal->transactiontype->type == 'Transfer')
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i>
@endif
@else
@if($journal->type == 'Withdrawal')
<i class="fa fa-long-arrow-left fa-fw" title="Withdrawal"></i>
@endif
@if($journal->type == 'Deposit')
<i class="fa fa-long-arrow-right fa-fw" title="Deposit"></i>
@endif
@if($journal->type == 'Transfer')
<i class="fa fa-arrows-h fa-fw" title="Transfer"></i>
@endif
@endif @endif
{{{$journal->description}}} {{{$journal->description}}}