From 31b445f725ff6783fa7b3217b03f18778f80d2ff Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 6 Nov 2017 12:50:19 +0200 Subject: [PATCH] Clean up rounding code --- app/Ninja/Datatables/ProductDatatable.php | 2 +- resources/views/invoices/knockout.blade.php | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/Ninja/Datatables/ProductDatatable.php b/app/Ninja/Datatables/ProductDatatable.php index d5a3aba104d6..2325d78f52ac 100644 --- a/app/Ninja/Datatables/ProductDatatable.php +++ b/app/Ninja/Datatables/ProductDatatable.php @@ -30,7 +30,7 @@ class ProductDatatable extends EntityDatatable [ 'cost', function ($model) { - return Utils::formatMoney($model->cost); + return Utils::roundSignificant($model->cost); }, ], [ diff --git a/resources/views/invoices/knockout.blade.php b/resources/views/invoices/knockout.blade.php index 197b327792b2..3e5a336dc2c9 100644 --- a/resources/views/invoices/knockout.blade.php +++ b/resources/views/invoices/knockout.blade.php @@ -866,13 +866,7 @@ function ItemModel(data) { self.loadData = function(data) { ko.mapping.fromJS(data, {}, this); - var precision = getPrecision(this.cost()); - var cost = parseFloat(this.cost()); - if (cost) { - this.cost(cost.toFixed(Math.max(2, precision))); - } else { - this.cost(''); - } + this.cost(roundSignificant(this.cost(), true)); this.qty(roundSignificant(this.qty())); } @@ -1025,9 +1019,7 @@ ko.bindingHandlers.productTypeahead = { } if (parseFloat(datum.cost)) { if (! model.cost() || ! model.task_public_id()) { - var cost = roundSignificant(datum.cost); - var precision = getPrecision(cost); - model.cost(cost.toFixed(precision)); + model.cost(roundSignificant(datum.cost, true)); } } if (!model.qty()) {