Topic: Bug Found in Invoice Creation

I have been facing this issue quite a long but couldn't find the reason becuase this is not happening always but only once in 1000 attempts may be.

While Creating Invoice From Delivery Notes a function write_customer_trans_detail_item is called from customer_invoice.php with following backtrace and function arguments

Function Arguments
(
    [0] => 10
    [1] => 916
    [2] => 10036
    [3] => 50/3 Polyester Color SKY 2500
    [4] => 88
    [5] => 139
    [6] => 0
    [7] => 0
    [8] => 62.160883841992
    [9] => 9783
    [10] => 9783
)
/home/sites/22a/e/eeb3fd1d98/public_html/boxyerp/sales/includes/db/sales_invoice_db.inc:122: write_customer_trans_detail_item('10','916','10036','50/3 Polyester Color SKY 2500','88','139','0','0','62.160883841992','9783','9783')

/home/sites/22a/e/eeb3fd1d98/public_html/boxyerp/sales/includes/cart_class.inc:343: write_sales_invoice((Cart Object))

/home/sites/22a/e/eeb3fd1d98/public_html/boxyerp/sales/customer_invoice.php:396: (Cart Object)->write()</td

I have just added following lines in the beginning of function to alert the user

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)
{
    if ($debtor_trans_type == ST_SALESINVOICE && $src_id == $line_id){
        display_error ("High Alert. Bug Found in Invoice Creation. Please Try Again");
        exit();
    }

Here $line_id was supposed to be Zero but it was same as $src_id and that is creating a big database anomaly.

Still trying to investigate why this happens.
Just sharing here if anyone else facing same issue.

Regards.

www.boxygen.pk