2014-07-29 13:30:50 -05:00
|
|
|
<?php
|
2014-11-02 11:46:01 -06:00
|
|
|
use Carbon\Carbon;
|
2014-08-02 00:34:38 -05:00
|
|
|
|
2014-08-10 08:01:46 -05:00
|
|
|
/**
|
|
|
|
* Class ReportController
|
|
|
|
*/
|
2014-08-02 00:34:38 -05:00
|
|
|
class ReportController extends BaseController
|
|
|
|
{
|
2014-07-29 13:30:50 -05:00
|
|
|
|
|
|
|
|
2014-08-10 08:01:46 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2014-07-29 13:30:50 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-11-02 11:46:01 -06:00
|
|
|
/** @var \FireflyIII\Database\TransactionJournal $journals */
|
|
|
|
$journals = App::make('FireflyIII\Database\TransactionJournal');
|
|
|
|
$journal = $journals->first();
|
|
|
|
|
|
|
|
$date = $journal->date;
|
|
|
|
$years = [];
|
|
|
|
while ($date <= Carbon::now()) {
|
|
|
|
$years[] = $date->format('Y');
|
|
|
|
$date->addYear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return View::make('reports.index', compact('years'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $year
|
|
|
|
*/
|
|
|
|
public function year($year)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$date = new Carbon('01-01-' . $year);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
App::abort(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
|
|
|
$tj = App::make('FireflyIII\Database\TransactionJournal');
|
|
|
|
|
|
|
|
// get some sums going
|
|
|
|
$summary = [];
|
|
|
|
|
|
|
|
|
|
|
|
$end = clone $date;
|
|
|
|
$end->endOfYear();
|
|
|
|
while ($date < $end) {
|
|
|
|
$summary[] = [
|
|
|
|
'month' => $date->format('F'),
|
|
|
|
'income' => $tj->getSumOfIncomesByMonth($date),
|
|
|
|
'expense' => $tj->getSumOfExpensesByMonth($date),
|
|
|
|
];
|
|
|
|
$date->addMonth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// draw some charts etc.
|
|
|
|
return View::make('reports.year', compact('summary'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart')->with('subTitle', $year)->with(
|
|
|
|
'subTitleIcon', 'fa-bar-chart'
|
|
|
|
)->with('year', $year);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|