/**
  * @param BillRepositoryInterface $repository
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function boxBillsUnpaid(BillRepositoryInterface $repository)
 {
     $start = session('start', Carbon::now()->startOfMonth());
     $end = session('end', Carbon::now()->endOfMonth());
     $amount = $repository->getBillsUnpaidInRange($start, $end);
     // will be a positive amount.
     $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     return Response::json($data);
 }
Exemple #2
0
 /**
  * @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 the overview for a bill. The min/max amount and matched journals.
  *
  * @param BillRepositoryInterface $repository
  * @param Bill                    $bill
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function single(BillRepositoryInterface $repository, Bill $bill)
 {
     $cache = new CacheProperties();
     $cache->addProperty('single');
     $cache->addProperty('bill');
     $cache->addProperty($bill->id);
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     // get first transaction or today for start:
     $results = $repository->getJournals($bill, 1, 200);
     // resort:
     $results = $results->sortBy(function (TransactionJournal $journal) {
         return $journal->date->format('U');
     });
     $data = $this->generator->single($bill, $results);
     $cache->store($data);
     return Response::json($data);
 }
Exemple #4
0
 /**
  * @param BillRepositoryInterface    $repository
  * @param AccountRepositoryInterface $accountRepository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function boxBillsUnpaid(BillRepositoryInterface $repository, AccountRepositoryInterface $accountRepository)
 {
     $amount = 0;
     $start = Session::get('start', Carbon::now()->startOfMonth());
     $end = Session::get('end', Carbon::now()->endOfMonth());
     // works for json too!
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('box-bills-unpaid');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $bills = $repository->getActiveBills();
     $unpaid = new Collection();
     // bills
     /** @var Bill $bill */
     foreach ($bills as $bill) {
         $ranges = $repository->getRanges($bill, $start, $end);
         foreach ($ranges as $range) {
             $journals = $repository->getJournalsInRange($bill, $range['start'], $range['end']);
             if ($journals->count() == 0) {
                 $unpaid->push([$bill, $range['start']]);
             }
         }
     }
     unset($bill, $bills, $range, $ranges);
     $creditCards = $accountRepository->getCreditCards();
     foreach ($creditCards as $creditCard) {
         $balance = Steam::balance($creditCard, $end, true);
         $date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));
         if ($balance < 0) {
             // unpaid! create a fake bill that matches the amount.
             $description = $creditCard->name;
             $fakeAmount = $balance * -1;
             $fakeBill = $repository->createFakeBill($description, $date, $fakeAmount);
             $unpaid->push([$fakeBill, $date]);
         }
     }
     /** @var Bill $entry */
     foreach ($unpaid as $entry) {
         $current = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
         $amount += $current;
     }
     $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * @param BillFormRequest         $request
  * @param BillRepositoryInterface $repository
  * @param Bill                    $bill
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update(BillFormRequest $request, BillRepositoryInterface $repository, Bill $bill)
 {
     $billData = $request->getBillData();
     $bill = $repository->update($bill, $billData);
     Session::flash('success', 'Bill "' . e($bill->name) . '" updated.');
     Preferences::mark();
     if (intval(Input::get('return_to_edit')) === 1) {
         // set value so edit routine will not overwrite URL:
         Session::put('bills.edit.fromUpdate', true);
         return redirect(route('bills.edit', [$bill->id]))->withInput(['return_to_edit' => 1]);
     }
     // redirect to previous URL.
     return redirect(Session::get('bills.edit.url'));
 }
Exemple #6
0
 /**
  * Shows the overview for a bill. The min/max amount and matched journals.
  *
  * @param BillRepositoryInterface $repository
  * @param Bill                    $bill
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function single(BillRepositoryInterface $repository, Bill $bill)
 {
     $cache = new CacheProperties();
     $cache->addProperty('single');
     $cache->addProperty('bill');
     $cache->addProperty($bill->id);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     // get first transaction or today for start:
     $results = $repository->getJournals($bill);
     $data = $this->generator->single($bill, $results);
     $cache->store($data);
     return Response::json($data);
 }