Recently, came across an issue with the customer where they were getting an error as below everytime generating an invoice for the sales orders. { Division by zero. - (S)\Classes\SalesInvoiceDP\insertIntoSalesInvoiceTmp - line 123 }
I discovered there was an unhandled exception in the line of code for \classes\SalesInvoiceDP\insertIntoSalesInvoiceTmp method on a certain line of code as below
Line 122 of the method states
I discovered there was an unhandled exception in the line of code for \classes\SalesInvoiceDP\insertIntoSalesInvoiceTmp method on a certain line of code as below
Line 122 of the method states
salesInvoiceTmp.SalesPrice = _custInvoiceTrans.SalesPrice / (_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount;
Changing that line of code to below resolves the issue
// changes made to avoid division by zero error.
if((_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount == 0)
salesInvoiceTmp.SalesPrice = 0 ;
else
salesInvoiceTmp.SalesPrice = _custInvoiceTrans.SalesPrice / (_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount;
if((_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount == 0)
salesInvoiceTmp.SalesPrice = 0 ;
else
salesInvoiceTmp.SalesPrice = _custInvoiceTrans.SalesPrice / (_custInvoiceTrans.LineAmount +_custInvoiceTrans.LineAmountTax) * _custInvoiceTrans.LineAmount;