2014-07-06 08:18:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Carbon\Carbon as Carbon;
|
|
|
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
2014-07-08 00:51:25 -05:00
|
|
|
use Firefly\Helper\Toolkit\Toolkit as tk;
|
2014-07-06 08:18:11 -05:00
|
|
|
|
|
|
|
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-08 00:51:25 -05:00
|
|
|
public function homeAccount($account = null)
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
2014-07-08 00:51:25 -05:00
|
|
|
list($start,$end) = tk::getDateRange();
|
|
|
|
$current = clone $start;
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
// chart
|
|
|
|
$chart = App::make('gchart');
|
|
|
|
$chart->addColumn('Day of the month', 'date');
|
|
|
|
|
2014-07-08 00:51:25 -05:00
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
|
|
|
|
if (is_null($account)) {
|
|
|
|
// get accounts:
|
|
|
|
$accounts = $this->accounts->getActiveDefault();
|
|
|
|
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
$chart->addColumn($account->name, 'number');
|
|
|
|
}
|
|
|
|
|
2014-07-08 00:51:25 -05:00
|
|
|
while ($current <= $end) {
|
2014-07-06 08:18:11 -05:00
|
|
|
$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');
|
2014-07-08 00:51:25 -05:00
|
|
|
while ($current <= $end) {
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|