T
The Natural Philosopher
I have this routine that is called when a salesperson over rides a
selling price.
It has two problems. One is that rounding errors occasionally meana it
rounds the value down a penny when it should not. That I can fix.
The second is that sometimes, for no discernible reason, it blows up
spectacularly and sets line totals that are monstrous and often negative.
I cannot reliably reproduce this, so I am appealing for someone to look
through this not very good code, and indicate where a possible problem
might arise.
function price_override(id)
{
document.getElementsByName('line_discount_'+id)[0].value='0';
document.getElementById('discount_'+id).innerHTML='0.00';
document.getElementsByName('discount')[0].value='0';
var oldtotal=Math.round((document.getElementById('total_'+id).innerHTML)
*100)/100;
var newtotal=Math.round((document.getElementById('qty_'+id).innerHTML *
document.getElementsByName('sale_price_'+id)[0].value)*100)/100;
document.getElementById('total_'+id).innerHTML=newtotal;
var grandtotal=
Math.round((document.getElementsByName('grand_total')[0].value)*100)/100;
grandtotal=grandtotal+(newtotal-oldtotal);
document.getElementsByName('grand_total')[0].value=grandtotal;
document.getElementsByName('order_total')[0].value+=(newtotal-oldtotal);
do_discount(); // this just does other irrelavant stuff and calculstes
order total magins and discounts.
}
selling price.
It has two problems. One is that rounding errors occasionally meana it
rounds the value down a penny when it should not. That I can fix.
The second is that sometimes, for no discernible reason, it blows up
spectacularly and sets line totals that are monstrous and often negative.
I cannot reliably reproduce this, so I am appealing for someone to look
through this not very good code, and indicate where a possible problem
might arise.
function price_override(id)
{
document.getElementsByName('line_discount_'+id)[0].value='0';
document.getElementById('discount_'+id).innerHTML='0.00';
document.getElementsByName('discount')[0].value='0';
var oldtotal=Math.round((document.getElementById('total_'+id).innerHTML)
*100)/100;
var newtotal=Math.round((document.getElementById('qty_'+id).innerHTML *
document.getElementsByName('sale_price_'+id)[0].value)*100)/100;
document.getElementById('total_'+id).innerHTML=newtotal;
var grandtotal=
Math.round((document.getElementsByName('grand_total')[0].value)*100)/100;
grandtotal=grandtotal+(newtotal-oldtotal);
document.getElementsByName('grand_total')[0].value=grandtotal;
document.getElementsByName('order_total')[0].value+=(newtotal-oldtotal);
do_discount(); // this just does other irrelavant stuff and calculstes
order total magins and discounts.
}