Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various code cleanup things inspired by Code Climate [skip ci]
James Coledde09f9f8964
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.phpindex e97bf24bdc..b072dd4867 100644--- a/app/controllers/HomeController.php+++ b/app/controllers/HomeController.php@@ -77,11 +77,7 @@ class HomeController extends BaseController$preferences->set('viewRange', $range);Session::forget('range');}- if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) {- return Redirect::back();- } else {- return Redirect::intended();- }+ Redirect::to(URL::previous());}/**@@ -90,14 +86,7 @@ class HomeController extends BaseControllerpublic function sessionNext(){Navigation::next();-- if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === 0) {- Log::debug('Redirect back');- return Redirect::back();- } else {- Log::debug('Redirect intended');- return Redirect::intended();- }+ Redirect::to(URL::previous());}@@ -107,13 +96,6 @@ class HomeController extends BaseControllerpublic function sessionPrev(){Navigation::prev();-- if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === 0) {- Log::debug('Redirect back');- return Redirect::back();- } else {- Log::debug('Redirect intended');- return Redirect::intended();- }+ Redirect::to(URL::previous());}}diff --git a/app/database/seeds/TestDataSeeder.php b/app/database/seeds/TestDataSeeder.phpindex 6ef7c64842..1ff8892e69 100644--- a/app/database/seeds/TestDataSeeder.php+++ b/app/database/seeds/TestDataSeeder.php@@ -41,31 +41,24 @@ class TestDataSeeder extends Seederprotected $_yearAgoStartOfMonth;/**- *+ * A whole bunch of times and dates.*/public function __construct(){- $this->_startOfMonth = Carbon::now()->startOfMonth();- $this->som = $this->_startOfMonth->format('Y-m-d');-- $this->_endOfMonth = Carbon::now()->endOfMonth();- $this->eom = $this->_endOfMonth->format('Y-m-d');-- $this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();- $this->nsom = $this->_nextStartOfMonth->format('Y-m-d');-- $this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();- $this->neom = $this->_nextEndOfMonth->format('Y-m-d');-+ $this->_startOfMonth = Carbon::now()->startOfMonth();+ $this->som = $this->_startOfMonth->format('Y-m-d');+ $this->_endOfMonth = Carbon::now()->endOfMonth();+ $this->eom = $this->_endOfMonth->format('Y-m-d');+ $this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();+ $this->nsom = $this->_nextStartOfMonth->format('Y-m-d');+ $this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();+ $this->neom = $this->_nextEndOfMonth->format('Y-m-d');$this->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();$this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');-- $this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();- $this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');--- $this->_today = Carbon::now();- $this->today = $this->_today->format('Y-m-d');+ $this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();+ $this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');+ $this->_today = Carbon::now();+ $this->today = $this->_today->format('Y-m-d');}/**@@ -76,67 +69,42 @@ class TestDataSeeder extends SeederUser::create(['email' => '[email protected]', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);User::create(['email' => '[email protected]', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);-$user = User::create(['email' => '[email protected]', 'password' => 'james', 'reset' => null, 'remember_token' => null]);Log::debug('Created users.');// create initial accounts and various other stuff:$this->createAssetAccounts($user);- Log::debug('Created asset accounts.');$this->createBudgets($user);- Log::debug('Created budgets.');$this->createCategories($user);- Log::debug('Created categories.');$this->createPiggyBanks($user);- Log::debug('Created piggy banks.');$this->createReminders($user);- Log::debug('Created reminders.');$this->createRecurringTransactions($user);- Log::debug('Created recurring transactions.');$this->createBills($user);- Log::debug('Created bills.');$this->createExpenseAccounts($user);- Log::debug('Created expense accounts.');$this->createRevenueAccounts($user);- Log::debug('Created revenue accounts.');// get some objects from the database:- $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();- Log::debug('Found checking: ' . json_encode($checking));- $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();- Log::debug('Found savings: ' . json_encode($savings));- $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();- Log::debug('Found landlord: ' . json_encode($landLord));- $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();- Log::debug('Found utilities: ' . json_encode($utilities));+ $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first();+ $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first();+ $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();+ $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();$television = Account::whereName('TV company')->orderBy('id', 'DESC')->first();- Log::debug('Found tv company: ' . json_encode($television));- $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();- Log::debug('Found phone company: ' . json_encode($phone));- $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();- Log::debug('Found employer: ' . json_encode($employer));+ $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first();+ $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first();- $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();- Log::debug('Found bills budget: ' . json_encode($bills));+ $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();$groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first();- Log::debug('Found groceries budget: ' . json_encode($groceries));$house = Category::whereName('House')->orderBy('id', 'DESC')->first();- Log::debug('Found house category: ' . json_encode($checking));$withdrawal = TransactionType::whereType('Withdrawal')->first();- Log::debug('Found withdrawal: ' . json_encode($withdrawal));- $deposit = TransactionType::whereType('Deposit')->first();- Log::debug('Found deposit: ' . json_encode($deposit));- $transfer = TransactionType::whereType('Transfer')->first();- Log::debug('Found transfer: ' . json_encode($transfer));+ $deposit = TransactionType::whereType('Deposit')->first();+ $transfer = TransactionType::whereType('Transfer')->first();$euro = TransactionCurrency::whereCode('EUR')->first();- Log::debug('Found euro: ' . json_encode($euro));$rentBill = Bill::where('name', 'Rent')->first();- Log::debug('Found bill "rent": ' . json_encode($rentBill));$current = clone $this->_yearAgoStartOfMonth;@@ -146,31 +114,22 @@ class TestDataSeeder extends SeederLog::debug('Now at: ' . $cur);// create expenses for rent, utilities, TV, phone on the 1st of the month.+$this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill);- Log::debug('Created rent.');$this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house);- Log::debug('Created utilities.');$this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house);- Log::debug('Created TV.');$this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house);- Log::debug('Created phone bill.');// two transactions. One without a budget, one without a category.$this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house);- Log::debug('Created extra charges no budget.');$this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null);- Log::debug('Created extra charges no category.');// income from job:$this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro);- Log::debug('Created income.');$this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);- Log::debug('Created savings.');$this->createGroceries($current);- Log::debug('Created groceries range.');$this->createBigExpense(clone $current);- Log::debug('Created big expense.');echo 'Created test-content for ' . $current->format('F Y') . "\n";$current->addMonth();@@ -242,7 +201,7 @@ class TestDataSeeder extends Seeder$user = User::whereEmail('[email protected]')->first();$billID = is_null($bill) ? null : $bill->id;- Log::debug('String length of encrypted description ("'.$description.'") is: ' . strlen(Crypt::encrypt($description)));+ Log::debug('String length of encrypted description ("' . $description . '") is: ' . strlen(Crypt::encrypt($description)));/** @var TransactionJournal $journal */$journal = TransactionJournal::create(diff --git a/public/assets/javascript/firefly/accounts.js b/public/assets/javascript/firefly/accounts.jsindex b63d11ca98..d0830eecef 100644--- a/public/assets/javascript/firefly/accounts.js+++ b/public/assets/javascript/firefly/accounts.js@@ -1,6 +1,6 @@$(function () {- if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined' && typeof view != 'undefined') {+ if (typeof(googleLineChart) === "function" && typeof accountID !== 'undefined' && typeof view !== 'undefined') {googleLineChart('chart/account/' + accountID + '/' + view, 'overview-chart');}diff --git a/public/assets/javascript/firefly/bills.js b/public/assets/javascript/firefly/bills.jsindex 01c26984ce..0bddb7f3ef 100644--- a/public/assets/javascript/firefly/bills.js+++ b/public/assets/javascript/firefly/bills.js@@ -1,6 +1,6 @@$(document).ready(function () {- if (typeof(googleComboChart) == 'function' && typeof(billID) != 'undefined') {+ if (typeof(googleComboChart) === 'function' && typeof(billID) !== 'undefined') {googleComboChart('chart/bills/' + billID, 'bill-overview');}}diff --git a/public/assets/javascript/firefly/budgets.js b/public/assets/javascript/firefly/budgets.jsindex e8a856cf4a..bb5de2fca7 100644--- a/public/assets/javascript/firefly/budgets.js+++ b/public/assets/javascript/firefly/budgets.js@@ -7,10 +7,10 @@ $(function () {$('.updateIncome').on('click', updateIncome);- if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') {+ if (typeof budgetID !== 'undefined' && typeof repetitionID === 'undefined') {googleColumnChart('chart/budget/' + budgetID + '/spending', 'budgetOverview');}- if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') {+ if (typeof budgetID !== 'undefined' && typeof repetitionID !== 'undefined') {googleLineChart('chart/budget/' + budgetID + '/' + repetitionID, 'budgetOverview');}@@ -24,7 +24,6 @@ function updateSingleRange(e) {var value = parseInt(input.val());var spent = parseFloat($('#spent-' + id).data('value'));- console.log('Spent vs budgeted: ' + spent + ' vs ' + value)// update small display:if (value > 0) {@@ -41,7 +40,6 @@ function updateSingleRange(e) {// $('#budgeted-' + id).html('Budgeted: <span class="text-success">\u20AC ' + value.toFixed(2) + '</span>');//}} else {- console.log('Set to zero!');// hide the input:$('#budget-info-' + id + ' span').hide();$('#budget-info-' + id + ' input').hide();@@ -55,10 +53,7 @@ function updateSingleRange(e) {$('#budget-range-display-' + id).text('\u20AC ' + value.toFixed(2));// send a post to Firefly to update the amount:- console.log('Value is: ' + value);- console.log('POST! with ID ' + id + ' AND value ' + value);$.post('budgets/amount/' + id, {amount: value}).success(function (data) {- console.log('Budget ' + data.name + ' updated!');// update the link if relevant:$('#budget-link-' + id).attr('href', 'budgets/show/' + id + '/' + data.repetition);});@@ -97,7 +92,6 @@ function updateTotal() {// we gaan er X overheen,var pct = totalAmount / sum * 100;- console.log(pct)var danger = 100 - pct;var err = 100 - danger;$('#progress-bar-default').css('width', 0);@@ -134,14 +128,9 @@ function updateRanges() {// update progress bar (if relevant)var barHolder = $('#budget-progress-' + id);var spent = parseFloat(barHolder.data('spent'));- if (value > 0 && spent > 0) {- console.log('Add bar')- //barHolder.append($('<div class="progress-bar" id="progress-bar-something-' + id + '" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" style="width: 10%;"></div>'));- }// send a post to Firefly to update the amount:$.post('budgets/amount/' + id, {amount: value}).success(function (data) {- console.log('Budget ' + data.name + ' updated!');});});diff --git a/public/assets/javascript/firefly/categories.js b/public/assets/javascript/firefly/categories.jsindex 01cae7033b..694754351b 100644--- a/public/assets/javascript/firefly/categories.js+++ b/public/assets/javascript/firefly/categories.js@@ -1,6 +1,6 @@$(function () {- if (typeof componentID != 'undefined' && typeof repetitionID == 'undefined') {+ if (typeof componentID !== 'undefined' && typeof repetitionID === 'undefined') {googleColumnChart('chart/category/' + componentID + '/spending/' + year, 'componentOverview');}diff --git a/public/assets/javascript/firefly/piggy_banks.js b/public/assets/javascript/firefly/piggy_banks.jsindex f336d2d3fd..8b7ee057c4 100644--- a/public/assets/javascript/firefly/piggy_banks.js+++ b/public/assets/javascript/firefly/piggy_banks.js@@ -2,7 +2,7 @@ $(function () {$('.addMoney').on('click', addMoney);$('.removeMoney').on('click', removeMoney);- if (typeof(googleLineChart) == 'function' && typeof(piggyBankID) != 'undefined') {+ if (typeof(googleLineChart) === 'function' && typeof(piggyBankID) !== 'undefined') {googleLineChart('chart/piggy_history/' + piggyBankID, 'piggy-bank-history');}});diff --git a/public/assets/javascript/firefly/related-manager.js b/public/assets/javascript/firefly/related-manager.jsindex 2c3e55f8af..d824d1191f 100644--- a/public/assets/javascript/firefly/related-manager.js+++ b/public/assets/javascript/firefly/related-manager.js@@ -22,7 +22,6 @@ function relateTransaction(e) {var ID = target.data('id');- console.log($('#searchRelated').length);$('#relationModal').empty().load('related/related/' + ID, function () {$('#relationModal').modal('show');