/** * Get a full report on the users incomes during the period for the given accounts. * * @param Carbon $start * @param Carbon $end * @param Collection $accounts * * @return Income */ public function getIncomeReport($start, $end, Collection $accounts) { $object = new Income(); $set = $this->query->incomeInPeriod($start, $end, $accounts); foreach ($set as $entry) { $object->addToTotal($entry->amount_positive); $object->addOrCreateIncome($entry); } return $object; }
/** * @param ReportQueryInterface $reportQuery * * @param AccountRepositoryInterface $accountRepository * * @return \Symfony\Component\HttpFoundation\Response */ public function boxIn(ReportQueryInterface $reportQuery, AccountRepositoryInterface $accountRepository) { $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-in'); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']); $amount = $reportQuery->incomeInPeriod($start, $end, $accounts)->sum('to_amount'); $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; $cache->store($data); return Response::json($data); }
/** * Summarizes all income and expenses for a given year. Gives a total and an average. * * @param ReportQueryInterface $query * @param $report_type * @param Carbon $start * @param Carbon $end * @param Collection $accounts * * @return \Illuminate\Http\JsonResponse */ public function yearInOutSummarized(ReportQueryInterface $query, $report_type, Carbon $start, Carbon $end, Collection $accounts) { // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty('yearInOutSummarized'); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty($accounts); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $income = '0'; $expense = '0'; $count = 0; bcscale(2); if ($start->diffInMonths($end) > 12) { // per year while ($start < $end) { $startOfYear = clone $start; $startOfYear->startOfYear(); $endOfYear = clone $startOfYear; $endOfYear->endOfYear(); // total income and total expenses: $currentIncome = $query->incomeInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive'); $currentExpense = $query->expenseInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive'); $income = bcadd($income, $currentIncome); $expense = bcadd($expense, $currentExpense); $count++; $start->addYear(); } $data = $this->generator->multiYearInOutSummarized($income, $expense, $count); $cache->store($data); } else { // per month! while ($start < $end) { $month = clone $start; $month->endOfMonth(); // total income and total expenses: $currentIncome = $query->incomeInPeriod($start, $month, $accounts)->sum('amount_positive'); $currentExpense = $query->expenseInPeriod($start, $month, $accounts)->sum('amount_positive'); $income = bcadd($income, $currentIncome); $expense = bcadd($expense, $currentExpense); $count++; $start->addMonth(); } $data = $this->generator->yearInOutSummarized($income, $expense, $count); $cache->store($data); } return Response::json($data); }