mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-31 18:54:58 +00:00
Small optimalizations.
This commit is contained in:
@@ -42,7 +42,7 @@ class BudgetController extends BaseController
|
|||||||
$date = Session::get('start', Carbon::now()->startOfMonth());
|
$date = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount);
|
$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('Day of month', 'date');
|
||||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||||
|
$this->_chart->addCertainty(1);
|
||||||
|
|
||||||
$start = $this->_start;
|
$start = $this->_start;
|
||||||
$end = $this->_end;
|
$end = $this->_end;
|
||||||
@@ -61,7 +62,7 @@ class GoogleChartController extends BaseController
|
|||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
|
|
||||||
while ($end >= $current) {
|
while ($end >= $current) {
|
||||||
$this->_chart->addRow(clone $current, Steam::balance($account, $current));
|
$this->_chart->addRow(clone $current, Steam::balance($account, $current), false);
|
||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,17 +87,23 @@ class GoogleChartController extends BaseController
|
|||||||
$acct = App::make('FireflyIII\Database\Account\Account');
|
$acct = App::make('FireflyIII\Database\Account\Account');
|
||||||
$accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']);
|
$accounts = count($pref->data) > 0 ? $acct->getByIds($pref->data) : $acct->getAccountsByType(['Default account', 'Asset account']);
|
||||||
|
|
||||||
|
$index = 1;
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||||
|
$this->_chart->addCertainty($index);
|
||||||
|
$index++;
|
||||||
}
|
}
|
||||||
$current = clone $this->_start;
|
$current = clone $this->_start;
|
||||||
$current->subDay();
|
$current->subDay();
|
||||||
|
$today = Carbon::now();
|
||||||
while ($this->_end >= $current) {
|
while ($this->_end >= $current) {
|
||||||
$row = [clone $current];
|
$row = [clone $current];
|
||||||
|
$certain = $current < $today;
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
|
|
||||||
$row[] = Steam::balance($account, $current);
|
$row[] = Steam::balance($account, $current);
|
||||||
|
$row[] = $certain;
|
||||||
}
|
}
|
||||||
$this->_chart->addRowArray($row);
|
$this->_chart->addRowArray($row);
|
||||||
$current->addDay();
|
$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
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -77,8 +77,11 @@ class HomeController extends BaseController
|
|||||||
$preferences->set('viewRange', $range);
|
$preferences->set('viewRange', $range);
|
||||||
Session::forget('range');
|
Session::forget('range');
|
||||||
}
|
}
|
||||||
|
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {
|
||||||
return Redirect::back();
|
return Redirect::back();
|
||||||
|
} else {
|
||||||
|
return Redirect::intended();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +90,11 @@ class HomeController extends BaseController
|
|||||||
public function sessionNext()
|
public function sessionNext()
|
||||||
{
|
{
|
||||||
Navigation::next();
|
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();
|
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);
|
$balances = $this->_repository->yearBalanceReport($date);
|
||||||
$groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15);
|
$groupedIncomes = $this->_repository->revenueGroupedByAccount($date, $end, 15);
|
||||||
$groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15);
|
$groupedExpenses = $this->_repository->expensesGroupedByAccount($date, $end, 15);
|
||||||
$budgets = \Auth::user()->budgets()->get();
|
|
||||||
|
|
||||||
return View::make(
|
return View::make(
|
||||||
'reports.year',
|
'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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@foreach($budgets as $budget)
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
{{{$budget->name}}}
|
Budgets
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="budgets" data-id="{{{$budget->id}}}" id="budgets-{{{$budget->id}}}"></div>
|
<div id="budgets"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
|
||||||
|
|
||||||
|
|
||||||
@stop
|
@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) {
|
function googleComboChart(URL, container, options) {
|
||||||
if ($('#' + container).length == 1) {
|
if ($('#' + container).length == 1) {
|
||||||
$.getJSON(URL).success(function (data) {
|
$.getJSON(URL).success(function (data) {
|
||||||
|
|||||||
@@ -96,20 +96,11 @@ var defaultStackedColumnChartOptions = {
|
|||||||
width: '85%',
|
width: '85%',
|
||||||
height: '80%'
|
height: '80%'
|
||||||
},
|
},
|
||||||
vAxis: {format: '\u20AC #'},
|
|
||||||
legend: {
|
legend: {
|
||||||
position: 'none'
|
position: 'none'
|
||||||
},
|
},
|
||||||
isStacked: true,
|
isStacked: true,
|
||||||
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
|
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
|
||||||
vAxis: {
|
|
||||||
textStyle: {
|
|
||||||
color: '#838383',
|
|
||||||
fontName: 'Roboto2',
|
|
||||||
fontSize: '12'
|
|
||||||
},
|
|
||||||
format: '\u20AC #'
|
|
||||||
},
|
|
||||||
hAxis: {
|
hAxis: {
|
||||||
textStyle: {
|
textStyle: {
|
||||||
color: '#838383',
|
color: '#838383',
|
||||||
@@ -120,6 +111,14 @@ var defaultStackedColumnChartOptions = {
|
|||||||
color: 'transparent'
|
color: 'transparent'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
vAxis: {
|
||||||
|
textStyle: {
|
||||||
|
color: '#838383',
|
||||||
|
fontName: 'Roboto2',
|
||||||
|
fontSize: '12'
|
||||||
|
},
|
||||||
|
format: '\u20AC #'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var defaultPieChartOptions = {
|
var defaultPieChartOptions = {
|
||||||
|
|||||||
@@ -4,10 +4,6 @@ if (typeof(google) != 'undefined') {
|
|||||||
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
|
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
|
||||||
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
|
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
|
||||||
|
|
||||||
$.each($('.budgets'), function (i, v) {
|
googleStackedColumnChart('chart/budgets/spending/' + year, 'budgets');
|
||||||
var holder = $(v);
|
|
||||||
var id = holder.data('id');
|
|
||||||
googleColumnChart('chart/budget/' + id + '/spending/' + year, 'budgets-' + id);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user