Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * 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->income($accounts, $start, $end);
     foreach ($set as $entry) {
         $object->addToTotal($entry->journalAmount);
         $object->addOrCreateIncome($entry);
     }
     return $object;
 }
Ejemplo n.º 4
0
 /**
  * Get a full report on the users incomes during the period.
  *
  * @param Carbon  $start
  * @param Carbon  $end
  * @param boolean $shared
  *
  * @return Income
  */
 public function getIncomeReport($start, $end, $shared)
 {
     $object = new Income();
     $set = $this->query->incomeInPeriodCorrected($start, $end, $shared);
     foreach ($set as $entry) {
         $object->addToTotal($entry->amount);
         $object->addOrCreateIncome($entry);
     }
     return $object;
 }
Ejemplo n.º 5
0
 /**
  * Get a full report on the users expenses during the period for a list of accounts.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return Expense
  */
 public function getExpenseReport($start, $end, Collection $accounts)
 {
     $object = new Expense();
     $set = $this->query->expense($accounts, $start, $end);
     foreach ($set as $entry) {
         $object->addToTotal($entry->journalAmount);
         // can be positive, if it's a transfer
         $object->addOrCreateExpense($entry);
     }
     return $object;
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 /**
  * @param ReportQueryInterface $reportQuery
  *
  * @param ARI                  $accountRepository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function boxOut(ReportQueryInterface $reportQuery, ARI $accountRepository)
 {
     $start = Session::get('start', Carbon::now()->startOfMonth());
     $end = Session::get('end', Carbon::now()->endOfMonth());
     $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
     // 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->expense($accounts, $start, $end)->sum('journalAmount');
     $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     $cache->store($data);
     return Response::json($data);
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return Balance
  */
 public function getBalanceReport(Carbon $start, Carbon $end, Collection $accounts)
 {
     $repository = app('FireflyIII\\Repositories\\Budget\\BudgetRepositoryInterface');
     $tagRepository = app('FireflyIII\\Repositories\\Tag\\TagRepositoryInterface');
     $balance = new Balance();
     // build a balance header:
     $header = new BalanceHeader();
     $budgets = $repository->getBudgets();
     foreach ($accounts as $account) {
         $header->addAccount($account);
     }
     /** @var BudgetModel $budget */
     foreach ($budgets as $budget) {
         $line = new BalanceLine();
         $line->setBudget($budget);
         // get budget amount for current period:
         $rep = $repository->getCurrentRepetition($budget, $start, $end);
         // could be null?
         $line->setRepetition($rep);
         // loop accounts:
         foreach ($accounts as $account) {
             $balanceEntry = new BalanceEntry();
             $balanceEntry->setAccount($account);
             // get spent:
             $spent = $this->query->spentInBudget($account, $budget, $start, $end);
             // I think shared is irrelevant.
             $balanceEntry->setSpent($spent);
             $line->addBalanceEntry($balanceEntry);
         }
         // add line to balance:
         $balance->addBalanceLine($line);
     }
     // then a new line for without budget.
     // and one for the tags:
     // and one for "left unbalanced".
     $empty = new BalanceLine();
     $tags = new BalanceLine();
     $diffLine = new BalanceLine();
     $tags->setRole(BalanceLine::ROLE_TAGROLE);
     $diffLine->setRole(BalanceLine::ROLE_DIFFROLE);
     foreach ($accounts as $account) {
         $spent = $this->query->spentNoBudget($account, $start, $end);
         $left = $tagRepository->coveredByBalancingActs($account, $start, $end);
         bcscale(2);
         $diff = bcadd($spent, $left);
         // budget
         $budgetEntry = new BalanceEntry();
         $budgetEntry->setAccount($account);
         $budgetEntry->setSpent($spent);
         $empty->addBalanceEntry($budgetEntry);
         // balanced by tags
         $tagEntry = new BalanceEntry();
         $tagEntry->setAccount($account);
         $tagEntry->setLeft($left);
         $tags->addBalanceEntry($tagEntry);
         // difference:
         $diffEntry = new BalanceEntry();
         $diffEntry->setAccount($account);
         $diffEntry->setSpent($diff);
         $diffLine->addBalanceEntry($diffEntry);
     }
     $balance->addBalanceLine($empty);
     $balance->addBalanceLine($tags);
     $balance->addBalanceLine($diffLine);
     $balance->setBalanceHeader($header);
     return $balance;
 }