/** * @param BillRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse */ public function boxBillsUnpaid(BillRepositoryInterface $repository) { bcscale(2); $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $amount = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount. $creditCardDue = $repository->getCreditCardBill($start, $end); if ($creditCardDue < 0) { // expenses are negative (bill not yet paid), $creditCardDue = bcmul($creditCardDue, '-1'); $amount = bcadd($amount, $creditCardDue); } $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; return Response::json($data); }
/** * Shows all bills and whether or not they've been paid this month (pie chart). * * @param BillRepositoryInterface $repository * * @return \Symfony\Component\HttpFoundation\Response */ public function frontpage(BillRepositoryInterface $repository) { $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount. $unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount. $creditCardDue = $repository->getCreditCardBill($start, $end); if ($creditCardDue < 0) { // expenses are negative (bill not yet paid), $creditCardDue = bcmul($creditCardDue, '-1'); $unpaid = bcadd($unpaid, $creditCardDue); } else { // if more than zero, the bill has been paid: (transfer = positive). // amount must be negative to be added to $paid: $paid = bcadd($paid, $creditCardDue); } // build chart: $data = $this->generator->frontpage($paid, $unpaid); return Response::json($data); }