Fixed a bug where getAmountAttribute would interfere with queries that contained a "amount"-field.

This commit is contained in:
James Cole
2015-04-09 20:52:47 +02:00
parent 950c4045b0
commit 5124ce0302

View File

@@ -40,9 +40,9 @@ class JsonController extends Controller
->after($start) ->after($start)
->transactionTypes(['Deposit']) ->transactionTypes(['Deposit'])
->where('transactions.amount', '>', 0) ->where('transactions.amount', '>', 0)
->first([DB::Raw('SUM(transactions.amount) as `amount`')]); ->first([DB::Raw('SUM(transactions.amount) as `totalAmount`')]);
if (!is_null($in)) { if (!is_null($in)) {
$amount = floatval($in->amount); $amount = floatval($in->totalAmount);
} }
break; break;
@@ -50,13 +50,13 @@ class JsonController extends Controller
$box = Input::get('box'); $box = Input::get('box');
$in = Auth::user()->transactionjournals() $in = Auth::user()->transactionjournals()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->before($end) //->before($end)
->after($start) // ->after($start)
->transactionTypes(['Withdrawal']) ->transactionTypes(['Withdrawal'])
->where('transactions.amount', '>', 0) ->where('transactions.amount', '>', 0)
->first([DB::Raw('SUM(transactions.amount) as `amount`')]); ->first([DB::Raw('SUM(transactions.amount) as `totalAmount`')]);
if (!is_null($in)) { if (!is_null($in)) {
$amount = floatval($in->amount); $amount = floatval($in->totalAmount);
} }
break; break;
@@ -115,14 +115,8 @@ class JsonController extends Controller
// paid a bill in this range? // paid a bill in this range?
$count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count();
if ($count != 0) { if ($count != 0) {
$journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first();
$currentAmount = 0; $amount += $journal->amount;
foreach ($journal->transactions as $t) {
if (floatval($t->amount) > 0) {
$currentAmount = floatval($t->amount);
}
}
$amount += $currentAmount;
} }
} }