diff --git a/app/assets/javascripts/firefly/index.js b/app/assets/javascripts/firefly/index.js
index b46c80c64a..d6b9e1b0ab 100644
--- a/app/assets/javascripts/firefly/index.js
+++ b/app/assets/javascripts/firefly/index.js
@@ -48,7 +48,6 @@ $(function () {
}
//console.log();
return str;
- return '' + this.series.name + ' on ' + Highcharts.dateFormat("%e %B", this.x) + ':
€ ' + Highcharts.numberFormat(this.y, 2);
}
},
plotOptions: {
@@ -73,7 +72,7 @@ $(function () {
y: e.pageY
},
objectType: 'ajax',
- headingText: '' + this.series.name + '',
+ headingText: '' + this.series.name + '',
width: 250
}
)
@@ -102,7 +101,7 @@ $(function () {
text: 'Expenses for each categorie'
},
subtitle: {
- text: 'View more',
+ text: 'View more',
useHTML: true
},
credits: {
@@ -191,13 +190,24 @@ $(function () {
}
},
tooltip: {
- formatter: function() {return '€ ' + Highcharts.numberFormat(this.y,2);}
+ formatter: function () {
+ return false;
+ return '€ ' + Highcharts.numberFormat(this.y, 2);
+ }
},
plotOptions: {
bar: {
+ cursor: 'pointer',
+ events: {
+ click: function(e) {
+ alert('klik!!');
+ }
+ },
dataLabels: {
enabled: true,
- formatter: function() {return '€ ' + Highcharts.numberFormat(this.y,2);}
+ formatter: function () {
+ return '€ ' + Highcharts.numberFormat(this.y, 2);
+ }
}
}
},
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index 150992a659..84572d05bc 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -1,5 +1,6 @@
_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' => 'View more',
+ 'series' => $serie
+ ];
+
+ return Response::json($data);
+
+
+ }
+
/**
* @param Account $account
*
@@ -70,28 +89,15 @@ class ChartController extends BaseController
return Response::json($data);
}
- /**
- * 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)
+ public function homeAccountInfo(Account $account, $day, $month, $year)
{
- $account = $this->_accounts->findByName($name);
$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']);
- } else {
- return View::make('error')->with('message', 'No account!');
- }
+ return View::make('charts.info')->with('rows', $result['rows'])->with('sum', $result['sum'])->with(
+ 'account', $account
+ );
}
/**
@@ -115,23 +121,5 @@ class ChartController extends BaseController
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' => 'View more',
- 'series' => $serie
- ];
-
- return Response::json($data);
-
-
}
}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/Controllers/Chart.php b/app/lib/Firefly/Helper/Controllers/Chart.php
index 62290d58cd..2523979ae2 100644
--- a/app/lib/Firefly/Helper/Controllers/Chart.php
+++ b/app/lib/Firefly/Helper/Controllers/Chart.php
@@ -66,8 +66,15 @@ class Chart implements ChartInterface
foreach ($journal->transactions as $transaction) {
$name = $transaction->account->name;
if ($transaction->account->id != $account->id) {
- $result['rows'][$name] = isset($result[$name]) ? $result[$name] + floatval($transaction->amount)
- : floatval($transaction->amount);
+ if (!isset($result['rows'][$name])) {
+ $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);
}
}
@@ -89,7 +96,7 @@ class Chart implements ChartInterface
$data = [];
$budgets = \Auth::user()->budgets()->with(
- ['limits' => function ($q) {
+ ['limits' => function ($q) {
$q->orderBy('limits.startdate', 'ASC');
}, 'limits.limitrepetitions' => function ($q) use ($start) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
@@ -101,7 +108,11 @@ class Chart implements ChartInterface
$budget->count = 0;
foreach ($budget->limits as $limit) {
/** @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();
// overspent:
if ($rep->left < 0) {
@@ -122,8 +133,6 @@ class Chart implements ChartInterface
}
}
- $limitInPeriod = 'Envelope for XXX';
- $spentInPeriod = 'Spent in XXX';
$data['series'] = [
[
@@ -147,8 +156,8 @@ class Chart implements ChartInterface
$amount = floatval($rep->amount);
$spent = $rep->spent;
$color = $spent > $amount ? '#FF0000' : null;
- $data['series'][0]['data'][] = $amount;
- $data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color];
+ $data['series'][0]['data'][] = ['y' => $amount, 'id' => 'def'];
+ $data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'abc'];
}
}
@@ -158,6 +167,53 @@ class Chart implements ChartInterface
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)
{
$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;
- }
-
}
\ No newline at end of file
diff --git a/app/routes.php b/app/routes.php
index 53da333c74..c82f4fadb9 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -10,6 +10,16 @@ Route::bind('account', function($value, $route)
}
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)
{
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/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
Route::get('/chart/home/account/{account?}', ['uses' => 'ChartController@homeAccount', 'as' => 'chart.home']);
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/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:
diff --git a/app/views/charts/info.blade.php b/app/views/charts/info.blade.php
index 8bcf421910..dbe16970f1 100644
--- a/app/views/charts/info.blade.php
+++ b/app/views/charts/info.blade.php
@@ -3,10 +3,10 @@