mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 09:51:40 +00:00
First basic version that "works". Now it's time to do some code cleanup. [skip ci]
This commit is contained in:
@@ -4,6 +4,7 @@ use Firefly\Exception\FireflyException;
|
|||||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||||
use Firefly\Helper\Toolkit\ToolkitInterface as tk;
|
use Firefly\Helper\Toolkit\ToolkitInterface as tk;
|
||||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||||
|
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,17 +17,19 @@ class ChartController extends BaseController
|
|||||||
protected $_journals;
|
protected $_journals;
|
||||||
protected $_tk;
|
protected $_tk;
|
||||||
protected $_preferences;
|
protected $_preferences;
|
||||||
|
protected $_budgets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ARI $accounts
|
* @param ARI $accounts
|
||||||
* @param TJRI $journals
|
* @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->_accounts = $accounts;
|
||||||
$this->_journals = $journals;
|
$this->_journals = $journals;
|
||||||
$this->_preferences = $preferences;
|
$this->_preferences = $preferences;
|
||||||
$this->_tk = $toolkit;
|
$this->_tk = $toolkit;
|
||||||
|
$this->_budgets = $budgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +124,7 @@ class ChartController extends BaseController
|
|||||||
|
|
||||||
public function homeCategories()
|
public function homeCategories()
|
||||||
{
|
{
|
||||||
list($start, $end) =$this->_tk->getDateRangeDates();
|
list($start, $end) = $this->_tk->getDateRangeDates();
|
||||||
$account = null;
|
$account = null;
|
||||||
$result = [];
|
$result = [];
|
||||||
// grab all transaction journals in this period:
|
// grab all transaction journals in this period:
|
||||||
@@ -159,4 +162,56 @@ class ChartController extends BaseController
|
|||||||
return Response::json($chartData);
|
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, "<br>");
|
||||||
|
}
|
||||||
|
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 '<pre>';
|
||||||
|
print_r($data);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@@ -43,6 +43,8 @@ class TransactionController extends BaseController
|
|||||||
|
|
||||||
$budgets[0] = '(no budget)';
|
$budgets[0] = '(no budget)';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with(
|
return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with(
|
||||||
'what', $what
|
'what', $what
|
||||||
);
|
);
|
||||||
@@ -106,14 +108,23 @@ class TransactionController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
Session::flash('success', 'Transaction saved');
|
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);
|
$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)
|
public function show($journalId)
|
||||||
|
@@ -9,6 +9,7 @@ Route::group(['before' => 'auth'], function () {
|
|||||||
// 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']);
|
||||||
|
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']);
|
Route::get('/chart/home/info/{account}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -65,50 +65,10 @@
|
|||||||
<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">
|
||||||
<h4>Budgets</h4>
|
<h4>Budgets</h4>
|
||||||
@foreach($budgets as $budget)
|
|
||||||
<h5><a href="{{route('budgets.show',$budget->id)}}">{{{$budget->name}}}</a>
|
|
||||||
@if($budget->count > 0)
|
|
||||||
@foreach($budget->limits as $limit)
|
|
||||||
@foreach($limit->limitrepetitions as $rep)
|
|
||||||
<small>{{mf($rep->amount,false)}}</small>
|
|
||||||
@endforeach
|
|
||||||
@endforeach
|
|
||||||
@endif
|
|
||||||
</h5>
|
|
||||||
@if($budget->count == 0)
|
|
||||||
<p>
|
|
||||||
<a href="{{route('budgets.limits.create',[$budget->id])}}?startdate={{\Session::get('start')->format('Y-m-d')}}&repeat_freq={{\Config::get('firefly.range_to_repeat_freq.' . \Session::get('range'))}}" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-envelope"></span> Add a new envelope</a>
|
|
||||||
|
|
||||||
</p>
|
<div id="budgets">
|
||||||
@else
|
|
||||||
@foreach($budget->limits as $limit)
|
|
||||||
@foreach($limit->limitrepetitions as $rep)
|
|
||||||
@if($rep->left() < 0)
|
|
||||||
<!-- bar to display when over budget -->
|
|
||||||
<div class="progress progress-striped">
|
|
||||||
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="{{$rep->spent_pct}}" aria-valuemin="0"
|
|
||||||
aria-valuemax="100" style="width: {{$rep->spent_pct}}%;min-width:30px;">{{mf($rep->amount,false)}}</div>
|
|
||||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="{{$rep->overspent_pct}}" aria-valuemin="0"
|
|
||||||
aria-valuemax="100" style="width: {{$rep->overspent_pct}}%;min-width:30px;">{{mf($rep->overspent,false)}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
@else
|
|
||||||
<!-- bar to display when UNDER budget -->
|
|
||||||
<div class="progress progress-striped">
|
|
||||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{$rep->spent_pct}}" aria-valuemin="0"
|
|
||||||
aria-valuemax="100" style="width: {{$rep->spent_pct}}%;min-width:80px;">{{mf($rep->spent,false)}}
|
|
||||||
</div>
|
|
||||||
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="{{$rep->left_pct}}" aria-valuemin="0"
|
|
||||||
aria-valuemax="100" style="width: {{$rep->left_pct}}%;min-width:30px;">{{mf($rep->left,false)}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
|
|
||||||
@endforeach
|
|
||||||
@endforeach
|
|
||||||
@endif
|
|
||||||
@endforeach
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@
|
|||||||
@endif
|
@endif
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{{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'])}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
@endif
|
@endif
|
||||||
</label>
|
</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="number" name="amount" min="0.01" value="{{Input::old('amount') or 0}}" step="any" class="form-control" />
|
<input type="number" name="amount" min="0.01" value="{{Input::old('amount')}}" step="any" class="form-control" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<h4>Optional fields</h4>
|
<h4>Optional fields</h4>
|
||||||
|
|
||||||
<!-- ONLY WHEN CREATING A WITHDRAWAL -->
|
<!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->
|
||||||
@if($what == 'withdrawal')
|
@if($what == 'withdrawal')
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="budget_id" class="col-sm-4 control-label">Budget</label>
|
<label for="budget_id" class="col-sm-4 control-label">Budget</label>
|
||||||
@@ -133,11 +133,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
<!-- CATEGORY ALWAYS -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="category" class="col-sm-4 control-label">Category</label>
|
<label for="category" class="col-sm-4 control-label">Category</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" name="category" value="" autocomplete="off" class="form-control" placeholder="Category" />
|
<input type="text" name="category" value="{{Input::old('category')}}" autocomplete="off" class="form-control" placeholder="Category" />
|
||||||
<span class="help-block">Add more fine-grained information to this transaction by entering a category.
|
<span class="help-block">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
|
Like the beneficiary-field, this field will auto-complete existing categories but can also be used
|
||||||
to create new ones.
|
to create new ones.
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" value="1" name="create">
|
<input type="checkbox" value="1" name="create" @if(Input::old('create') == '1') checked @endif>
|
||||||
Create another (return to this form)
|
Create another (return to this form)
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -20,6 +20,10 @@ $(function () {
|
|||||||
return '$' + Highcharts.numberFormat(this.y, 0);
|
return '$' + Highcharts.numberFormat(this.y, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
subtitle: {
|
||||||
|
text: '<a href="#">View more</a>',
|
||||||
|
useHTML: true
|
||||||
|
},
|
||||||
|
|
||||||
xAxis: {
|
xAxis: {
|
||||||
floor: 0,
|
floor: 0,
|
||||||
@@ -97,6 +101,10 @@ $(function () {
|
|||||||
title: {
|
title: {
|
||||||
text: 'Expenses for each categorie'
|
text: 'Expenses for each categorie'
|
||||||
},
|
},
|
||||||
|
subtitle: {
|
||||||
|
text: '<a href="#">View more</a>',
|
||||||
|
useHTML: true
|
||||||
|
},
|
||||||
credits: {
|
credits: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
@@ -148,5 +156,85 @@ $(function () {
|
|||||||
/**
|
/**
|
||||||
* Get chart data for budget charts.
|
* 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: '<a href="#">View more</a>',
|
||||||
|
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]
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
Reference in New Issue
Block a user