2014-07-06 08:18:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Carbon\Carbon as Carbon;
|
|
|
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
|
|
|
|
|
|
|
class ChartController extends BaseController
|
|
|
|
{
|
|
|
|
|
2014-07-06 14:07:52 -05:00
|
|
|
protected $accounts;
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
public function __construct(ARI $accounts)
|
|
|
|
{
|
|
|
|
$this->accounts = $accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show home charts.
|
|
|
|
*/
|
2014-07-06 14:07:52 -05:00
|
|
|
public function home($account = null)
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
|
|
|
// chart
|
|
|
|
$chart = App::make('gchart');
|
|
|
|
$chart->addColumn('Day of the month', 'date');
|
|
|
|
|
|
|
|
// date
|
|
|
|
$today = new Carbon;
|
|
|
|
$past = clone $today;
|
|
|
|
$past->subMonth();
|
|
|
|
$current = clone $past;
|
|
|
|
|
|
|
|
if (is_null($account)) {
|
|
|
|
// get accounts:
|
|
|
|
$accounts = $this->accounts->getActiveDefault();
|
|
|
|
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
$chart->addColumn($account->name, 'number');
|
|
|
|
}
|
|
|
|
|
|
|
|
while ($current <= $today) {
|
|
|
|
$row = [clone $current];
|
|
|
|
|
|
|
|
// loop accounts:
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
$row[] = $account->balance(clone $current);
|
|
|
|
}
|
|
|
|
$current->addDay();
|
|
|
|
$chart->addRowArray($row);
|
|
|
|
}
|
|
|
|
} else {
|
2014-07-06 14:07:52 -05:00
|
|
|
$account = $this->accounts->find($account);
|
|
|
|
if (is_null($account)) {
|
|
|
|
return View::make('error')->with('message', 'No account found.');
|
|
|
|
}
|
2014-07-06 08:18:11 -05:00
|
|
|
$chart->addColumn($account->name, 'number');
|
|
|
|
while ($current <= $today) {
|
2014-07-06 14:07:52 -05:00
|
|
|
$row = [clone $current, $account->balance(clone $current)];
|
2014-07-06 08:18:11 -05:00
|
|
|
$current->addDay();
|
|
|
|
$chart->addRowArray($row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$chart->generate();
|
|
|
|
return $chart->getData();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|