Fixed rounding differences in sales delivery and invoice.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 16 Nov 2017 18:56:08 +0000 (19:56 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 16 Nov 2017 18:56:57 +0000 (19:56 +0100)
sales/includes/db/sales_delivery_db.inc

index 8276eb5113d335a30e46aa0c9d61cbb51fd2c7f5..15b4736d90e49c34a77a611686c6055dea60e22f 100644 (file)
@@ -70,20 +70,21 @@ function write_sales_delivery(&$delivery,$bo_policy)
        }
        foreach ($delivery->line_items as $line_no => $delivery_line) {
 
+               $qty = $delivery_line->qty_dispatched;
                $line_price = $delivery_line->line_price();
                $line_taxfree_price = get_tax_free_price_for_item($delivery_line->stock_id,
-                       $delivery_line->price, 0, $delivery->tax_included,
+                       $delivery_line->price*$qty, 0, $delivery->tax_included
                        $delivery->tax_group_array);
 
-               $line_tax = get_full_price_for_item($delivery_line->stock_id, $delivery_line->price,
-                       0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price;
+               $line_tax = get_full_price_for_item(ST_CUSTDELIVERY, $delivery_line->stock_id,
+                               $delivery_line->price * $qty, 0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price
 
                $delivery_line->standard_cost = get_unit_cost($delivery_line->stock_id);
 
                /* add delivery details for all lines */
                write_customer_trans_detail_item(ST_CUSTDELIVERY, $delivery_no, $delivery_line->stock_id,
                        $delivery_line->item_description, $delivery_line->qty_dispatched,
-                       $delivery_line->line_price(), $line_tax,
+                       $delivery_line->line_price(), $qty ? $line_tax/$qty : 0,
                        $delivery_line->discount_percent, $delivery_line->standard_cost, $delivery_line->src_id,
                        $trans_no ? $delivery_line->id : 0);
 
@@ -119,8 +120,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                                $sales_account = ($branch_data['sales_account'] != "" ? $branch_data['sales_account'] : $stock_gl_code['sales_account']);
 
                                $total += add_gl_trans_customer(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, $sales_account, $dim, $dim2,
-                                       -$line_taxfree_price*$delivery_line->qty_dispatched, // FIXME - calculation order should be exactly like in invoice to minimalize roundings
-                                       $delivery->customer_id, "The sales price GL posting could not be inserted");
+                                       -$line_taxfree_price, $delivery->customer_id, "The sales price GL posting could not be inserted");
                        }
                        /* insert gl_trans to credit stock and debit cost of sales at standard cost*/