Пример #1
0
 /**
  * Get a full report on the users expenses during the period.
  *
  * @param Carbon  $start
  * @param Carbon  $end
  * @param boolean $shared
  *
  * @return Expense
  */
 public function getExpenseReport($start, $end, $shared)
 {
     $object = new Expense();
     $set = $this->query->expenseInPeriodCorrected($start, $end, $shared);
     foreach ($set as $entry) {
         $object->addToTotal($entry->amount);
         $object->addOrCreateExpense($entry);
     }
     return $object;
 }
Пример #2
0
 /**
  * Summarizes all income and expenses for a given year. Gives a total and an average.
  *
  * @param ReportQueryInterface $query
  * @param                      $year
  * @param bool                 $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function yearInOutSummarized(ReportQueryInterface $query, $year, $shared = false)
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('yearInOutSummarized');
     $cache->addProperty($year);
     $cache->addProperty($shared);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $start = new Carbon($year . '-01-01');
     $end = new Carbon($year . '-12-31');
     $shared = $shared == 'shared' ? true : false;
     $income = '0';
     $expense = '0';
     $count = 0;
     bcscale(2);
     while ($start < $end) {
         $month = clone $start;
         $month->endOfMonth();
         // total income and total expenses:
         $currentIncome = $query->incomeInPeriodCorrected($start, $month, $shared)->sum('amount_positive');
         $currentExpense = $query->expenseInPeriodCorrected($start, $month, $shared)->sum('amount_positive');
         Log::debug('Date [' . $month->format('M Y') . ']: income = [' . $income . ' + ' . $currentIncome . '], out = [' . $expense . ' + ' . $currentExpense . ']');
         $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);
 }
Пример #3
0
 /**
  * @param ReportQueryInterface $reportQuery
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function boxOut(ReportQueryInterface $reportQuery)
 {
     $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-out');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount');
     $amount = $amount * -1;
     $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     $cache->store($data);
     return Response::json($data);
 }