/** * Get a full report on the users expenses during the period for a list of accounts. * * @param Carbon $start * @param Carbon $end * @param Collection $accounts * * @return Expense */ public function getExpenseReport($start, $end, Collection $accounts) { $object = new Expense(); $set = $this->query->expense($accounts, $start, $end); foreach ($set as $entry) { $object->addToTotal($entry->journalAmount); // can be positive, if it's a transfer $object->addOrCreateExpense($entry); } return $object; }
/** * @param ReportQueryInterface $reportQuery * * @param ARI $accountRepository * * @return \Symfony\Component\HttpFoundation\Response */ public function boxOut(ReportQueryInterface $reportQuery, ARI $accountRepository) { $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']); // works for json too! $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('box-out'); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $amount = $reportQuery->expense($accounts, $start, $end)->sum('journalAmount'); $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; $cache->store($data); return Response::json($data); }