/**
  * 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('start', Carbon::now()->startOfMonth());
     $end = session('end', Carbon::now()->endOfMonth());
     $paid = $repository->getBillsPaidInRange($start, $end);
     // will be a negative amount.
     $unpaid = $repository->getBillsUnpaidInRange($start, $end);
     // will be a positive amount.
     $data = $this->generator->frontpage($paid, $unpaid);
     return Response::json($data);
 }
 /**
  * @param BillRepositoryInterface $repository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function boxBillsPaid(BillRepositoryInterface $repository)
 {
     $start = session('start', Carbon::now()->startOfMonth());
     $end = session('end', Carbon::now()->endOfMonth());
     /*
      * Since both this method and the chart use the exact same data, we can suffice
      * with calling the one method in the bill repository that will get this amount.
      */
     $amount = $repository->getBillsPaidInRange($start, $end);
     // will be a negative amount.
     $amount = bcmul($amount, '-1');
     $data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     return Response::json($data);
 }
Esempio n. 3
0
 /**
  * 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);
 }