mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Fixed some chart details.
This commit is contained in:
@@ -48,7 +48,6 @@ $(function () {
|
|||||||
}
|
}
|
||||||
//console.log();
|
//console.log();
|
||||||
return str;
|
return str;
|
||||||
return '<span style="font-size:80%;">' + this.series.name + ' on ' + Highcharts.dateFormat("%e %B", this.x) + ':</span><br /> € ' + Highcharts.numberFormat(this.y, 2);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plotOptions: {
|
plotOptions: {
|
||||||
@@ -73,7 +72,7 @@ $(function () {
|
|||||||
y: e.pageY
|
y: e.pageY
|
||||||
},
|
},
|
||||||
objectType: 'ajax',
|
objectType: 'ajax',
|
||||||
headingText: '<a href="#">' + this.series.name + '</a>',
|
headingText: '<a href="accounts/show/' + this.series.id + '">' + this.series.name + '</a>',
|
||||||
width: 250
|
width: 250
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -102,7 +101,7 @@ $(function () {
|
|||||||
text: 'Expenses for each categorie'
|
text: 'Expenses for each categorie'
|
||||||
},
|
},
|
||||||
subtitle: {
|
subtitle: {
|
||||||
text: '<a href="#">View more</a>',
|
text: '<a href="categories/index">View more</a>',
|
||||||
useHTML: true
|
useHTML: true
|
||||||
},
|
},
|
||||||
credits: {
|
credits: {
|
||||||
@@ -191,13 +190,24 @@ $(function () {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
formatter: function() {return '€ ' + Highcharts.numberFormat(this.y,2);}
|
formatter: function () {
|
||||||
|
return false;
|
||||||
|
return '€ ' + Highcharts.numberFormat(this.y, 2);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
plotOptions: {
|
plotOptions: {
|
||||||
bar: {
|
bar: {
|
||||||
|
cursor: 'pointer',
|
||||||
|
events: {
|
||||||
|
click: function(e) {
|
||||||
|
alert('klik!!');
|
||||||
|
}
|
||||||
|
},
|
||||||
dataLabels: {
|
dataLabels: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
formatter: function() {return '€ ' + Highcharts.numberFormat(this.y,2);}
|
formatter: function () {
|
||||||
|
return '€ ' + Highcharts.numberFormat(this.y, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Firefly\Helper\Controllers\ChartInterface;
|
use Firefly\Helper\Controllers\ChartInterface;
|
||||||
use Firefly\Storage\Account\AccountRepositoryInterface;
|
use Firefly\Storage\Account\AccountRepositoryInterface;
|
||||||
|
|
||||||
@@ -22,6 +23,24 @@ class ChartController extends BaseController
|
|||||||
$this->_accounts = $accounts;
|
$this->_accounts = $accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function categoryShowChart(Category $category)
|
||||||
|
{
|
||||||
|
$start = Session::get('start');
|
||||||
|
$end = Session::get('end');
|
||||||
|
$range = Session::get('range');
|
||||||
|
|
||||||
|
$serie = $this->_chart->categoryShowChart($category, $range, $start, $end);
|
||||||
|
$data = [
|
||||||
|
'chart_title' => $category->name,
|
||||||
|
'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',
|
||||||
|
'series' => $serie
|
||||||
|
];
|
||||||
|
|
||||||
|
return Response::json($data);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
@@ -70,28 +89,15 @@ class ChartController extends BaseController
|
|||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function homeAccountInfo(Account $account, $day, $month, $year)
|
||||||
* Return some beneficiary info for an account and a date.
|
|
||||||
*
|
|
||||||
* @param $name
|
|
||||||
* @param $day
|
|
||||||
* @param $month
|
|
||||||
* @param $year
|
|
||||||
*
|
|
||||||
* @return $this|\Illuminate\View\View
|
|
||||||
*/
|
|
||||||
public function homeAccountInfo($name, $day, $month, $year)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$account = $this->_accounts->findByName($name);
|
|
||||||
$date = Carbon::createFromDate($year, $month, $day);
|
$date = Carbon::createFromDate($year, $month, $day);
|
||||||
if ($account) {
|
$result = $this->_chart->accountDailySummary($account, $date);
|
||||||
$result = $this->_chart->accountDailySummary($account, $date);
|
|
||||||
|
|
||||||
return View::make('charts.info')->with('rows', $result['rows'])->with('sum', $result['sum']);
|
return View::make('charts.info')->with('rows', $result['rows'])->with('sum', $result['sum'])->with(
|
||||||
} else {
|
'account', $account
|
||||||
return View::make('error')->with('message', 'No account!');
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,23 +121,5 @@ class ChartController extends BaseController
|
|||||||
return Response::json($this->_chart->categories($start, $end));
|
return Response::json($this->_chart->categories($start, $end));
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function categoryShowChart(Category $category)
|
|
||||||
{
|
|
||||||
$start = Session::get('start');
|
|
||||||
$end = Session::get('end');
|
|
||||||
$range = Session::get('range');
|
|
||||||
|
|
||||||
$serie = $this->_chart->categoryShowChart($category, $range, $start, $end);
|
|
||||||
$data = [
|
|
||||||
'chart_title' => $category->name,
|
|
||||||
'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',
|
|
||||||
'series' => $serie
|
|
||||||
];
|
|
||||||
|
|
||||||
return Response::json($data);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -66,8 +66,15 @@ class Chart implements ChartInterface
|
|||||||
foreach ($journal->transactions as $transaction) {
|
foreach ($journal->transactions as $transaction) {
|
||||||
$name = $transaction->account->name;
|
$name = $transaction->account->name;
|
||||||
if ($transaction->account->id != $account->id) {
|
if ($transaction->account->id != $account->id) {
|
||||||
$result['rows'][$name] = isset($result[$name]) ? $result[$name] + floatval($transaction->amount)
|
if (!isset($result['rows'][$name])) {
|
||||||
: floatval($transaction->amount);
|
$result['rows'][$name] = [
|
||||||
|
'name' => $name,
|
||||||
|
'id' => $transaction->account->id,
|
||||||
|
'amount' => floatval($transaction->amount)
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result['rows'][$name]['amount'] += floatval($transaction->amount);
|
||||||
|
}
|
||||||
$result['sum'] += floatval($transaction->amount);
|
$result['sum'] += floatval($transaction->amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +96,7 @@ class Chart implements ChartInterface
|
|||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
$budgets = \Auth::user()->budgets()->with(
|
$budgets = \Auth::user()->budgets()->with(
|
||||||
['limits' => function ($q) {
|
['limits' => function ($q) {
|
||||||
$q->orderBy('limits.startdate', 'ASC');
|
$q->orderBy('limits.startdate', 'ASC');
|
||||||
}, 'limits.limitrepetitions' => function ($q) use ($start) {
|
}, 'limits.limitrepetitions' => function ($q) use ($start) {
|
||||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||||
@@ -101,7 +108,11 @@ class Chart implements ChartInterface
|
|||||||
$budget->count = 0;
|
$budget->count = 0;
|
||||||
foreach ($budget->limits as $limit) {
|
foreach ($budget->limits as $limit) {
|
||||||
/** @var $rep \LimitRepetition */
|
/** @var $rep \LimitRepetition */
|
||||||
foreach ($limit->limitrepetitions as $rep) {
|
foreach ($limit->limitrepetitions as $index => $rep) {
|
||||||
|
if ($index == 0) {
|
||||||
|
$limitInPeriod = 'Envelope for ' . $rep->periodShow();
|
||||||
|
$spentInPeriod = 'Spent in ' . $rep->periodShow();
|
||||||
|
}
|
||||||
$rep->left = $rep->left();
|
$rep->left = $rep->left();
|
||||||
// overspent:
|
// overspent:
|
||||||
if ($rep->left < 0) {
|
if ($rep->left < 0) {
|
||||||
@@ -122,8 +133,6 @@ class Chart implements ChartInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$limitInPeriod = 'Envelope for XXX';
|
|
||||||
$spentInPeriod = 'Spent in XXX';
|
|
||||||
|
|
||||||
$data['series'] = [
|
$data['series'] = [
|
||||||
[
|
[
|
||||||
@@ -147,8 +156,8 @@ class Chart implements ChartInterface
|
|||||||
$amount = floatval($rep->amount);
|
$amount = floatval($rep->amount);
|
||||||
$spent = $rep->spent;
|
$spent = $rep->spent;
|
||||||
$color = $spent > $amount ? '#FF0000' : null;
|
$color = $spent > $amount ? '#FF0000' : null;
|
||||||
$data['series'][0]['data'][] = $amount;
|
$data['series'][0]['data'][] = ['y' => $amount, 'id' => 'def'];
|
||||||
$data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color];
|
$data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'abc'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +167,53 @@ class Chart implements ChartInterface
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function categories(Carbon $start, Carbon $end)
|
||||||
|
{
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
// grab all transaction journals in this period:
|
||||||
|
$journals = \TransactionJournal::
|
||||||
|
with(
|
||||||
|
['components', 'transactions' => function ($q) {
|
||||||
|
$q->where('amount', '>', 0);
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
|
->where('transaction_types.type', 'Withdrawal')
|
||||||
|
->after($start)->before($end)
|
||||||
|
->where('completed', 1)
|
||||||
|
->get(['transaction_journals.*']);
|
||||||
|
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:
|
||||||
|
$category = $journal->categories()->first();
|
||||||
|
$categoryName = is_null($category) ? '(no category)' : $category->name;
|
||||||
|
|
||||||
|
$result[$categoryName] = isset($result[$categoryName]) ? $result[$categoryName] + floatval($amount)
|
||||||
|
: $amount;
|
||||||
|
|
||||||
|
}
|
||||||
|
unset($journal, $transaction, $category, $amount);
|
||||||
|
|
||||||
|
// sort
|
||||||
|
arsort($result);
|
||||||
|
$chartData = [];
|
||||||
|
foreach ($result as $name => $value) {
|
||||||
|
$chartData[] = [$name, $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $chartData;
|
||||||
|
}
|
||||||
|
|
||||||
public function categoryShowChart(\Category $category, $range, Carbon $start, Carbon $end)
|
public function categoryShowChart(\Category $category, $range, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
$data = ['name' => $category->name . ' per ' . $range, 'data' => []];
|
$data = ['name' => $category->name . ' per ' . $range, 'data' => []];
|
||||||
@@ -316,51 +372,4 @@ class Chart implements ChartInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function categories(Carbon $start, Carbon $end)
|
|
||||||
{
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
// grab all transaction journals in this period:
|
|
||||||
$journals = \TransactionJournal::
|
|
||||||
with(
|
|
||||||
['components', 'transactions' => function ($q) {
|
|
||||||
$q->where('amount', '>', 0);
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
|
||||||
->where('transaction_types.type', 'Withdrawal')
|
|
||||||
->after($start)->before($end)
|
|
||||||
->where('completed', 1)
|
|
||||||
->get(['transaction_journals.*']);
|
|
||||||
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:
|
|
||||||
$category = $journal->categories()->first();
|
|
||||||
$categoryName = is_null($category) ? '(no category)' : $category->name;
|
|
||||||
|
|
||||||
$result[$categoryName] = isset($result[$categoryName]) ? $result[$categoryName] + floatval($amount)
|
|
||||||
: $amount;
|
|
||||||
|
|
||||||
}
|
|
||||||
unset($journal, $transaction, $category, $amount);
|
|
||||||
|
|
||||||
// sort
|
|
||||||
arsort($result);
|
|
||||||
$chartData = [];
|
|
||||||
foreach ($result as $name => $value) {
|
|
||||||
$chartData[] = [$name, $value];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $chartData;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -10,6 +10,16 @@ Route::bind('account', function($value, $route)
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::bind('accountname', function($value, $route)
|
||||||
|
{
|
||||||
|
if(Auth::check()) {
|
||||||
|
return Account::
|
||||||
|
where('name', $value)->
|
||||||
|
where('user_id',Auth::user()->id)->first();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
Route::bind('budget', function($value, $route)
|
Route::bind('budget', function($value, $route)
|
||||||
{
|
{
|
||||||
if(Auth::check()) {
|
if(Auth::check()) {
|
||||||
@@ -89,10 +99,6 @@ Route::group(['before' => 'auth'], function () {
|
|||||||
Route::get('/categories/edit/{category}',['uses' => 'CategoryController@edit','as' => 'categories.edit']);
|
Route::get('/categories/edit/{category}',['uses' => 'CategoryController@edit','as' => 'categories.edit']);
|
||||||
Route::get('/categories/delete/{category}',['uses' => 'CategoryController@delete','as' => 'categories.delete']);
|
Route::get('/categories/delete/{category}',['uses' => 'CategoryController@delete','as' => 'categories.delete']);
|
||||||
|
|
||||||
// home controller
|
|
||||||
Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']);
|
|
||||||
Route::get('/flush', ['uses' => 'HomeController@flush', 'as' => 'flush']);
|
|
||||||
|
|
||||||
// chart controller
|
// chart controller
|
||||||
Route::get('/chart/home/account/{account?}', ['uses' => 'ChartController@homeAccount', 'as' => 'chart.home']);
|
Route::get('/chart/home/account/{account?}', ['uses' => 'ChartController@homeAccount', 'as' => 'chart.home']);
|
||||||
Route::get('/chart/home/categories', ['uses' => 'ChartController@homeCategories', 'as' => 'chart.categories']);
|
Route::get('/chart/home/categories', ['uses' => 'ChartController@homeCategories', 'as' => 'chart.categories']);
|
||||||
@@ -100,6 +106,12 @@ Route::group(['before' => 'auth'], function () {
|
|||||||
Route::get('/chart/home/info/{accountname}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
Route::get('/chart/home/info/{accountname}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
||||||
Route::get('/chart/categories/show/{category}', ['uses' => 'ChartController@categoryShowChart','as' => 'chart.showcategory']);
|
Route::get('/chart/categories/show/{category}', ['uses' => 'ChartController@categoryShowChart','as' => 'chart.showcategory']);
|
||||||
|
|
||||||
|
// home controller
|
||||||
|
Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']);
|
||||||
|
Route::get('/flush', ['uses' => 'HomeController@flush', 'as' => 'flush']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Categories controller:
|
// Categories controller:
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,10 +3,10 @@
|
|||||||
<th>Total</th>
|
<th>Total</th>
|
||||||
<th>{{mf($sum*-1)}}</th>
|
<th>{{mf($sum*-1)}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
@foreach($rows as $name => $amount)
|
@foreach($rows as $name => $entry)
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="#">{{{$name}}}</a></td>
|
<td><a href="{{route('accounts.show',$entry['id'])}}">{{{$name}}}</a></td>
|
||||||
<td>{{mf($amount*-1)}}</td>
|
<td>{{mf($entry['amount']*-1)}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</table>
|
Reference in New Issue
Block a user