Topic: Auto Item Code

It would be helpful to be able to allow FA to auto increment the item code when adding new items. 

I am switching from an accounting system that auto populated the item code. 

Researching the forum showed that the issue was raised in 2017 but I cannot find any further reference.

Regards, Frank Carll

Re: Auto Item Code

How to set the header on the Sales Invoice because its alingnment is out from the top of the page. Please guide possible with the images or steps so i can adjust it accordingly.

Re: Auto Item Code

fcarll wrote:

It would be helpful to be able to allow FA to auto increment the item code when adding new items. 

I am switching from an accounting system that auto populated the item code. 

Researching the forum showed that the issue was raised in 2017 but I cannot find any further reference.

Regards, Frank Carll

Hope the core doesn't have this feature. You need to create constant in types.in and use it inside the sysnames.inc and update it on transactions_db.inc. after that you can see the item in transaction references.

Create one there with your desired format and customize the items.php and get next reference will help you to make it auto increment on item codes.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Auto Item Code

cowlas wrote:

How to set the header on the Sales Invoice because its alingnment is out from the top of the page. Please guide possible with the images or steps so i can adjust it accordingly.

How are you cowlas?

This is actually not clear. Are you looking view_invoice.php

Or rep107.php header2.inc and doctext.inc

Hope you have the dual header options that we  done last time.

Subscription service based on FA
HRM CRM POS batch Themes

Re: Auto Item Code

Kvvaradha describes the generalized approach (making item code a reference, thus reusing existing code).  This would be a great addition to the base, and assuming your part numbers are numeric, would be easy to implement, using the {1} definition.  If they are not strictly numeric, you would have to add the meta code to handle those fields.

The quick and dirty approach is what I did in my fork.  This hard codes an assumption of how item codes are formatted, and may need to changed depending on how your item codes are formatted.  In my case, they have an alpha prefix and a numeric suffix.

inventory/manage/items.php

function item_settings(&$stock_id, $new_item)
{
...
if ($new_item)
    {
        $tmpCodeID=next_stock_id();
...

function numeric_offset($text) {
    preg_match('/\d/', $text, $m, PREG_OFFSET_CAPTURE);
    if (sizeof($m))
        return $m[0][1];

    // the case when there's no numbers in the string
    return strlen($text);
}

/*
    This function returns the next unused stock_id in stock_master.
    To work correctly, stock_ids should be numeric or end in a numeric.
*/
function next_stock_id() {
    $sql = "SELECT max(stock_id) as max FROM ".TB_PREF."stock_master";
    $result = db_query($sql, "Can not find max stock_id");
    $row = db_fetch_row($result);
    if (!$row[0]) return null;
    $offset= numeric_offset($row[0]);
    $num=substr($row[0], $offset);
    if (!is_numeric($num))
    return null;
    $num += 1;
    return substr($row[0], 0, $offset) . $num;
}