Esempio n. 1
0
 /**
  * Summarizes all income and expenses for a given year. Gives a total and an average.
  *
  * @param ReportQueryInterface $query
  * @param                      $reportType
  * @param Carbon               $start
  * @param Carbon               $end
  * @param Collection           $accounts
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function yearInOutSummarized(ReportQueryInterface $query, $reportType, Carbon $start, Carbon $end, Collection $accounts)
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('yearInOutSummarized');
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty($reportType);
     $cache->addProperty($accounts);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     // spent per month, and earned per month. For a specific set of accounts
     // grouped by month
     $spentArray = $query->spentPerMonth($accounts, $start, $end);
     $earnedArray = $query->earnedPerMonth($accounts, $start, $end);
     if ($start->diffInMonths($end) > 12) {
         // per year
         $data = $this->multiYearInOutSummarized($earnedArray, $spentArray, $start, $end);
     } else {
         // per month!
         $data = $this->singleYearInOutSummarized($earnedArray, $spentArray, $start, $end);
     }
     $cache->store($data);
     return Response::json($data);
 }