mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
- Full move to high charts.
- Cleanup homepage. - Expanded libraries - Added limits (for budgets) - Extended models - Added popups for charts. - [skip-ci]
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||
use Firefly\Helper\Toolkit\Toolkit as tk;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
@@ -12,15 +13,17 @@ class ChartController extends BaseController
|
||||
|
||||
protected $_accounts;
|
||||
protected $_journals;
|
||||
protected $_preferences;
|
||||
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param TJRI $journals
|
||||
*/
|
||||
public function __construct(ARI $accounts, TJRI $journals)
|
||||
public function __construct(ARI $accounts, TJRI $journals, PHI $preferences)
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
$this->_journals = $journals;
|
||||
$this->_preferences = $preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,98 +37,139 @@ class ChartController extends BaseController
|
||||
$current = clone $start;
|
||||
$return = [];
|
||||
$account = null;
|
||||
$today = new Carbon\Carbon;
|
||||
|
||||
if (!is_null($accountId)) {
|
||||
/** @var \Account $account */
|
||||
$account = $this->_accounts->find($accountId);
|
||||
}
|
||||
|
||||
if (is_null($account)) {
|
||||
$accounts = $this->_accounts->getActiveDefault();
|
||||
|
||||
$pref = $this->_preferences->get('frontpageAccounts', []);
|
||||
if ($pref->data == []) {
|
||||
$accounts = $this->_accounts->getActiveDefault();
|
||||
} else {
|
||||
$accounts = $this->_accounts->getByIds($pref->data);
|
||||
}
|
||||
foreach ($accounts as $account) {
|
||||
$return[] = ['name' => $account->name, 'data' => []];
|
||||
$return[] = ['name' => $account->name, 'id' => 'acc-' . $account->id, 'data' => []];
|
||||
|
||||
}
|
||||
while ($current <= $end) {
|
||||
|
||||
// loop accounts:
|
||||
foreach ($accounts as $index => $account) {
|
||||
$return[$index]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)];
|
||||
|
||||
|
||||
if ($current > $today) {
|
||||
$return[$index]['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
|
||||
} else {
|
||||
$return[$index]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)];
|
||||
}
|
||||
}
|
||||
$current->addDay();
|
||||
}
|
||||
} else {
|
||||
$return[0] = ['name' => $account->name, 'data' => []];
|
||||
$return[0] = ['name' => $account->name, 'id' => $account->id, 'data' => []];
|
||||
|
||||
while ($current <= $end) {
|
||||
if ($current > $today) {
|
||||
$return[0]['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
|
||||
} else {
|
||||
$return[0]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)];
|
||||
}
|
||||
|
||||
$return[0]['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)];
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
}
|
||||
// // add an error bar as experiment:
|
||||
// foreach($return as $index => $serie) {
|
||||
// $err = [
|
||||
// 'type' => 'errorbar',
|
||||
// 'name' => $serie['name'].' pred',
|
||||
// 'linkedTo' => $serie['id'],
|
||||
// 'data' => []
|
||||
// ];
|
||||
// foreach($serie['data'] as $entry) {
|
||||
// $err['data'][] = [$entry[0],10,300];
|
||||
// }
|
||||
// $return[] = $err;
|
||||
// }
|
||||
|
||||
|
||||
return Response::json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all budgets used in transaction(journals) this period:
|
||||
* Return some beneficiary info for an account and a date.
|
||||
*
|
||||
* @param $name
|
||||
* @param $day
|
||||
* @param $month
|
||||
* @param $year
|
||||
*/
|
||||
public function homeBudgets()
|
||||
public function homeAccountInfo($name, $day, $month, $year)
|
||||
{
|
||||
list($start, $end) = tk::getDateRange();
|
||||
$data = [
|
||||
'type' => 'pie',
|
||||
'name' => 'Expense: ',
|
||||
'data' => []
|
||||
];
|
||||
$account = $this->_accounts->findByName($name);
|
||||
$result = [];
|
||||
$sum = 0;
|
||||
if ($account) {
|
||||
$date = \Carbon\Carbon::createFromDate($year, $month, $day);
|
||||
$journals = $this->_journals->getByAccountAndDate($account, $date);
|
||||
|
||||
$result = $this->_journals->homeBudgetChart($start, $end);
|
||||
|
||||
foreach ($result as $name => $amount) {
|
||||
$data['data'][] = [$name, $amount];
|
||||
// loop all journals:
|
||||
foreach ($journals as $journal) {
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$name = $transaction->account->name;
|
||||
if ($transaction->account->id != $account->id) {
|
||||
$result[$name] = isset($result[$name]) ? $result[$name] + floatval($transaction->amount)
|
||||
: floatval($transaction->amount);
|
||||
$sum += floatval($transaction->amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Response::json([$data]);
|
||||
|
||||
return View::make('charts.info')->with('rows', $result)->with('sum', $sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories used in transaction(journals) this period.
|
||||
*/
|
||||
public function homeCategories()
|
||||
{
|
||||
public function homeCategories() {
|
||||
list($start, $end) = tk::getDateRange();
|
||||
$account = null;
|
||||
$result = [];
|
||||
// grab all transaction journals in this period:
|
||||
$journals = $this->_journals->getByDateRange($start,$end);
|
||||
|
||||
$result = $this->_journals->homeCategoryChart($start, $end);
|
||||
$data = [
|
||||
'type' => 'pie',
|
||||
'name' => 'Amount: ',
|
||||
'data' => []
|
||||
];
|
||||
$result = [];
|
||||
foreach ($journals as $journal) {
|
||||
// has to be one:
|
||||
|
||||
if (!isset($journal->transactions[0])) {
|
||||
throw new FireflyException('Journal #' . $journal->id . ' has ' . count($journal->transactions)
|
||||
. ' transactions!');
|
||||
}
|
||||
$transaction = $journal->transactions[0];
|
||||
$amount = floatval($transaction->amount);
|
||||
|
||||
// get budget from journal:
|
||||
$budget = $journal->categories()->first();
|
||||
$budgetName = is_null($budget) ? '(no category)' : $budget->name;
|
||||
|
||||
$result[$budgetName] = isset($result[$budgetName]) ? $result[$budgetName] + floatval($amount) : $amount;
|
||||
|
||||
foreach ($result as $name => $amount) {
|
||||
$data['data'][] = [$name, $amount];
|
||||
}
|
||||
return Response::json([$data]);
|
||||
unset($journal, $transaction, $budget, $amount);
|
||||
|
||||
// sort
|
||||
arsort($result);
|
||||
$chartData = [
|
||||
];
|
||||
foreach($result as $name => $value) {
|
||||
$chartData[] = [$name, $value];
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Response::json($chartData);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get all beneficiaries used in transaction(journals) this period.
|
||||
*/
|
||||
public function homeBeneficiaries()
|
||||
{
|
||||
list($start, $end) = tk::getDateRange();
|
||||
$data = [
|
||||
'type' => 'pie',
|
||||
'name' => 'Amount: ',
|
||||
'data' => []
|
||||
];
|
||||
|
||||
$result = $this->_journals->homeBeneficiaryChart($start, $end);
|
||||
|
||||
foreach ($result as $name => $amount) {
|
||||
$data['data'][] = [$name, $amount];
|
||||
}
|
||||
return Response::json([$data]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,24 +30,10 @@ class HomeController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// get list setting:
|
||||
$pref = $this->_preferences->get('frontpageAccounts', []);
|
||||
|
||||
// get the accounts to display on the home screen:
|
||||
$count = $this->_accounts->count();
|
||||
if ($pref->data == []) {
|
||||
$list = $this->_accounts->getActiveDefault();
|
||||
} else {
|
||||
$list = $this->_accounts->getByIds($pref->data);
|
||||
}
|
||||
|
||||
// get transactions for each account:
|
||||
foreach ($list as $account) {
|
||||
$account->transactionList = $this->_journal->getByAccount($account, 10);
|
||||
}
|
||||
|
||||
|
||||
// build the home screen:
|
||||
return View::make('index')->with('count', $count)->with('accounts', $list);
|
||||
return View::make('index')->with('count', $count);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ class MigrationController extends BaseController
|
||||
exit();
|
||||
}
|
||||
}
|
||||
echo '<a href="'.route('index').'">home</a>';
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user