Optimise queries.

This commit is contained in:
James Cole
2015-12-26 09:39:35 +01:00
parent 209116e766
commit 8b0f0fb615
3 changed files with 58 additions and 11 deletions

View File

@@ -59,6 +59,7 @@ class JsonController extends Controller
$steps[7]['orphan'] = true; // final in the center again.
$steps[7]['backdrop'] = true;
$template = view('json.tour')->render();
return Response::json(['steps' => $steps, 'template' => $template]);
}
@@ -73,7 +74,6 @@ class JsonController extends Controller
{
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
$amount = 0;
bcscale(2);
// works for json too!
@@ -84,16 +84,10 @@ class JsonController extends Controller
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$bills = $repository->getActiveBills(); // these two functions are the same as the chart
/** @var Bill $bill */
foreach ($bills as $bill) {
$amount = bcadd($amount, $repository->billPaymentsInRange($bill, $start, $end));
}
unset($bill, $bills);
$amount = $amount * -1; // make the amount positive again.
// get amount from bills
$amount = $repository->billsPaidInRange($start, $end)->sum('paid');
// add credit card bill.
$creditCards = $accountRepository->getCreditCards(); // Find credit card accounts and possibly unpaid credit card bills.
/** @var Account $creditCard */
foreach ($creditCards as $creditCard) {