Renamed various fields from 'amount' to 'queryAmount' to prevent interfering with the getAmountAttribute property.

This commit is contained in:
James Cole 2015-04-09 21:14:15 +02:00
parent 0224d1d59b
commit 37f40d8637
5 changed files with 42 additions and 40 deletions

View File

@ -60,15 +60,15 @@ class ReportHelper implements ReportHelperInterface
$join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d')); $join->on('budget_limits.budget_id', '=', 'budgets.id')->where('budget_limits.startdate', '=', $date->format('Y-m-d'));
} }
) )
->get(['budgets.*', 'budget_limits.amount as amount']); ->get(['budgets.*', 'budget_limits.amount as queryAmount']);
$budgets = Steam::makeArray($set); $budgets = Steam::makeArray($set);
$amountSet = $query->journalsByBudget($start, $end, $showSharedReports); $amountSet = $query->journalsByBudget($start, $end, $showSharedReports);
$amounts = Steam::makeArray($amountSet); $amounts = Steam::makeArray($amountSet);
$budgets = Steam::mergeArrays($budgets, $amounts); $budgets = Steam::mergeArrays($budgets, $amounts);
$budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0; $budgets[0]['spent'] = isset($budgets[0]['spent']) ? $budgets[0]['spent'] : 0.0;
$budgets[0]['amount'] = isset($budgets[0]['amount']) ? $budgets[0]['amount'] : 0.0; $budgets[0]['queryAmount'] = isset($budgets[0]['queryAmount']) ? $budgets[0]['queryAmount'] : 0.0;
$budgets[0]['name'] = 'No budget'; $budgets[0]['name'] = 'No budget';
// find transactions to shared asset accounts, which are without a budget by default: // find transactions to shared asset accounts, which are without a budget by default:
// which is only relevant when shared asset accounts are hidden. // which is only relevant when shared asset accounts are hidden.

View File

