Topic: Sales Invoices and Credit Notes united reference counting

I want to unite the references of Sales Invoices and Credit Notes.

Example: Invoice 1, Invoice 2, Credit Note 3, Invoice 4, Credit Note 5....

I can manually put the needed number, but that's not the point.
What must I do?

Re: Sales Invoices and Credit Notes united reference counting

No standard fix. Hack the Credit Note script and alter the way the new reference is generated to take it as the next one from the invoices series and then use that in the Credit Note set.

3 (edited by kvvaradha 10/06/2017 01:30:58 pm)

Re: Sales Invoices and Credit Notes united reference counting

That's only way, you need to edit the code of reference and put it as of your needs. Me too changed it like this. i mean the reference functions to create custom reference prefix

Subscription service based on FA
HRM CRM POS batch Themes

Re: Sales Invoices and Credit Notes united reference counting

I gave no feedback, but changing a little the function _parse_next works fine...

Re: Sales Invoices and Credit Notes united reference counting

@stefan: would you like to submit the function changes?

Re: Sales Invoices and Credit Notes united reference counting

Here it is, it works on the identical reflines for Sales Invoices and Credit Notes.
Maybe it's too simple, but that's what I needed and I'm happy with it.

CAUTION - I haven't made data checks as I use alone this system.
For the moment it is not impossible to manually create Sales Invoice and Credit Note with same numbers.
I mean if you change the displayed reference number...

Also note, here it is with mb_strlen

This is the changed part in _parse_next function:

                $prefix = $match[1];
        $postfix = $match[3];

        $db_info = get_systype_db_info($type);
        $trans_table = $db_info[0];
        $type_fld = $db_info[1];
        $tno_fld = $db_info[2];
        $ref_fld = $db_info[3];
        $type_sec = '';                                   // change starts here
       
        if($type== ST_CUSTCREDIT || $type== ST_SALESINVOICE)   
        {
        $type_sec = '10,11';                        // don't laugh, it works fine smile
        }
        else
        {
        $type_sec= $type;
        }

        // retrieve last ref number in the refline from original transaction table
        $sql = "SELECT MAX(CAST(SUBSTR($ref_fld, ".(mb_strlen($prefix)+1).",LENGTH($ref_fld)-".(mb_strlen($postfix)+mb_strlen($prefix)).") AS UNSIGNED))"
                ." FROM `$trans_table` tbl
                    LEFT JOIN ".TB_PREF."voided v ON tbl.`$tno_fld`=v.id AND v.type in ($type_sec)"
                ." WHERE ISNULL(v.id)"
                .($type_fld ? " AND tbl.`$type_fld`in ($type_sec)" : '')
                ." AND `$ref_fld` REGEXP ".db_escape('^'.preg_quote($prefix).'[0-9]*'.preg_quote($postfix).'$');
        $result = db_query($sql, 'cannot retrieve last reference');
        $result = db_fetch_row($result);