start; $dayBefore->subDay(); /** @var Account $account */ foreach ($this->accounts as $account) { // balance the day before: $id = $account->id; $auditData[$id] = $this->getAuditReport($account, $dayBefore); } $defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to']; $reportType = 'audit'; $accountIds = join(',', $this->accounts->pluck('id')->toArray()); $hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'interest_date', 'book_date', 'process_date', // three new optional fields. 'due_date', 'payment_date', 'invoice_date', 'from', 'to', 'budget', 'category', 'bill', // more new optional fields 'internal_reference', 'notes', 'create_date', 'update_date', ]; return view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow')) ->with('start', $this->start)->with('end', $this->end)->with('accounts', $this->accounts) ->render(); } /** * @param Collection $accounts * * @return ReportGeneratorInterface */ public function setAccounts(Collection $accounts): ReportGeneratorInterface { $this->accounts = $accounts; return $this; } /** * @param Collection $budgets * * @return ReportGeneratorInterface */ public function setBudgets(Collection $budgets): ReportGeneratorInterface { return $this; } /** * @param Collection $categories * * @return ReportGeneratorInterface */ public function setCategories(Collection $categories): ReportGeneratorInterface { return $this; } /** * @param Carbon $date * * @return ReportGeneratorInterface */ public function setEndDate(Carbon $date): ReportGeneratorInterface { $this->end = $date; return $this; } /** * @param Carbon $date * * @return ReportGeneratorInterface */ public function setStartDate(Carbon $date): ReportGeneratorInterface { $this->start = $date; return $this; } /** * @param Account $account * @param Carbon $date * * @return array */ private function getAuditReport(Account $account, Carbon $date): array { $dayBeforeBalance = Steam::balance($account, $date); $collector = new JournalCollector(auth()->user()); $collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end); $journals = $collector->getJournals(); $journals = $journals->reverse(); $startBalance = $dayBeforeBalance; /** @var Transaction $journal */ foreach ($journals as $transaction) { $transaction->before = $startBalance; $transactionAmount = $transaction->transaction_amount; $newBalance = bcadd($startBalance, $transactionAmount); $transaction->after = $newBalance; $startBalance = $newBalance; } /* * Reverse set again. */ $return = [ 'journals' => $journals->reverse(), 'exists' => $journals->count() > 0, 'end' => $this->end->formatLocalized(strval(trans('config.month_and_day'))), 'endBalance' => Steam::balance($account, $this->end), 'dayBefore' => $date->formatLocalized(strval(trans('config.month_and_day'))), 'dayBeforeBalance' => $dayBeforeBalance, ]; return $return; } }