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?

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

Will ask Janusz to have a look.

/Joe

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

Yes, indeed, seems this was leaved unfinished in 2.4RC development. Fixed.

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

So now we will have it uniformly as 11.905 in both Sales Delivery and Sales Invoice!

A search for the string "FIXME" in the entire codebase will popup several files!

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

this seems to cuz the following error that prevent me from login

Parse error: syntax error, unexpected '$delivery' (T_VARIABLE) in /home/Accounting/public_html/Test/sales/includes/db/sales_delivery_db.inc on line 77

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

Typo  - missing comma - in commit.

Alter line 76 in the file sales/includes/db/sales_delivery_db.inc:

            $delivery_line->price*$qty, 0, $delivery->tax_included

to:

            $delivery_line->price*$qty, 0, $delivery->tax_included,

Also terminate line 80 with a semicolon.

@itronics: please commit it.
@Alaa: Nice catch.

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

@apmuthu  it works now but i have error message now
set_exception_handler() expects the argument (exception_handler) to be a valid callback in file: /home/accounting/public_html/test/includes/session.inc at line 375

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

There are 2 corrections in my post above.

The function exception_handler() is defined in includes/errors.inc file and is included in line 372 (before function usage) in includes/session.inc. So all are okay here.

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

here is how line 80 should look ?

$delivery_line->price * $qty, 0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price;

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

Yes.

@itronics: please commit fixes in post #6 here.

Re: debtor_trans_details entry for $unit_tax is different for SD and SI

@itronics: Please fix this commit as above.. Committed.

The function get_full_price_for_item() takes only 5 arguments but the usage in the said commit calls for a change from 6 to 7 arguments now!

FA remains broken till this is fixed.