Now includes chart! [skip ci]

This commit is contained in:
James Cole 2015-05-17 18:03:16 +02:00
parent c9df265c9b
commit 6580752bde
4 changed files with 69 additions and 2 deletions

View File

@ -7,6 +7,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Grumpydictator\Gchart\GChart; use Grumpydictator\Gchart\GChart;
use Illuminate\Support\Collection;
use Preferences; use Preferences;
use Response; use Response;
use Session; use Session;
@ -19,6 +20,60 @@ use Steam;
*/ */
class AccountController extends Controller class AccountController extends Controller
{ {
/**
* Shows the balances for all the user's accounts.
*
* @param GChart $chart
* @param AccountRepositoryInterface $repository
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function all(GChart $chart, AccountRepositoryInterface $repository, $year, $month, $shared = false)
{
$start = new Carbon($year . '-' . $month . '-01');
$end = clone $start;
$end->endOfMonth();
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
/** @var Collection $accounts */
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
if ($shared === false) {
// remove the shared accounts from the collection:
/** @var Account $account */
foreach ($accounts as $index => $account) {
if ($account->getMeta('accountRole') == 'sharedAsset') {
$accounts->forget($index);
}
}
}
$index = 1;
/** @var Account $account */
foreach ($accounts as $account) {
$chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
$chart->addCertainty($index);
$index++;
}
$current = clone $start;
$current->subDay();
$today = Carbon::now();
while ($end >= $current) {
$row = [clone $current];
$certain = $current < $today;
foreach ($accounts as $account) {
$row[] = Steam::balance($account, $current);
$row[] = $certain;
}
$chart->addRowArray($row);
$current->addDay();
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* Shows the balances for all the user's frontpage accounts. * Shows the balances for all the user's frontpage accounts.
* *

View File

@ -276,8 +276,10 @@ Route::group(
*/ */
// accounts: // accounts:
Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']); Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']);
Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where(['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared']);
Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']); Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']);
// bills: // bills:
Route::get('/chart/bill/frontpage', ['uses' => 'Chart\BillController@frontpage']); Route::get('/chart/bill/frontpage', ['uses' => 'Chart\BillController@frontpage']);
Route::get('/chart/bill/{bill}', ['uses' => 'Chart\BillController@single']); Route::get('/chart/bill/{bill}', ['uses' => 'Chart\BillController@single']);

View File

@ -9,6 +9,8 @@ function drawChart() {
googleStackedColumnChart('chart/budget/year/' + year + shared, 'budgets'); googleStackedColumnChart('chart/budget/year/' + year + shared, 'budgets');
googleStackedColumnChart('chart/category/year/' + year + shared, 'categories'); googleStackedColumnChart('chart/category/year/' + year + shared, 'categories');
googleLineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart');
} }
$(function () { $(function () {
@ -39,7 +41,7 @@ function openModal(e) {
function showIncomes() { function showIncomes() {
"use strict"; "use strict";
if(incomeRestShow) { if (incomeRestShow) {
// hide everything, make button say "show" // hide everything, make button say "show"
$('#showIncomes').text(showTheRest); $('#showIncomes').text(showTheRest);
$('.incomesCollapsed').removeClass('in').addClass('out'); $('.incomesCollapsed').removeClass('in').addClass('out');
@ -59,7 +61,7 @@ function showIncomes() {
} }
function showExpenses() { function showExpenses() {
if(expenseRestShow) { if (expenseRestShow) {
// hide everything, make button say "show" // hide everything, make button say "show"
$('#showExpenses').text(showTheRestExpense); $('#showExpenses').text(showTheRestExpense);
$('.expenseCollapsed').removeClass('in').addClass('out'); $('.expenseCollapsed').removeClass('in').addClass('out');

View File

@ -69,7 +69,15 @@
</div> </div>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<!-- load the libraries and scripts necessary for Google Charts: -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/gcharts.options.js"></script>
<script type="text/javascript" src="js/gcharts.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var year = {{ start.year }};
var month = {{ start.month }};
var shared = {% if shared %}'/shared'{% else %}''{% endif %}; var shared = {% if shared %}'/shared'{% else %}''{% endif %};
var incomeTopLength = {{ incomeTopLength }}; var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }}; var expenseTopLength = {{ expenseTopLength }};