Various code cleanup things inspired by Code Climate [skip ci]

This commit is contained in:
James Cole 2015-01-31 08:51:40 +01:00
parent 916d85c3fe
commit dde09f9f89
8 changed files with 33 additions and 104 deletions

View File

@ -77,11 +77,7 @@ class HomeController extends BaseController
$preferences->set('viewRange', $range); $preferences->set('viewRange', $range);
Session::forget('range'); Session::forget('range');
} }
if (isset($_SERVER['HTTP_REFERER']) && (!strpos($_SERVER['HTTP_REFERER'], Config::get('app.url')) === false)) { Redirect::to(URL::previous());
return Redirect::back();
} else {
return Redirect::intended();
}
} }
/** /**
@ -90,14 +86,7 @@ class HomeController extends BaseController
public function sessionNext() public function sessionNext()
{ {
Navigation::next(); Navigation::next();
Redirect::to(URL::previous());
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();
}
} }
@ -107,13 +96,6 @@ class HomeController extends BaseController
public function sessionPrev() public function sessionPrev()
{ {
Navigation::prev(); Navigation::prev();
Redirect::to(URL::previous());
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();
}
} }
} }

View File

@ -41,31 +41,24 @@ class TestDataSeeder extends Seeder
protected $_yearAgoStartOfMonth; protected $_yearAgoStartOfMonth;
/** /**
* * A whole bunch of times and dates.
*/ */
public function __construct() public function __construct()
{ {
$this->_startOfMonth = Carbon::now()->startOfMonth(); $this->_startOfMonth = Carbon::now()->startOfMonth();
$this->som = $this->_startOfMonth->format('Y-m-d'); $this->som = $this->_startOfMonth->format('Y-m-d');
$this->_endOfMonth = Carbon::now()->endOfMonth();
$this->_endOfMonth = Carbon::now()->endOfMonth(); $this->eom = $this->_endOfMonth->format('Y-m-d');
$this->eom = $this->_endOfMonth->format('Y-m-d'); $this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth();
$this->nsom = $this->_nextStartOfMonth->format('Y-m-d');
$this->_nextStartOfMonth = Carbon::now()->addMonth()->startOfMonth(); $this->_nextEndOfMonth = Carbon::now()->addMonth()->endOfMonth();
$this->nsom = $this->_nextStartOfMonth->format('Y-m-d'); $this->neom = $this->_nextEndOfMonth->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->_yearAgoStartOfMonth = Carbon::now()->subYear()->startOfMonth();
$this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d'); $this->yasom = $this->_yearAgoStartOfMonth->format('Y-m-d');
$this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth();
$this->_yearAgoEndOfMonth = Carbon::now()->subYear()->startOfMonth(); $this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d');
$this->yaeom = $this->_yearAgoEndOfMonth->format('Y-m-d'); $this->_today = Carbon::now();
$this->today = $this->_today->format('Y-m-d');
$this->_today = Carbon::now();
$this->today = $this->_today->format('Y-m-d');
} }
/** /**
@ -76,67 +69,42 @@ class TestDataSeeder extends Seeder
User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]); User::create(['email' => 'reset@example.com', 'password' => 'functional', 'reset' => 'okokokokokokokokokokokokokokokok', 'remember_token' => null]);
User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]); User::create(['email' => 'functional@example.com', 'password' => 'functional', 'reset' => null, 'remember_token' => null]);
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]); $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]);
Log::debug('Created users.'); Log::debug('Created users.');
// create initial accounts and various other stuff: // create initial accounts and various other stuff:
$this->createAssetAccounts($user); $this->createAssetAccounts($user);
Log::debug('Created asset accounts.');
$this->createBudgets($user); $this->createBudgets($user);
Log::debug('Created budgets.');
$this->createCategories($user); $this->createCategories($user);
Log::debug('Created categories.');
$this->createPiggyBanks($user); $this->createPiggyBanks($user);
Log::debug('Created piggy banks.');
$this->createReminders($user); $this->createReminders($user);
Log::debug('Created reminders.');
$this->createRecurringTransactions($user); $this->createRecurringTransactions($user);
Log::debug('Created recurring transactions.');
$this->createBills($user); $this->createBills($user);
Log::debug('Created bills.');
$this->createExpenseAccounts($user); $this->createExpenseAccounts($user);
Log::debug('Created expense accounts.');
$this->createRevenueAccounts($user); $this->createRevenueAccounts($user);
Log::debug('Created revenue accounts.');
// get some objects from the database: // get some objects from the database:
$checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); $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();
$savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first();
Log::debug('Found savings: ' . json_encode($savings)); $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first();
$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));
$television = Account::whereName('TV 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();
$phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first(); $employer = Account::whereName('Employer')->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));
$bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first(); $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first();
Log::debug('Found bills budget: ' . json_encode($bills));
$groceries = Budget::whereName('Groceries')->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(); $house = Category::whereName('House')->orderBy('id', 'DESC')->first();
Log::debug('Found house category: ' . json_encode($checking));
$withdrawal = TransactionType::whereType('Withdrawal')->first(); $withdrawal = TransactionType::whereType('Withdrawal')->first();
Log::debug('Found withdrawal: ' . json_encode($withdrawal)); $deposit = TransactionType::whereType('Deposit')->first();
$deposit = TransactionType::whereType('Deposit')->first(); $transfer = TransactionType::whereType('Transfer')->first();
Log::debug('Found deposit: ' . json_encode($deposit));
$transfer = TransactionType::whereType('Transfer')->first();
Log::debug('Found transfer: ' . json_encode($transfer));
$euro = TransactionCurrency::whereCode('EUR')->first(); $euro = TransactionCurrency::whereCode('EUR')->first();
Log::debug('Found euro: ' . json_encode($euro));
$rentBill = Bill::where('name', 'Rent')->first(); $rentBill = Bill::where('name', 'Rent')->first();
Log::debug('Found bill "rent": ' . json_encode($rentBill));
$current = clone $this->_yearAgoStartOfMonth; $current = clone $this->_yearAgoStartOfMonth;
@ -146,31 +114,22 @@ class TestDataSeeder extends Seeder
Log::debug('Now at: ' . $cur); Log::debug('Now at: ' . $cur);
// create expenses for rent, utilities, TV, phone on the 1st of the month. // 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); $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); $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); $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); $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. // 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); $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); $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: // income from job:
$this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro); $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); $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro);
Log::debug('Created savings.');
$this->createGroceries($current); $this->createGroceries($current);
Log::debug('Created groceries range.');
$this->createBigExpense(clone $current); $this->createBigExpense(clone $current);
Log::debug('Created big expense.');
echo 'Created test-content for ' . $current->format('F Y') . "\n"; echo 'Created test-content for ' . $current->format('F Y') . "\n";
$current->addMonth(); $current->addMonth();
@ -242,7 +201,7 @@ class TestDataSeeder extends Seeder
$user = User::whereEmail('thegrumpydictator@gmail.com')->first(); $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
$billID = is_null($bill) ? null : $bill->id; $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 */ /** @var TransactionJournal $journal */
$journal = TransactionJournal::create( $journal = TransactionJournal::create(

View File

@ -1,6 +1,6 @@
$(function () { $(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'); googleLineChart('chart/account/' + accountID + '/' + view, 'overview-chart');
} }

View File

@ -1,6 +1,6 @@
$(document).ready(function () { $(document).ready(function () {
if (typeof(googleComboChart) == 'function' && typeof(billID) != 'undefined') { if (typeof(googleComboChart) === 'function' && typeof(billID) !== 'undefined') {
googleComboChart('chart/bills/' + billID, 'bill-overview'); googleComboChart('chart/bills/' + billID, 'bill-overview');
} }
} }

View File

@ -7,10 +7,10 @@ $(function () {
$('.updateIncome').on('click', updateIncome); $('.updateIncome').on('click', updateIncome);
if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') { if (typeof budgetID !== 'undefined' && typeof repetitionID === 'undefined') {
googleColumnChart('chart/budget/' + budgetID + '/spending', 'budgetOverview'); 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'); googleLineChart('chart/budget/' + budgetID + '/' + repetitionID, 'budgetOverview');
} }
@ -24,7 +24,6 @@ function updateSingleRange(e) {
var value = parseInt(input.val()); var value = parseInt(input.val());
var spent = parseFloat($('#spent-' + id).data('value')); var spent = parseFloat($('#spent-' + id).data('value'));
console.log('Spent vs budgeted: ' + spent + ' vs ' + value)
// update small display: // update small display:
if (value > 0) { if (value > 0) {
@ -41,7 +40,6 @@ function updateSingleRange(e) {
// $('#budgeted-' + id).html('Budgeted: <span class="text-success">\u20AC ' + value.toFixed(2) + '</span>'); // $('#budgeted-' + id).html('Budgeted: <span class="text-success">\u20AC ' + value.toFixed(2) + '</span>');
//} //}
} else { } else {
console.log('Set to zero!');
// hide the input: // hide the input:
$('#budget-info-' + id + ' span').hide(); $('#budget-info-' + id + ' span').hide();
$('#budget-info-' + id + ' input').hide(); $('#budget-info-' + id + ' input').hide();
@ -55,10 +53,7 @@ function updateSingleRange(e) {
$('#budget-range-display-' + id).text('\u20AC ' + value.toFixed(2)); $('#budget-range-display-' + id).text('\u20AC ' + value.toFixed(2));
// send a post to Firefly to update the amount: // 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) { $.post('budgets/amount/' + id, {amount: value}).success(function (data) {
console.log('Budget ' + data.name + ' updated!');
// update the link if relevant: // update the link if relevant:
$('#budget-link-' + id).attr('href', 'budgets/show/' + id + '/' + data.repetition); $('#budget-link-' + id).attr('href', 'budgets/show/' + id + '/' + data.repetition);
}); });
@ -97,7 +92,6 @@ function updateTotal() {
// we gaan er X overheen, // we gaan er X overheen,
var pct = totalAmount / sum * 100; var pct = totalAmount / sum * 100;
console.log(pct)
var danger = 100 - pct; var danger = 100 - pct;
var err = 100 - danger; var err = 100 - danger;
$('#progress-bar-default').css('width', 0); $('#progress-bar-default').css('width', 0);
@ -134,14 +128,9 @@ function updateRanges() {
// update progress bar (if relevant) // update progress bar (if relevant)
var barHolder = $('#budget-progress-' + id); var barHolder = $('#budget-progress-' + id);
var spent = parseFloat(barHolder.data('spent')); 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: // send a post to Firefly to update the amount:
$.post('budgets/amount/' + id, {amount: value}).success(function (data) { $.post('budgets/amount/' + id, {amount: value}).success(function (data) {
console.log('Budget ' + data.name + ' updated!');
}); });
}); });

View File

@ -1,6 +1,6 @@
$(function () { $(function () {
if (typeof componentID != 'undefined' && typeof repetitionID == 'undefined') { if (typeof componentID !== 'undefined' && typeof repetitionID === 'undefined') {
googleColumnChart('chart/category/' + componentID + '/spending/' + year, 'componentOverview'); googleColumnChart('chart/category/' + componentID + '/spending/' + year, 'componentOverview');
} }

View File

@ -2,7 +2,7 @@ $(function () {
$('.addMoney').on('click', addMoney); $('.addMoney').on('click', addMoney);
$('.removeMoney').on('click', removeMoney); $('.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'); googleLineChart('chart/piggy_history/' + piggyBankID, 'piggy-bank-history');
} }
}); });

View File

@ -22,7 +22,6 @@ function relateTransaction(e) {
var ID = target.data('id'); var ID = target.data('id');
console.log($('#searchRelated').length);
$('#relationModal').empty().load('related/related/' + ID, function () { $('#relationModal').empty().load('related/related/' + ID, function () {
$('#relationModal').modal('show'); $('#relationModal').modal('show');