Topic: debtor_trans_details entry for $unit_tax is different for SD and SI
The function write_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost, $src_id, $line_id=0) is defined in sales/includes/db/cust_trans_details_db.inc.
When creating the Sales Delivery, the working lines 71-88 of sales/includes/db/sales_delivery_db.inc are:
foreach ($delivery->line_items as $line_no => $delivery_line) {
$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->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;
$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->discount_percent, $delivery_line->standard_cost, $delivery_line->src_id,
$trans_no ? $delivery_line->id : 0);
When creating the Sales Invoice, the corresponding working lines 105-119 of sales/includes/db/sales_invoice_db.inc are:
foreach ($invoice->line_items as $line_no => $invoice_line) {
$qty = $invoice_line->qty_dispatched;
$line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
$invoice_line->price * $qty, 0, $invoice->tax_included,
$invoice->tax_group_array);
$line_tax = get_full_price_for_item($invoice_line->stock_id,
$invoice_line->price * $qty, 0, $invoice->tax_included,
$invoice->tax_group_array) - $line_taxfree_price;
write_customer_trans_detail_item(ST_SALESINVOICE, $invoice_no, $invoice_line->stock_id,
$invoice_line->item_description, $invoice_line->qty_dispatched,
$invoice_line->line_price(), $qty ? $line_tax/$qty : 0, $invoice_line->discount_percent,
$invoice_line->standard_cost, $invoice_line->src_id,
$trans_no ? $invoice_line->id : 0);
Observe that the former is just a number whilst the latter is the result of a division by quantity if it exists. The latter results in some rounding off errors. Can the invoice not just be the unit tax as in the sales order? The element in question is in the 7th parameter in the call to the function write_customer_trans_detail_item() in each case.
The sql for the sales order is:
INSERT INTO `1_debtor_trans_details` VALUES
('13', '5', '13', '102', 'iPhone 6 64GB', '250', '11.9', '2', '0', '150', '2', '11'),
whilst that for the sales invoice is:
INSERT INTO `1_debtor_trans_details` VALUES
('15', '5', '10', '102', 'iPhone 6 64GB', '250', '11.905', '2', '0', '150', '0', '13'),
Note the difference:11.9 and 11.905 for unit_tax.
@joe: does this need fixing?