mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small optimalizations.
This commit is contained in:
parent
a24c90eae8
commit
9327430484
@ -42,7 +42,7 @@ class BudgetController extends BaseController
|
||||
$date = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount);
|
||||
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition->id]);
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ class GoogleChartController extends BaseController
|
||||
{
|
||||
$this->_chart->addColumn('Day of month', 'date');
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
$this->_chart->addCertainty(1);
|
||||
|
||||
$start = $this->_start;
|
||||
$end = $this->_end;
|
||||
@ -61,7 +62,7 @@ class GoogleChartController extends BaseController
|
||||
$current = clone $start;
|
||||
|
||||
while ($end >= $current) {
|
||||
$this->_chart->addRow(clone $current, Steam::balance($account, $current));
|
||||
$this->_chart->addRow(clone $current, Steam::balance($account, $current), false);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
@ -86,17 +87,23 @@ class GoogleChartController extends BaseController
|
||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||
$accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']);
|
||||
|
||||
$index = 1;
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
$this->_chart->addCertainty($index);
|
||||
$index++;
|
||||
}
|
||||
$current = clone $this->_start;
|
||||
$current->subDay();
|
||||
|
||||
$today = Carbon::now();
|
||||
while ($this->_end >= $current) {
|
||||
$row = [clone $current];
|
||||
$row = [clone $current];
|
||||
$certain = $current < $today;
|
||||
foreach ($accounts as $account) {
|
||||
|
||||
$row[] = Steam::balance($account, $current);
|
||||
$row[] = $certain;
|
||||
}
|
||||
$this->_chart->addRowArray($row);
|
||||
$current->addDay();
|
||||
@ -108,6 +115,49 @@ class GoogleChartController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allBudgetsAndSpending($year)
|
||||
{
|
||||
try {
|
||||
new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
return View::make('error')->with('message', 'Invalid year.');
|
||||
}
|
||||
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
|
||||
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
|
||||
$budgets = $budgetRepository->get();
|
||||
$budgets->sortBy('name');
|
||||
$this->_chart->addColumn('Month', 'date');
|
||||
foreach ($budgets as $budget) {
|
||||
$this->_chart->addColumn($budget->name, 'number');
|
||||
}
|
||||
$start = Carbon::createFromDate(intval($year), 1, 1);
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
|
||||
|
||||
while ($start <= $end) {
|
||||
$row = [clone $start];
|
||||
foreach ($budgets as $budget) {
|
||||
$spent = $budgetRepository->spentInMonth($budget, $start);
|
||||
//$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
|
||||
$row[] = $spent;
|
||||
}
|
||||
$this->_chart->addRowArray($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$this->_chart->generate();
|
||||
|
||||
return Response::json($this->_chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
@ -77,8 +77,11 @@ class HomeController extends BaseController
|
||||
$preferences->set('viewRange', $range);
|
||||
Session::forget('range');
|
||||
}
|
||||
|
||||
return Redirect::back();
|
||||
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {
|
||||
return Redirect::back();
|
||||
} else {
|
||||
return Redirect::intended();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +90,11 @@ class HomeController extends BaseController
|
||||
public function sessionNext()
|
||||
{
|
||||
Navigation::next();
|
||||
return Redirect::back();
|
||||
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {
|
||||
return Redirect::back();
|
||||
} else {
|
||||
return Redirect::intended();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -98,6 +105,10 @@ class HomeController extends BaseController
|
||||
{
|
||||
Navigation::prev();
|
||||
|
||||
return Redirect::back();
|
||||
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {
|
||||
return Redirect::back();
|
||||
} else {
|
||||
return Redirect::intended();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,11 +126,10 @@ class ReportController extends BaseController
|
||||
$balances = $this->_repository->yearBalanceReport($date);
|
||||
$groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15);
|
||||
$groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15);
|
||||
$budgets = \Auth::user()->budgets()->get();
|
||||
|
||||
return View::make(
|
||||
'reports.year',
|
||||
compact('date', 'groupedIncomes', 'budgets', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon')
|
||||
compact('date', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'title', 'subTitle', 'subTitleIcon', 'mainTitleIcon')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -133,20 +133,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@foreach($budgets as $budget)
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{{$budget->name}}}
|
||||
Budgets
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="budgets" data-id="{{{$budget->id}}}" id="budgets-{{{$budget->id}}}"></div>
|
||||
<div id="budgets"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
|
||||
@stop
|
||||
|
@ -113,6 +113,43 @@ function googleColumnChart(URL, container, options) {
|
||||
}
|
||||
}
|
||||
|
||||
function googleStackedColumnChart(URL, container, options) {
|
||||
if ($('#' + container).length == 1) {
|
||||
$.getJSON(URL).success(function (data) {
|
||||
/*
|
||||
Get the data from the JSON
|
||||
*/
|
||||
gdata = new google.visualization.DataTable(data);
|
||||
|
||||
/*
|
||||
Format as money
|
||||
*/
|
||||
var money = new google.visualization.NumberFormat({
|
||||
decimalSymbol: ',',
|
||||
groupingSymbol: '.',
|
||||
prefix: currencyCode + ' '
|
||||
});
|
||||
for (i = 1; i < gdata.getNumberOfColumns(); i++) {
|
||||
money.format(gdata, i);
|
||||
}
|
||||
|
||||
/*
|
||||
Create a new google charts object.
|
||||
*/
|
||||
var chart = new google.visualization.ColumnChart(document.getElementById(container));
|
||||
/*
|
||||
Draw it:
|
||||
*/
|
||||
chart.draw(gdata, options || defaultStackedColumnChartOptions);
|
||||
|
||||
}).fail(function () {
|
||||
$('#' + container).addClass('google-chart-error');
|
||||
});
|
||||
} else {
|
||||
console.log('No container found called "' + container + '"');
|
||||
}
|
||||
}
|
||||
|
||||
function googleComboChart(URL, container, options) {
|
||||
if ($('#' + container).length == 1) {
|
||||
$.getJSON(URL).success(function (data) {
|
||||
|
@ -96,20 +96,11 @@ var defaultStackedColumnChartOptions = {
|
||||
width: '85%',
|
||||
height: '80%'
|
||||
},
|
||||
vAxis: {format: '\u20AC #'},
|
||||
legend: {
|
||||
position: 'none'
|
||||
},
|
||||
isStacked: true,
|
||||
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
|
||||
vAxis: {
|
||||
textStyle: {
|
||||
color: '#838383',
|
||||
fontName: 'Roboto2',
|
||||
fontSize: '12'
|
||||
},
|
||||
format: '\u20AC #'
|
||||
},
|
||||
hAxis: {
|
||||
textStyle: {
|
||||
color: '#838383',
|
||||
@ -120,6 +111,14 @@ var defaultStackedColumnChartOptions = {
|
||||
color: 'transparent'
|
||||
}
|
||||
},
|
||||
vAxis: {
|
||||
textStyle: {
|
||||
color: '#838383',
|
||||
fontName: 'Roboto2',
|
||||
fontSize: '12'
|
||||
},
|
||||
format: '\u20AC #'
|
||||
}
|
||||
};
|
||||
|
||||
var defaultPieChartOptions = {
|
||||
|
@ -4,10 +4,6 @@ if (typeof(google) != 'undefined') {
|
||||
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
|
||||
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
|
||||
|
||||
$.each($('.budgets'), function (i, v) {
|
||||
var holder = $(v);
|
||||
var id = holder.data('id');
|
||||
googleColumnChart('chart/budget/' + id + '/spending/' + year, 'budgets-' + id);
|
||||
});
|
||||
googleStackedColumnChart('chart/budgets/spending/' + year, 'budgets');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user