Topic: Invoice not converting from DN due to float bug

While converting the delivery note to the invoice the system is showing the following error:

Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet.

To re-produce
1 i created an SO and DN of 28 pieces.
2. Invoiced 19.60 pcs
3. and now while invoicing the remaining 8.40 pcs i get the above error.

I have checked the above in FA's latest build as well.

While investigating i found that in the following function in data_checks.inc, the $num>$max is going true. please note that both $num and $max are both 8.4, and $num can not be greater than $max.

But if i subtract $num-$max it gives me 1.7763568394003E-15(which should be zero). I googled it and found out that this is due to the shortcoming of floating point arithmetic.

Reference Function
function check_num($postname, $min=null, $max=null, $dflt=0) {
    if(!isset($_POST[$postname]))
      return 0;
    $num = input_num($postname, $dflt);
    if ($num === false || $num === null)
      return 0;
    if (isset($min) && ($num<$min))
      return 0;
    if (isset($max) && ($num>$max))
      return 0;
    return 1;
}

Should i add a rounding value like 0.00001 in $num for comparing it with $min and $max?

Kindly advise.

Re: Invoice not converting from DN due to float bug

@joe Kindly advise

Re: Invoice not converting from DN due to float bug

Hello @dz.
Yes I will be glad to assist, had I have a clue about this. We are working otherwise with a DELTA value in current_user.inc (about line 540), can this be used?
Does any expert on this have a good solution?

Joe

Re: Invoice not converting from DN due to float bug

ok Thanks joe, let me check that smile

Re: Invoice not converting from DN due to float bug

Hello again,

I found the problem. It was not inside function check_num, but from function check_quantities in customer_invoice.php and customer_delivery.php.
Inside these functions the $max value was calculated and due to a floating bug in PHP got a very small overlay.
This has been fixed in these two functions, check_quantities.

/sales/customer_delivery.php can be downloaded here.
/sales/customer_invoice.php can be downloaded here.

Joe

Re: Invoice not converting from DN due to float bug

ok great !
let me check, thanks again smile