示例#1
0
 /**
  * Summarizes all income and expenses, per month, for a given year.
  *
  * @param ReportQueryInterface $query
  * @param                      $year
  * @param bool                 $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function yearInOut(ReportQueryInterface $query, $year, $shared = false)
 {
     // get start and end of year
     $start = new Carbon($year . '-01-01');
     $end = new Carbon($year . '-12-31');
     $shared = $shared == 'shared' ? true : false;
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('yearInOut');
     $cache->addProperty($year);
     $cache->addProperty($shared);
     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->incomeInPeriodCorrected($start, $month, $shared)->sum('amount_positive');
         $expenseSum = $query->expenseInPeriodCorrected($start, $month, $shared)->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, 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
     }
     // per year?
     if ($start->diffInMonths($end) > 12) {
         $entries = new Collection();
         while ($start < $end) {
             $startOfYear = clone $start;
             $startOfYear->startOfYear();
             $endOfYear = clone $startOfYear;
             $endOfYear->endOfYear();
             // total income and total expenses:
             $incomeSum = $query->incomeInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
             $expenseSum = $query->expenseInPeriod($startOfYear, $endOfYear, $accounts)->sum('amount_positive');
             $entries->push([clone $start, $incomeSum, $expenseSum]);
             $start->addYear();
         }
         $data = $this->generator->multiYearInOut($entries);
         $cache->store($data);
     } else {
         // per month:
         $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);
 }
 /**
  * @param array  $earned
  * @param array  $spent
  * @param Carbon $start
  * @param Carbon $end
  *
  * @return array
  */
 protected function singleYearInOut(array $earned, array $spent, Carbon $start, Carbon $end)
 {
     // per month? simply use each month.
     $entries = new Collection();
     while ($start < $end) {
         // total income and total expenses:
         $date = $start->format('Y-m');
         $incomeSum = isset($earned[$date]) ? $earned[$date] : 0;
         $expenseSum = isset($spent[$date]) ? $spent[$date] * -1 : 0;
         $entries->push([clone $start, $incomeSum, $expenseSum]);
         $start->addMonth();
     }
     $data = $this->generator->yearInOut($entries);
     return $data;
 }