mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 11:19:16 +00:00
Made big headway in preference management, accounts, importing stuff, etc. etc.
This commit is contained in:
61
app/controllers/ChartController.php
Normal file
61
app/controllers/ChartController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon as Carbon;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
|
||||
class ChartController extends BaseController
|
||||
{
|
||||
|
||||
public function __construct(ARI $accounts)
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show home charts.
|
||||
*/
|
||||
public function home(Account $account = null)
|
||||
{
|
||||
// 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 {
|
||||
$chart->addColumn($account->name, 'number');
|
||||
while ($current <= $today) {
|
||||
$row = [clone $current,$account->balance(clone $current)];
|
||||
$current->addDay();
|
||||
$chart->addRowArray($row);
|
||||
}
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
return $chart->getData();
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user