generator = app('FireflyIII\Generator\Chart\Report\ReportChartGenerator'); } /** * Summarizes all income and expenses, per month, for a given year. * * @param ReportQueryInterface $query * @param $report_type * @param Carbon $start * @param Carbon $end * @param Collection $accounts * * @return \Illuminate\Http\JsonResponse */ public function yearInOut(ReportQueryInterface $query, $report_type, Carbon $start, Carbon $end, Collection $accounts) { // chart properties for cache: $cache = new CacheProperties; $cache->addProperty('yearInOut'); $cache->addProperty($start); $cache->addProperty($accounts); $cache->addProperty($end); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $entries = new Collection; while ($start < $end) { $month = clone $start; $month->endOfMonth(); // total income and total expenses: $incomeSum = $query->incomeInPeriod($start, $month, $accounts)->sum('amount_positive'); $expenseSum = $query->expenseInPeriod($start, $month, $accounts)->sum('amount_positive'); $entries->push([clone $start, $incomeSum, $expenseSum]); $start->addMonth(); } $data = $this->generator->yearInOut($entries); $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); 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); } }