@ -96,7 +96,7 @@ class ReportQuery implements ReportQueryInterface
->get( ->get(
[ [
'transaction_journals.*', 'transaction_journals.*',
'transactions.amount' 'transactions.amount as queryAmount'
] ]
); );
@ -178,7 +178,7 @@ class ReportQuery implements ReportQueryInterface
{ {
$query = $this->queryJournalsNoBudget($account, $start, $end); $query = $this->queryJournalsNoBudget($account, $start, $end);
return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) as `amount`')]); return $query->get(['budgets.id', 'budgets.name', DB::Raw('SUM(`transactions`.`amount`) as `queryAmount`')]);
} }
@ -196,7 +196,7 @@ class ReportQuery implements ReportQueryInterface
{ {
$query = $this->queryJournalsNoBudget($account, $start, $end); $query = $this->queryJournalsNoBudget($account, $start, $end);
return $query->get(['budgets.name', 'transactions.amount', 'transaction_journals.*']); return $query->get(['budgets.name', 'transactions.amount as queryAmount', 'transaction_journals.*']);
} }
/** /**
@ -244,7 +244,7 @@ class ReportQuery implements ReportQueryInterface
'transaction_journals.description', 'transaction_journals.description',
'transaction_journals.encrypted', 'transaction_journals.encrypted',
'transaction_types.type', 'transaction_types.type',
DB::Raw('SUM(`t_to`.`amount`) as `amount`'), DB::Raw('SUM(`t_to`.`amount`) as `queryAmount`'),
'transaction_journals.date', 'transaction_journals.date',
't_from.account_id as account_id', 't_from.account_id as account_id',
'ac_from.name as name', 'ac_from.name as name',
@ -334,9 +334,9 @@ class ReportQuery implements ReportQueryInterface
->where('transaction_journals.date', '<=', $end->format('Y-m-d')) ->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->where('transaction_types.type', 'Withdrawal') ->where('transaction_types.type', 'Withdrawal')
->groupBy('categories.id') ->groupBy('categories.id')
->orderBy('amount'); ->orderBy('queryAmount');
$data = $query->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `amount`')]); $data = $query->get(['categories.id', 'categories.encrypted', 'categories.name', DB::Raw('SUM(`transactions`.`amount`) AS `queryAmount`')]);
// decrypt data: // decrypt data:
$data->each( $data->each(
function (Model $object) { function (Model $object) {
@ -389,9 +389,9 @@ class ReportQuery implements ReportQueryInterface
$query->before($end)->after($start) $query->before($end)->after($start)
->where('transaction_journals.user_id', Auth::user()->id) ->where('transaction_journals.user_id', Auth::user()->id)
->groupBy('t_to.account_id') ->groupBy('t_to.account_id')
->orderBy('amount', 'DESC'); ->orderBy('queryAmount', 'DESC');
$data = $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `amount`')]); $data = $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `queryAmount`')]);
// decrypt // decrypt
$data->each( $data->each(
@ -440,10 +440,10 @@ class ReportQuery implements ReportQueryInterface
$query->where('transaction_types.type', 'Deposit'); $query->where('transaction_types.type', 'Deposit');
} }
$query->groupBy('t_from.account_id')->orderBy('amount'); $query->groupBy('t_from.account_id')->orderBy('queryAmount');
$data = $query->get( $data = $query->get(
['t_from.account_id as account_id', 'ac_from.name as name', 'ac_from.encrypted as encrypted', DB::Raw('SUM(t_from.amount) as `amount`')] ['t_from.account_id as account_id', 'ac_from.name as name', 'ac_from.encrypted as encrypted', DB::Raw('SUM(t_from.amount) as `queryAmount`')]
); );
// decrypt // decrypt
$data->each( $data->each(
@ -488,7 +488,7 @@ class ReportQuery implements ReportQueryInterface
->where('transaction_journals.user_id', Auth::user()->id) ->where('transaction_journals.user_id', Auth::user()->id)
->get( ->get(
['transaction_journals.id', 'transaction_journals.description', 'transactions.account_id', 'accounts.name', ['transaction_journals.id', 'transaction_journals.description', 'transactions.account_id', 'accounts.name',
'transactions.amount'] 'transactions.amount as queryAmount']
); );
} }
@ -533,7 +533,7 @@ class ReportQuery implements ReportQueryInterface
[ [
'categories.id', 'categories.id',
'categories.name as name', 'categories.name as name',
DB::Raw('SUM(`transactions`.`amount`) * -1 AS `amount`') DB::Raw('SUM(`transactions`.`amount`) * -1 AS `queryAmount`')
] ]
); );
} }

View File

@ -81,7 +81,7 @@ class ReportController extends Controller
$id = intval($budget->id); $id = intval($budget->id);
$data = $budget->toArray(); $data = $budget->toArray();
$array[$id] = $data; $array[$id] = $data;
if (floatval($data['amount']) != 0) { if (floatval($data['queryAmount']) != 0) {
$hide = false; $hide = false;
} }
} }

View File

@ -103,14 +103,16 @@ class Steam
$id = intval($entry->id); $id = intval($entry->id);
if (isset($array[$id])) { if (isset($array[$id])) {
$array[$id]['amount'] += floatval($entry->amount); $array[$id]['amount'] += floatval($entry->amount);
$array[$id]['queryAmount'] += floatval($entry->queryAmount);
$array[$id]['spent'] += floatval($entry->spent); $array[$id]['spent'] += floatval($entry->spent);
$array[$id]['encrypted'] = intval($entry->encrypted); $array[$id]['encrypted'] = intval($entry->encrypted);
} else { } else {
$array[$id] = [ $array[$id] = [
'amount' => floatval($entry->amount), 'amount' => floatval($entry->amount),
'spent' => floatval($entry->spent), 'queryAmount' => floatval($entry->queryAmount),
'encrypted' => intval($entry->encrypted), 'spent' => floatval($entry->spent),
'name' => $entry->name 'encrypted' => intval($entry->encrypted),
'name' => $entry->name
]; ];
} }
} }
@ -131,7 +133,7 @@ class Steam
foreach ($two as $id => $value) { foreach ($two as $id => $value) {
// $otherId also exists in $one: // $otherId also exists in $one:
if (isset($one[$id])) { if (isset($one[$id])) {
$one[$id]['amount'] += $value['amount']; $one[$id]['queryAmount'] += $value['queryAmount'];
$one[$id]['spent'] += $value['spent']; $one[$id]['spent'] += $value['spent'];
} else { } else {
$one[$id] = $value; $one[$id] = $value;
@ -170,11 +172,11 @@ class Steam
{ {
uasort( uasort(
$array, function ($left, $right) { $array, function ($left, $right) {
if ($left['amount'] == $right['amount']) { if ($left['queryAmount'] == $right['queryAmount']) {
return 0; return 0;
} }
return ($left['amount'] < $right['amount']) ? 1 : -1; return ($left['queryAmount'] < $right['queryAmount']) ? 1 : -1;
} }
); );
@ -193,11 +195,11 @@ class Steam
{ {
uasort( uasort(
$array, function ($left, $right) { $array, function ($left, $right) {
if ($left['amount'] == $right['amount']) { if ($left['queryAmount'] == $right['queryAmount']) {
return 0; return 0;
} }
return ($left['amount'] < $right['amount']) ? -1 : 1; return ($left['queryAmount'] < $right['queryAmount']) ? -1 : 1;
} }
); );

View File

@ -75,7 +75,7 @@
@foreach($budgets as $id => $budget) @foreach($budgets as $id => $budget)
<tr> <tr>
<td>{{{$budget['name']}}}</td> <td>{{{$budget['name']}}}</td>
<td>{!! Amount::format($budget['amount']) !!}</td> <td>{!! Amount::format($budget['queryAmount']) !!}</td>
<?php $spent = 0;?> <?php $spent = 0;?>
@foreach($accounts as $account) @foreach($accounts as $account)
@if($account->hide === false) @if($account->hide === false)
@ -83,23 +83,23 @@
<td> <td>
@if($id == 0) @if($id == 0)
<a href="{{route('reports.no-budget',[$account, $year, $month])}}" class="openModal"> <a href="{{route('reports.no-budget',[$account, $year, $month])}}" class="openModal">
{!! Amount::format($account->budgetInformation[$id]['amount']) !!} {!! Amount::format($account->budgetInformation[$id]['queryAmount']) !!}
</a> </a>
@else @else
{!! Amount::format($account->budgetInformation[$id]['amount']) !!} {!! Amount::format($account->budgetInformation[$id]['queryAmount']) !!}
@endif @endif
</td> </td>
<?php <?php
$spent += floatval($account->budgetInformation[$id]['amount']); $spent += floatval($account->budgetInformation[$id]['queryAmount']);
$accountSums[$account->id] += floatval($account->budgetInformation[$id]['amount']); $accountSums[$account->id] += floatval($account->budgetInformation[$id]['queryAmount']);
?> ?>
@else @else
<td>{!! Amount::format(0) !!}</td> <td>{!! Amount::format(0) !!}</td>
@endif @endif
@endif @endif
@endforeach @endforeach
<td>{!! Amount::format($budget['amount'] + $budget['spent']) !!}</td> <td>{!! Amount::format($budget['queryAmount'] + $budget['spent']) !!}</td>
<td>{!! Amount::format($budget['amount'] + $spent) !!}</td> <td>{!! Amount::format($budget['queryAmount'] + $spent) !!}</td>
</tr> </tr>
@endforeach @endforeach
<tr> <tr>
@ -122,10 +122,10 @@
@if($account->hide === false) @if($account->hide === false)
@if(isset($account->budgetInformation[0])) @if(isset($account->budgetInformation[0]))
<td> <td>
@if($account->budgetInformation[0]['amount'] + $account->balancedAmount != 0.0) @if($account->budgetInformation[0]['queryAmount'] + $account->balancedAmount != 0.0)
<a href="{{route('reports.left-unbalanced',[$account, $year, $month])}}" class="openModal">{!! Amount::format($account->budgetInformation[0]['amount'] + $account->balancedAmount) !!}</a> <a href="{{route('reports.left-unbalanced',[$account, $year, $month])}}" class="openModal">{!! Amount::format($account->budgetInformation[0]['queryAmount'] + $account->balancedAmount) !!}</a>
@else @else
{!! Amount::format($account->budgetInformation[0]['amount'] + $account->balancedAmount) !!} {!! Amount::format($account->budgetInformation[0]['queryAmount'] + $account->balancedAmount) !!}
@endif @endif
</td> </td>
@else @else