Topic: Error working with Sales Quotation

I tried to Cancel/Void a Sales Quotation and received a big red box with the following error:

DATABASE ERROR : Cannot add audit info
error code : 1366
error message : Incorrect integer value: '' for column 'trans_no' at row 1
sql that failed was : INSERT INTO 9_audit_trail (type, trans_no, user, fiscal_year, gl_date, description, gl_seq) VALUES('32', '',2,7,'2014-04-03','Deleted.', 0)


Any help would be appreciated!!

Version 2.3.19

Re: Error working with Sales Quotation

I just wonder how this is possible. The Sales Quotation must at leat have a number of 1.

Can you please add some information to this?

/Joe

Re: Error working with Sales Quotation

This has something to do with $order_no being absent in one of the three calls to the add-audit_trail() function in sales/includes/db/sales_order_db.inc

Re: Error working with Sales Quotation

I cannot reproduce this error.

The error is thrown in the file /sales/includes/db/sales_order_db.inc

function delete_sales_order($order_no, $trans_type)
{
    begin_transaction();
    hook_db_prevoid($trans_type, $order_no);

    $sql = "DELETE FROM ".TB_PREF."sales_orders WHERE order_no=" . db_escape($order_no) 
        . " AND trans_type=".db_escape($trans_type);

    db_query($sql, "order Header Delete");

    $sql = "DELETE FROM ".TB_PREF."sales_order_details WHERE order_no =" 
        .db_escape($order_no) . " AND trans_type=".db_escape($trans_type);
    db_query($sql, "order Detail Delete");

    delete_reference($trans_type, $order_no);

    add_audit_trail($trans_type, $order_no, Today(), _("Deleted."));
    commit_transaction();
}

If the $order_no is empty, the error should have been trown in one of the prior database calls.

The file /includes/db/audit_trail_db.inc shows the

function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
{
    $sql = "INSERT INTO ".TB_PREF."audit_trail"
        . " (type, trans_no, user, fiscal_year, gl_date, description, gl_seq)
            VALUES(".db_escape($trans_type).", ".db_escape($trans_no).","
            . $_SESSION["wa_current_user"]->user. ","
            . get_company_pref('f_year') .","
            . "'". date2sql($trans_date) ."',"
            . db_escape($descr). ", 0)";

    db_query($sql, "Cannot add audit info");
    
    // all audit records beside latest one should have gl_seq set to NULL
    // to avoid need for subqueries (not existing in MySQL 3) all over the code
    $sql = "UPDATE ".TB_PREF."audit_trail SET gl_seq = NULL"
        . " WHERE type=".db_escape($trans_type)." AND trans_no="
        .db_escape($trans_no)." AND id!=".db_insert_id();

    db_query($sql, "Cannot update audit gl_seq");
}

The sql sentence INSERT INTO ... throws the empty result. This is strange

Please can somebody help me to track this, if possible?

/Joe

Re: Error working with Sales Quotation

I can reproduce this error at will by going to Sales Quotation then hitting Cancel, but if I just hit back it exits out with no problem.

Re: Error working with Sales Quotation

Ah, now I understand what is going on.

Your version of MySql has detected a bug. When a quotation is not yet saved (not completed), FA should not try to delete the quotatin as well as update the audit trail when the quotation is not completed.

I will fix this later tonight. There are other forms needing to be fixEd as well.

In older versions of MySql it was no problems running these sql scripts.

/Joe

Re: Error working with Sales Quotation

This bug has now been fixed, and the HG repository will be updated in a while.

You can download the file /sales/sales_order_entry.php1. Rename it to sales_order_entry.php and replace the file in the /sales folder.

/Joe

ATTN.
If you downloaded the previous sales_order_entry.php1 file, then please re-download this one.
AN error in the confirm (cancel) was not performed correctly.

Post's attachments

sales_order_entry.php1 26.5 kb, 5 downloads since 2014-04-05 

You don't have the permssions to download the attachments of this post.

Re: Error working with Sales Quotation

Thanks for the quick fix Joe. Hope there are no more such instances of session dependencies.