2015-02-23 13:25:48 -06:00
|
|
|
<?php namespace FireflyIII\Http\Controllers;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
|
|
|
use FireflyIII\Models\Account;
|
2015-05-15 13:43:50 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2015-03-04 13:47:00 -06:00
|
|
|
use Session;
|
2015-02-23 13:25:48 -06:00
|
|
|
use View;
|
2015-03-04 13:47:00 -06:00
|
|
|
|
2015-02-23 13:25:48 -06:00
|
|
|
/**
|
|
|
|
* Class ReportController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
|
|
|
class ReportController extends Controller
|
|
|
|
{
|
|
|
|
|
2015-03-29 05:25:46 -05:00
|
|
|
/** @var ReportHelperInterface */
|
|
|
|
protected $helper;
|
|
|
|
|
2015-02-23 13:25:48 -06:00
|
|
|
/**
|
2015-05-23 13:49:57 -05:00
|
|
|
* @codeCoverageIgnore
|
2015-05-24 04:41:52 -05:00
|
|
|
*
|
2015-03-29 05:25:46 -05:00
|
|
|
* @param ReportHelperInterface $helper
|
2015-02-23 13:25:48 -06:00
|
|
|
*/
|
2015-05-16 09:04:51 -05:00
|
|
|
public function __construct(ReportHelperInterface $helper)
|
2015-02-23 13:25:48 -06:00
|
|
|
{
|
2015-05-15 15:00:00 -05:00
|
|
|
parent::__construct();
|
2015-03-29 05:25:46 -05:00
|
|
|
$this->helper = $helper;
|
|
|
|
|
2015-05-15 14:01:24 -05:00
|
|
|
View::share('title', trans('firefly.reports'));
|
2015-02-23 13:25:48 -06:00
|
|
|
View::share('mainTitleIcon', 'fa-line-chart');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-17 02:18:44 -05:00
|
|
|
* @param AccountRepositoryInterface $repository
|
|
|
|
*
|
2015-02-23 13:25:48 -06:00
|
|
|
* @return View
|
2015-05-03 05:58:55 -05:00
|
|
|
* @internal param ReportHelperInterface $helper
|
2015-02-23 13:25:48 -06:00
|
|
|
*/
|
2015-05-15 13:43:50 -05:00
|
|
|
public function index(AccountRepositoryInterface $repository)
|
2015-02-23 13:25:48 -06:00
|
|
|
{
|
2015-05-16 06:06:38 -05:00
|
|
|
$start = Session::get('first');
|
|
|
|
$months = $this->helper->listOfMonths($start);
|
2015-02-23 13:25:48 -06:00
|
|
|
|
2015-05-15 13:43:50 -05:00
|
|
|
// does the user have shared accounts?
|
|
|
|
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
|
|
|
$hasShared = false;
|
|
|
|
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
if ($account->getMeta('accountRole') == 'sharedAsset') {
|
|
|
|
$hasShared = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-16 06:06:38 -05:00
|
|
|
return view('reports.index', compact('months', 'hasShared'));
|
2015-02-23 13:25:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $year
|
|
|
|
* @param string $month
|
|
|
|
*
|
2015-05-17 02:18:44 -05:00
|
|
|
* @param bool $shared
|
|
|
|
*
|
2015-02-23 13:25:48 -06:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2015-05-15 13:38:39 -05:00
|
|
|
public function month($year = '2014', $month = '1', $shared = false)
|
2015-02-23 13:25:48 -06:00
|
|
|
{
|
2015-05-16 06:06:38 -05:00
|
|
|
$start = new Carbon($year . '-' . $month . '-01');
|
2015-06-21 03:50:45 -05:00
|
|
|
$subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]);
|
2015-05-16 06:06:38 -05:00
|
|
|
$subTitleIcon = 'fa-calendar';
|
|
|
|
$end = clone $start;
|
2015-05-16 01:05:04 -05:00
|
|
|
$incomeTopLength = 8;
|
|
|
|
$expenseTopLength = 8;
|
2015-05-15 13:38:39 -05:00
|
|
|
if ($shared == 'shared') {
|
2015-05-15 15:00:00 -05:00
|
|
|
$shared = true;
|
2015-06-21 03:50:45 -05:00
|
|
|
$subTitle = trans('firefly.reportForMonthShared', ['month' => $start->formatLocalized($this->monthFormat)]);
|
2015-05-15 13:38:39 -05:00
|
|
|
}
|
2015-05-15 14:01:24 -05:00
|
|
|
|
2015-05-16 06:06:38 -05:00
|
|
|
$end->endOfMonth();
|
2015-05-15 15:00:00 -05:00
|
|
|
|
2015-05-16 06:53:08 -05:00
|
|
|
$accounts = $this->helper->getAccountReport($start, $end, $shared);
|
|
|
|
$incomes = $this->helper->getIncomeReport($start, $end, $shared);
|
|
|
|
$expenses = $this->helper->getExpenseReport($start, $end, $shared);
|
|
|
|
$budgets = $this->helper->getBudgetReport($start, $end, $shared);
|
|
|
|
$categories = $this->helper->getCategoryReport($start, $end, $shared);
|
2015-05-16 07:51:23 -05:00
|
|
|
$balance = $this->helper->getBalanceReport($start, $end, $shared);
|
2015-05-17 10:54:13 -05:00
|
|
|
$bills = $this->helper->getBillReport($start, $end, $shared);
|
2015-05-16 06:06:38 -05:00
|
|
|
|
2015-05-25 01:12:31 -05:00
|
|
|
Session::flash('gaEventCategory', 'report');
|
|
|
|
Session::flash('gaEventAction', 'month');
|
|
|
|
Session::flash('gaEventLabel', $start->format('F Y'));
|
|
|
|
|
2015-05-16 06:06:38 -05:00
|
|
|
|
|
|
|
return view(
|
|
|
|
'reports.month',
|
|
|
|
compact(
|
|
|
|
'start', 'shared',
|
|
|
|
'subTitle', 'subTitleIcon',
|
2015-05-16 06:53:08 -05:00
|
|
|
'accounts',
|
|
|
|
'incomes', 'incomeTopLength',
|
|
|
|
'expenses', 'expenseTopLength',
|
2015-05-17 02:18:44 -05:00
|
|
|
'budgets', 'balance',
|
2015-05-17 10:54:13 -05:00
|
|
|
'categories',
|
|
|
|
'bills'
|
2015-05-16 06:06:38 -05:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-17 02:18:44 -05:00
|
|
|
* @param $year
|
|
|
|
*
|
|
|
|
* @param bool $shared
|
2015-05-16 06:06:38 -05:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function year($year, $shared = false)
|
|
|
|
{
|
|
|
|
$start = new Carbon('01-01-' . $year);
|
|
|
|
$end = clone $start;
|
|
|
|
$subTitle = trans('firefly.reportForYear', ['year' => $year]);
|
|
|
|
$subTitleIcon = 'fa-bar-chart';
|
|
|
|
$incomeTopLength = 8;
|
|
|
|
$expenseTopLength = 8;
|
|
|
|
|
|
|
|
if ($shared == 'shared') {
|
|
|
|
$shared = true;
|
|
|
|
$subTitle = trans('firefly.reportForYearShared', ['year' => $year]);
|
|
|
|
}
|
|
|
|
$end->endOfYear();
|
|
|
|
|
|
|
|
$accounts = $this->helper->getAccountReport($start, $end, $shared);
|
|
|
|
$incomes = $this->helper->getIncomeReport($start, $end, $shared);
|
|
|
|
$expenses = $this->helper->getExpenseReport($start, $end, $shared);
|
|
|
|
|
2015-05-25 01:12:31 -05:00
|
|
|
Session::flash('gaEventCategory', 'report');
|
|
|
|
Session::flash('gaEventAction', 'year');
|
|
|
|
Session::flash('gaEventLabel', $start->format('Y'));
|
|
|
|
|
2015-02-24 15:53:38 -06:00
|
|
|
return view(
|
2015-05-15 15:00:00 -05:00
|
|
|
'reports.year',
|
2015-06-04 14:35:36 -05:00
|
|
|
compact('start', 'shared', 'accounts', 'incomes', 'expenses', 'subTitle', 'subTitleIcon', 'incomeTopLength', 'expenseTopLength')
|
2015-02-23 13:25:48 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|