Auto generate stock number

Hi…

I started designing stock form.

and I need to display automatically the stock number, the format is:yymmddxxx for example : 120323001

I need to display that stock number in my textbox when I first visit in my form…

Thank you so much…

Look at the options on [fphp]date/fphp.

where are you storing the fact that the last one was say, 120323001 and the next should be 120323002?

Hi…

I’ve notice in my code for autogenerate sr number, when no data was save in the database the sr number became 0001 the date did not display.


$sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
        $result = mysql_query($sql, $con);

        if (!$result) {
            echo 'failed';
            die();
        }
        $total = mysql_num_rows($result);
        if ($total <= 0) {
            $currentSRNum = 1;

        }
        else {
//------------------------------------------------------------------------------------------------------------------
            // Stock Number iteration....
            $row = mysql_fetch_assoc($result);

            $currentSRNum = (int)(substr($row['sr_number'],0,3));

            $currentSRYear  = (int)(substr($row['sr_number'],2,2));
            $currentSRMonth = (int)(substr($row['sr_number'],0,2));
            $currentSRNum = (int)(substr($row['sr_number'],6,4));
            $currentYear  = (int)(date('y'));
            $currentMonth = (int)(date('m'));
            $currentDay = (int)(date('d'));

            $currentSRYMD = substr($row['sr_number'], 0, 6);
            $currentYMD = date("ymd");
            if ($currentYMD > $currentSRYMD)
            {
                $currentSRNum = 1;
            }
            else
            {
                $currentSRNum += 1;
            }
        }
//------------------------------------------------------------------------------------------------------------------
        $yearMonth = date('ymd');
        $currentSR = $currentYMD . sprintf("%04d", $currentSRNum);

it works perfectly if theirs an sr number was already save in my database.

Thank you