Forum

Ask, reply and learn. Join the community of Akaunting.

New Discussion

TypeError: e.sale_price.toFixed is not a function

Ngạn Trần Hữu   ( User )

Commented 4 years ago

I installed Akaunting on localhost with XAMPP and it ran normally. But when I uploaded Share hosting, when I created a new invoice and added the product, the price and quantity didn't fill in automatically. In the Console, the error "TypeError: e.sale_price.toFixed is not a function" error appears. Please help me! Thank you!

Zrwstcom   ( User )

Commented 3 years ago

1. Find file bills.js in /public/js/purchases
2. Copy it to /public/js/sales
3. Find invoices.js in /public/js/sales and rename it to invoices_original.js (so you have a backup)
4. Rename bills.js to invoices.js in /public/js/sales

Worked for me!

Zrwstcom   ( User )

Commented 3 years ago

Forget what i posted before. That was dumb and it worked by mistake only once.

I found another solution. Hope it is correct. (Hey it works at least)
1. Download https://we.tl/t-ENDmaFWq9w
2. Replace your original invoices.js file in /public/js/sales with the one I provided
3. You can also download bills.js as most likely there is the same issue https://we.tl/t-TgqPZ4Hh1r
re (replace in public/js/purchases)

P.S. If someone is afraid that I've added some malicous code to both files you can DIY

Unminify original invoices.js and bills.js with https://unminify.com

Download the unminified versions of files

In invoices.js
search for 2 occurances of
e.sale_price.toFixed(2)
and change it to
parseFloat(e.sale_price).toFixed(2)

In bills.js
search for 2 occurances of
e.purchase_price.toFixed(2)
and change it to
parseFloat(e.purchase_price).toFixed(2)

Omar Only   ( User )

Commented 3 years ago

I have the same issue.

Delonbest   ( User )

Commented 1 year ago

It seems like toFixed() is a better solution, but it is not! In some cases it will NOT round correctly. Also, Math.round() will NOT round correctly in some cases.

To correct the rounding problem with the previous Math.round() and toFixed(), you can define a custom JavaScript rounding function that performs a "nearly equal" test to determine whether a fractional value is sufficiently close to a midpoint value to be subject to midpoint rounding. The following function return the value of the given number rounded to the nearest integer accurately.

Number.prototype.roundTo = function(decimal) {
return +(Math.round(this + "e+" + decimal) + "e-" + decimal);
}

var num = 9.7654;
console.log( num.roundTo(2)); //output 9.77

http://net-informations.com/js/progs/round.htm

Please login or register to leave a response.

Showing 1 to 5 of 5 discussions