/** * @param BillRepositoryInterface $repository * * @return \Illuminate\View\View */ public function index(BillRepositoryInterface $repository) { $bills = $repository->getBills(); $bills->each(function (Bill $bill) use($repository) { $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->lastFoundMatch = $repository->lastFoundMatch($bill); }); return view('bills.index', compact('bills')); }
/** * @param BillRepositoryInterface $repository * * @return View */ public function index(BillRepositoryInterface $repository) { /** @var Carbon $start */ $start = session('start'); /** @var Carbon $end */ $end = session('end'); $bills = $repository->getBills(); $bills->each(function (Bill $bill) use($repository, $start, $end) { $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->lastFoundMatch = $repository->lastFoundMatch($bill); $journals = $repository->getJournalsInRange($bill, $start, $end); // loop journals, find average: $average = '0'; $count = $journals->count(); if ($count > 0) { $sum = '0'; foreach ($journals as $journal) { $sum = bcadd($sum, TransactionJournal::amountPositive($journal)); } $average = bcdiv($sum, strval($count)); } $bill->lastPaidAmount = $average; $bill->paidInPeriod = $start <= $bill->lastFoundMatch && $end >= $bill->lastFoundMatch; }); return view('bills.index', compact('bills')); }