diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index 5755f01cb6..3b2f15322f 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -4,6 +4,7 @@ use Firefly\Exception\FireflyException;
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
use Firefly\Helper\Toolkit\ToolkitInterface as tk;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
+use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
/**
@@ -16,17 +17,19 @@ class ChartController extends BaseController
protected $_journals;
protected $_tk;
protected $_preferences;
+ protected $_budgets;
/**
* @param ARI $accounts
* @param TJRI $journals
*/
- public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit)
+ public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit, BRI $budgets)
{
$this->_accounts = $accounts;
$this->_journals = $journals;
$this->_preferences = $preferences;
$this->_tk = $toolkit;
+ $this->_budgets = $budgets;
}
/**
@@ -121,7 +124,7 @@ class ChartController extends BaseController
public function homeCategories()
{
- list($start, $end) =$this->_tk->getDateRangeDates();
+ list($start, $end) = $this->_tk->getDateRangeDates();
$account = null;
$result = [];
// grab all transaction journals in this period:
@@ -159,4 +162,56 @@ class ChartController extends BaseController
return Response::json($chartData);
}
+
+ public function homeBudgets()
+ {
+ // grab all budgets in the time period, like the index does:
+ // get the budgets for this period:
+ $data = [];
+
+ list($start, $end) = $this->_tk->getDateRangeDates();
+ $budgets = $this->_budgets->getWithRepetitionsInPeriod($start, \Session::get('range'));
+
+ $repeatFreq = Config::get('firefly.range_to_repeat_freq.'.Session::get('range'));
+
+ $dateFormats = Config::get('firefly.date_formats_by_period.' . $repeatFreq);
+ if (is_null($dateFormats)) {
+ throw new FireflyException('No date formats for ' . \Session::get('range'));
+ }
+
+
+ $limitInPeriod = 'Envelope for ' . $start->format($dateFormats['display_date']);
+ $spentInPeriod = 'Spent in ' . $start->format($dateFormats['display_date']);
+
+ $data['series'] = [
+ [
+ 'name' => $limitInPeriod,
+ 'data' => []
+ ],
+ [
+ 'name' => $spentInPeriod,
+ 'data' => []
+ ],
+ ];
+
+
+ foreach ($budgets as $budget) {
+ if ($budget->count > 0) {
+ $data['labels'][] = wordwrap($budget->name, 12, "
");
+ }
+ foreach ($budget->limits as $limit) {
+ foreach ($limit->limitrepetitions as $rep) {
+ //0: envelope for period:
+ $data['series'][0]['data'][] = floatval($rep->amount);
+ $data['series'][1]['data'][] = $rep->spent;
+ }
+ }
+
+
+ }
+ return Response::json($data);
+ echo '
'; + print_r($data); + + } } \ No newline at end of file diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index edc007129c..5640c3c004 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -43,6 +43,8 @@ class TransactionController extends BaseController $budgets[0] = '(no budget)'; + + return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with( 'what', $what ); @@ -106,14 +108,23 @@ class TransactionController extends BaseController } Session::flash('success', 'Transaction saved'); - return Redirect::route('index'); + + if(Input::get('create') == '1') { + return Redirect::route('transactions.create',$what)->withInput(); + } else { + return Redirect::route('index'); + } + + + } - public function index() { + public function index() + { $transactions = $this->_journal->paginate(25); - return View::make('transactions.index')->with('transactions',$transactions); + return View::make('transactions.index')->with('transactions', $transactions); } public function show($journalId) diff --git a/app/routes.php b/app/routes.php index 50580e697f..61aa59d180 100644 --- a/app/routes.php +++ b/app/routes.php @@ -9,6 +9,7 @@ Route::group(['before' => 'auth'], function () { // 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']); + Route::get('/chart/home/budgets', ['uses' => 'ChartController@homeBudgets', 'as' => 'chart.budgets']); Route::get('/chart/home/info/{account}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']); diff --git a/app/views/index.blade.php b/app/views/index.blade.php index e8c3b142bc..0d73a3b2d8 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -65,50 +65,10 @@@endif @@ -107,7 +107,7 @@ @endifdiff --git a/app/views/transactions/create.blade.php b/app/views/transactions/create.blade.php index c3f5c76928..5634fc7ff4 100644 --- a/app/views/transactions/create.blade.php +++ b/app/views/transactions/create.blade.php @@ -53,7 +53,7 @@ @endifBudgets
- @foreach($budgets as $budget) -{{{$budget->name}}} - @if($budget->count > 0) - @foreach($budget->limits as $limit) - @foreach($limit->limitrepetitions as $rep) - {{mf($rep->amount,false)}} - @endforeach - @endforeach - @endif -
- @if($budget->count == 0) - - @else - @foreach($budget->limits as $limit) - @foreach($limit->limitrepetitions as $rep) - @if($rep->left() < 0) - --- ++- @else - --- @endif - - - @endforeach - @endforeach - @endif - @endforeach - -- {{Form::select('account_id',$accounts,Input::old('account_id'),['class' => 'form-control'])}} + {{Form::select('account_id',$accounts,Input::old('account_id') ?: Input::get('account'),['class' => 'form-control'])}}- +@@ -123,7 +123,7 @@@endif - +Optional fields
- + @if($what == 'withdrawal')@@ -133,11 +133,11 @@- + Add more fine-grained information to this transaction by entering a category. Like the beneficiary-field, this field will auto-complete existing categories but can also be used to create new ones. @@ -156,7 +156,7 @@diff --git a/public/assets/javascript/index.js b/public/assets/javascript/index.js index e895811d89..02981645e4 100644 --- a/public/assets/javascript/index.js +++ b/public/assets/javascript/index.js @@ -20,6 +20,10 @@ $(function () { return '$' + Highcharts.numberFormat(this.y, 0); } }, + subtitle: { + text: 'View more', + useHTML: true + }, xAxis: { floor: 0, @@ -97,6 +101,10 @@ $(function () { title: { text: 'Expenses for each categorie' }, + subtitle: { + text: 'View more', + useHTML: true + }, credits: { enabled: false }, @@ -148,5 +156,85 @@ $(function () { /** * Get chart data for budget charts. */ + $.getJSON('chart/home/budgets').success(function (data) { + $('#budgets').highcharts({ + chart: { + type: 'bar' + }, + title: { + text: 'Budgets and spending' + }, + subtitle: { + text: 'View more', + useHTML: true + }, + xAxis: { + categories: data.labels, + title: { + text: null + }, + labels: { + style: { + fontSize: '11px', + fontFamily: 'Verdana, sans-serif' + } + } + }, + yAxis: { + min: 0, + title: { + text: 'Amount (€)', + align: 'high' + }, + labels: { + overflow: 'justify' + } + }, + tooltip: { + formatter: function() {return '€ ' + Highcharts.numberFormat(this.y,2);} + }, + plotOptions: { + bar: { + dataLabels: { + enabled: true, + } + } + }, + legend: { + layout: 'vertical', + align: 'right', + verticalAlign: 'top', + x: -40, + y: 100, + floating: true, + borderWidth: 1, + backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor || '#FFFFFF'), + shadow: true + }, + credits: { + enabled: false + }, + series: data.series +// [ +// { +// name: 'Budget in X', +// data: [107, 31, 635, 203, 2] +// }, +// { +// name: 'Expense in X', +// data: [107, 31, 635, 203, 2] +// }, +// { +// name: 'Budget now', +// data: [133, 156, 947, 408, 6] +// }, +// { +// name: 'Expense now', +// data: [973, 914, 454, 732, 34] +// } +// ] + }); + }); + }); \ No newline at end of file