mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 03:53:37 +00:00
New charts + tests.
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon as Carbon;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Helper\Toolkit\Toolkit as tk;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
|
||||
class ChartController extends BaseController
|
||||
{
|
||||
|
||||
protected $accounts;
|
||||
protected $journals;
|
||||
|
||||
public function __construct(ARI $accounts)
|
||||
public function __construct(ARI $accounts, TJRI $journals)
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
$this->journals = $journals;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,7 +21,7 @@ class ChartController extends BaseController
|
||||
*/
|
||||
public function homeAccount($account = null)
|
||||
{
|
||||
list($start,$end) = tk::getDateRange();
|
||||
list($start, $end) = tk::getDateRange();
|
||||
$current = clone $start;
|
||||
|
||||
// chart
|
||||
@@ -27,7 +29,6 @@ class ChartController extends BaseController
|
||||
$chart->addColumn('Day of the month', 'date');
|
||||
|
||||
|
||||
|
||||
if (is_null($account)) {
|
||||
// get accounts:
|
||||
$accounts = $this->accounts->getActiveDefault();
|
||||
@@ -61,7 +62,68 @@ class ChartController extends BaseController
|
||||
|
||||
$chart->generate();
|
||||
return $chart->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all budgets used in transaction(journals) this period:
|
||||
*/
|
||||
public function homeBudgets()
|
||||
{
|
||||
list($start, $end) = tk::getDateRange();
|
||||
|
||||
$result = $this->journals->homeBudgetChart($start, $end);
|
||||
|
||||
// create a chart:
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Budget', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
foreach ($result as $name => $amount) {
|
||||
$chart->addRow($name, $amount);
|
||||
}
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories used in transaction(journals) this period.
|
||||
*/
|
||||
public function homeCategories()
|
||||
{
|
||||
list($start, $end) = tk::getDateRange();
|
||||
|
||||
$result = $this->journals->homeCategoryChart($start, $end);
|
||||
|
||||
// create a chart:
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Category', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
foreach ($result as $name => $amount) {
|
||||
$chart->addRow($name, $amount);
|
||||
}
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get all beneficiaries used in transaction(journals) this period.
|
||||
*/
|
||||
public function homeBeneficiaries()
|
||||
{
|
||||
list($start, $end) = tk::getDateRange();
|
||||
|
||||
$result = $this->journals->homeBeneficiaryChart($start, $end);
|
||||
|
||||
// create a chart:
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Beneficiary', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
foreach ($result as $name => $amount) {
|
||||
$chart->addRow($name, $amount);
|
||||
}
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user