From 2d23bb1e3e00ea65ccc04574583274d7e20eef1b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 4 Feb 2014 09:07:16 +0200 Subject: [PATCH] bug fixes --- .gitignore | 15 ++++++++------- app/views/header.blade.php | 7 +++++++ app/views/invoices/edit.blade.php | 12 ++++++------ public/js/script.js | 6 ------ tests/acceptance/WelcomeCept.php | 3 ++- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 7c790a46b2..6ef3ce6c42 100755 --- a/.gitignore +++ b/.gitignore @@ -10,10 +10,11 @@ /bootstrap/compiled.php /bootstrap/environment.php /vendor -composer.phar -.DS_Store -Thumbs.db -app.yaml -database.sql -ninja.sublime-project -ninja.sublime-workspace \ No newline at end of file +/composer.phar +/.DS_Store +/Thumbs.db +/app.yaml +/database.sql +/ninja.sublime-project +/ninja.sublime-workspace +/tests/_log \ No newline at end of file diff --git a/app/views/header.blade.php b/app/views/header.blade.php index d6214918bc..330692d01f 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -48,7 +48,14 @@ var currency = currencies[i]; currencyMap[currency.id] = currency; } + var NINJA = {}; + NINJA.parseFloat = function(str) { + if (!str) return ''; + str = (str+'').replace(/[^0-9\.\-]/g, ''); + return window.parseFloat(str); + } function formatMoney(value, currency_id, hide_symbol) { + value = NINJA.parseFloat(value); if (!currency_id) currency_id = {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY); }}; var currency = currencyMap[currency_id]; return accounting.formatMoney(value, hide_symbol ? '' : currency.symbol, currency.precision, currency.thousand_separator, currency.decimal_separator); diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index b130b01dd6..a9b7d5649d 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -1090,7 +1090,7 @@ var taxRate = parseFloat(self.tax_rate()); if (taxRate > 0) { - total = parseFloat(total) + (total * (taxRate/100)); + total = NINJA.parseFloat(total) + (total * (taxRate/100)); } var paid = self.totals.rawPaidToDate(); @@ -1276,7 +1276,7 @@ this.prettyQty = ko.computed({ read: function () { - return parseFloat(this.qty()) ? parseFloat(this.qty()) : ''; + return NINJA.parseFloat(this.qty()) ? NINJA.parseFloat(this.qty()) : ''; }, write: function (value) { this.qty(value); @@ -1322,9 +1322,9 @@ this.totals = ko.observable(); this.totals.rawTotal = ko.computed(function() { - var cost = parseFloat(self.cost()); - var qty = parseFloat(self.qty()); - var taxRate = parseFloat(self.tax_rate()); + var cost = NINJA.parseFloat(self.cost()); + var qty = NINJA.parseFloat(self.qty()); + var taxRate = NINJA.parseFloat(self.tax_rate()); var value = cost * qty; if (taxRate > 0) { value += value * (taxRate/100); @@ -1436,7 +1436,7 @@ for (var i=0; i 0 ? formatMoney(item.cost(), model.invoice().client().currency_id(), true) : ''); + item.cost(NINJA.parseFloat(item.cost()) > 0 ? formatMoney(item.cost(), model.invoice().client().currency_id(), true) : ''); } onTaxRateChange(); diff --git a/public/js/script.js b/public/js/script.js index ad7a68ffbe..e24a71b970 100755 --- a/public/js/script.js +++ b/public/js/script.js @@ -5,7 +5,6 @@ var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Const var isChrome = !!window.chrome && !isOpera; // Chrome 1+ var isChromium = isChrome && navigator.userAgent.indexOf('Chromium') >= 0; var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6 -var NINJA = {}; function generatePDF(invoice, checkMath) { var client = invoice.client; @@ -380,11 +379,6 @@ function generatePDF(invoice, checkMath) { return doc; } -NINJA.parseFloat = function(str) { - str = str.replace(/[^0-9\.\-]/g, ''); - return window.parseFloat(str); -} - /* Handle converting variables in the invoices (ie, MONTH+1) */ diff --git a/tests/acceptance/WelcomeCept.php b/tests/acceptance/WelcomeCept.php index 8d0b49f70d..215c11087b 100644 --- a/tests/acceptance/WelcomeCept.php +++ b/tests/acceptance/WelcomeCept.php @@ -1,11 +1,12 @@ wantTo('ensure that frontpage works'); +$I->wantTo('click invoice now'); $I->amOnPage('/rocksteady'); $I->click('#startButton'); $I->seeInDatabase('users', ['id' => 1]); +$I->wantTo('create a client'); $I->click('#createClientLink'); $I->fillField('input#email', 'test@aol.com'); $I->click('#clientDoneButton');