From 5124ce03029e26d9f7390c56fa8e9507c9c7bc13 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 9 Apr 2015 20:52:47 +0200 Subject: [PATCH] Fixed a bug where getAmountAttribute would interfere with queries that contained a "amount"-field. --- app/Http/Controllers/JsonController.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index f620da02fd..e8229bfa84 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -40,9 +40,9 @@ class JsonController extends Controller ->after($start) ->transactionTypes(['Deposit']) ->where('transactions.amount', '>', 0) - ->first([DB::Raw('SUM(transactions.amount) as `amount`')]); + ->first([DB::Raw('SUM(transactions.amount) as `totalAmount`')]); if (!is_null($in)) { - $amount = floatval($in->amount); + $amount = floatval($in->totalAmount); } break; @@ -50,13 +50,13 @@ class JsonController extends Controller $box = Input::get('box'); $in = Auth::user()->transactionjournals() ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->before($end) - ->after($start) + //->before($end) + // ->after($start) ->transactionTypes(['Withdrawal']) ->where('transactions.amount', '>', 0) - ->first([DB::Raw('SUM(transactions.amount) as `amount`')]); + ->first([DB::Raw('SUM(transactions.amount) as `totalAmount`')]); if (!is_null($in)) { - $amount = floatval($in->amount); + $amount = floatval($in->totalAmount); } break; @@ -115,14 +115,8 @@ class JsonController extends Controller // paid a bill in this range? $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); if ($count != 0) { - $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); - $currentAmount = 0; - foreach ($journal->transactions as $t) { - if (floatval($t->amount) > 0) { - $currentAmount = floatval($t->amount); - } - } - $amount += $currentAmount; + $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); + $amount += $journal->amount; } }