Files
firefly-iii/app/controllers/ReportController.php

136 lines
4.4 KiB
PHP
Raw Normal View History

<?php
2014-11-02 18:46:01 +01:00
use Carbon\Carbon;
2014-12-13 22:54:52 +01:00
use FireflyIII\Database\TransactionJournal\TransactionJournal as TransactionJournalRepository;
use FireflyIII\Report\ReportInterface as Report;
2014-08-10 15:01:46 +02:00
/**
2014-12-31 16:17:43 +01:00
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
2014-12-14 20:40:02 +01:00
*
2014-08-10 15:01:46 +02:00
* Class ReportController
*/
class ReportController extends BaseController
{
2014-12-28 08:54:53 +01:00
/** @var \FireflyIII\Database\Budget\Budget */
protected $_budgets;
2014-12-07 15:37:53 +01:00
/** @var TransactionJournalRepository */
protected $_journals;
2014-12-13 22:54:52 +01:00
/** @var Report */
2014-12-07 15:37:53 +01:00
protected $_repository;
/**
* @param TransactionJournalRepository $journals
2014-12-13 22:54:52 +01:00
* @param Report $repository
2014-12-07 15:37:53 +01:00
*/
2014-12-28 08:54:53 +01:00
public function __construct(TransactionJournalRepository $journals, Report $repository)
2014-12-07 15:37:53 +01:00
{
$this->_journals = $journals;
$this->_repository = $repository;
2014-12-28 08:54:53 +01:00
/** @var \FireflyIII\Database\Budget\Budget _budgets */
$this->_budgets = App::make('FireflyIII\Database\Budget\Budget');
2014-12-07 15:37:53 +01:00
2014-12-25 09:50:01 +01:00
View::share('title', 'Reports');
View::share('mainTitleIcon', 'fa-line-chart');
2014-12-07 15:37:53 +01:00
}
2014-12-28 08:54:53 +01:00
/**
* @param string $year
* @param string $month
*
* @return \Illuminate\View\View
*/
public function budget($year = '2014', $month = '1')
{
try {
new Carbon($year . '-' . $month . '-01');
} catch (Exception $e) {
2014-12-30 17:55:46 +01:00
return View::make('error')->with('message', 'Invalid date');
2014-12-28 08:54:53 +01:00
}
2015-01-18 21:07:40 +01:00
$date = new Carbon($year . '-' . $month . '-01');
$dayEarly = clone $date;
2015-01-18 09:50:51 +01:00
$subTitle = 'Budget report for ' . $date->format('F Y');
$subTitleIcon = 'fa-calendar';
2015-01-18 21:07:40 +01:00
$dayEarly = $dayEarly->subDay();
$accounts = $this->_repository->getAccountListBudgetOverview($date);
$budgets = $this->_repository->getBudgetsForMonth($date);
2014-12-28 08:54:53 +01:00
2015-01-18 21:07:40 +01:00
return View::make('reports.budget', compact('subTitle', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
2014-12-28 08:54:53 +01:00
}
2014-08-10 15:01:46 +02:00
/**
*
*/
public function index()
{
2014-12-07 15:37:53 +01:00
$start = $this->_journals->firstDate();
2014-12-13 22:54:52 +01:00
$months = $this->_repository->listOfMonths(clone $start);
$years = $this->_repository->listOfYears(clone $start);
2014-12-07 15:37:53 +01:00
$title = 'Reports';
$mainTitleIcon = 'fa-line-chart';
2014-11-26 17:20:05 +01:00
2014-12-07 15:37:53 +01:00
return View::make('reports.index', compact('years', 'months', 'title', 'mainTitleIcon'));
2014-11-26 17:20:05 +01:00
}
2014-12-25 09:50:01 +01:00
/**
* @param string $year
* @param string $month
*
* @return \Illuminate\View\View
*/
public function month($year = '2014', $month = '1')
{
try {
new Carbon($year . '-' . $month . '-01');
} catch (Exception $e) {
2014-12-30 17:55:46 +01:00
return View::make('error')->with('message', 'Invalid date.');
2014-12-25 09:50:01 +01:00
}
2014-12-28 08:54:53 +01:00
$date = new Carbon($year . '-' . $month . '-01');
2014-12-25 09:50:01 +01:00
$subTitle = 'Report for ' . $date->format('F Y');
$subTitleIcon = 'fa-calendar';
2014-12-26 21:08:44 +01:00
$displaySum = true; // to show sums in report.
$income = $this->_repository->getIncomeForMonth($date);
$expenses = $this->_repository->getExpenseGroupedForMonth($date, 10);
$budgets = $this->_repository->getBudgetsForMonth($date);
$categories = $this->_repository->getCategoriesForMonth($date, 10);
$accounts = $this->_repository->getAccountsForMonth($date);
return View::make(
'reports.month',
2014-12-28 18:03:35 +01:00
compact('date', 'accounts', 'categories', 'budgets', 'expenses', 'subTitle', 'displaySum', 'subTitleIcon', 'income')
2014-12-26 21:08:44 +01:00
);
2014-12-25 09:50:01 +01:00
}
2014-11-02 18:46:01 +01:00
/**
* @param $year
2014-11-26 17:20:05 +01:00
*
* @return $this
2014-11-02 18:46:01 +01:00
*/
public function year($year)
{
try {
2014-12-07 15:37:53 +01:00
new Carbon('01-01-' . $year);
2014-11-02 18:46:01 +01:00
} catch (Exception $e) {
2014-12-30 17:55:46 +01:00
return View::make('error')->with('message', 'Invalid date.');
2014-11-02 18:46:01 +01:00
}
$date = new Carbon('01-01-' . $year);
$end = clone $date;
$end->endOfYear();
2014-12-07 15:37:53 +01:00
$title = 'Reports';
$subTitle = $year;
$subTitleIcon = 'fa-bar-chart';
$mainTitleIcon = 'fa-line-chart';
2014-12-13 22:54:52 +01:00
$balances = $this->_repository->yearBalanceReport($date);
$groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15);
$groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15);
2014-12-07 15:37:53 +01:00
return View::make(
'reports.year', compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon')
);
}
2015-01-02 06:16:49 +01:00
}