Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
First basic version that "works". Now it's time to do some code cleanup. [skip ci]
James Colebcd48f2e4907
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.phpindex 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 BaseControllerprotected $_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 BaseControllerpublic 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 BaseControllerreturn 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);++ }}\ No newline at end of filediff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.phpindex 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.phpindex 50580e697f..61aa59d180 100644--- a/app/routes.php+++ b/app/routes.php@@ -9,6 +9,7 @@ Route::group(['before' => 'auth'], function () {// chart controllerRoute::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.phpindex e8c3b142bc..0d73a3b2d8 100644--- a/app/views/index.blade.php+++ b/app/views/index.blade.php@@ -65,50 +65,10 @@<div class="row"><div class="col-lg-12 col-md-12 col-sm-12"><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>- @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 id="budgets">+</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>diff --git a/app/views/transactions/create.blade.php b/app/views/transactions/create.blade.phpindex c3f5c76928..5634fc7ff4 100644--- a/app/views/transactions/create.blade.php+++ b/app/views/transactions/create.blade.php@@ -53,7 +53,7 @@@endif</label><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>@endif@@ -107,7 +107,7 @@@endif</label><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>@@ -123,7 +123,7 @@<div class="col-lg-6 col-md-12 col-sm-12"><h4>Optional fields</h4>- <!-- ONLY WHEN CREATING A WITHDRAWAL -->+ <!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->@if($what == 'withdrawal')<div class="form-group"><label for="budget_id" class="col-sm-4 control-label">Budget</label>@@ -133,11 +133,11 @@</div></div>@endif-+ <!-- CATEGORY ALWAYS --><div class="form-group"><label for="category" class="col-sm-4 control-label">Category</label><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.Like the beneficiary-field, this field will auto-complete existing categories but can also be usedto create new ones.@@ -156,7 +156,7 @@<div class="col-sm-8"><div class="checkbox"><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)</label></div>diff --git a/public/assets/javascript/index.js b/public/assets/javascript/index.jsindex 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: '<a href="#">View more</a>',+ useHTML: true+ },xAxis: {floor: 0,@@ -97,6 +101,10 @@ $(function () {title: {text: 'Expenses for each categorie'},+ subtitle: {+ text: '<a href="#">View more</a>',+ 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: '<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]+// }+// ]+ });+ });+});\ No newline at end of file