SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto generate did not work

    Hi..

    I have code for auto generate but I got encountered problem that the SR number did not generate they still 120330001 even though I already save that SR number in my database.

    I want to happen is after I click the save button the SR number will be 120330002.

    here is my code:

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
     $sql = "SELECT sr_number FROM receiving_materials 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_num'],0,3));
                
                $currentSRYear  = (int)(substr($row['sr_num'],2,2));
                $currentSRMonth = (int)(substr($row['sr_num'],0,2));
                
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
                
                
                if ($currentYear == $currentSRYear) {
                    if ($currentMonth == $currentSRMonth) {
                        $currentSRNum = $currentSRNum + 1;
                    }
                    if ($currentMonth > $currentSRMonth) {
                        $currentSRNum = 1;
                    }
                    if ($currentDay > $currentSRDay) {
                        $currentSRNum = 1;
                    }
                }  
                if ($currentYear > $currentRefYear) {      
                    $currentSRNum = 1;                    
                }                                          
            }
    //------------------------------------------------------------------------------------------------------------------         
            $yearMonth = date('ymd');    
            $currentSR = $yearMonth . sprintf("%04d", $currentSRNum); 
            
            
    $sr_date = $_GET['sr_date'];
    $sr_number = $_GET['sr_number'];
    $si_num = $_GET['si_num'];
    $s_name = $_GET['s_name'];
    $po_num = $_GET['po_num'];
    $qty = $_GET['qty'];
    $mat_code = $_GET['mat_code'];
    $mat_desc = $_GET['mat_desc'];
    $wh_code = $_GET['wh_code'];
    $bin_loc = $_GET['bin_loc'];        
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    <style type="text/css">
    #ddcolortabs{
    margin-left: 2px;
    padding: 0;
    width: 100%;
    background: transparent;
    voice-family: "\"}\"";
    voice-family: inherit;
    padding-left: 2px;
    }
    
    #ddcolortabs ul{
    font: bold 12px Arial, Verdana, sans-serif;
    margin:0;
    padding:0;
    list-style:none;
    }
    
    #ddcolortabs li{
    display:inline;
    margin:0 2px 0 0;
    padding:0;
    text-transform:uppercase;
    }
    
    
    #ddcolortabs a{
    float:left;
    color: white;
    background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top;
    margin:2px 2px 0 0;
    padding:0px 0 1px 3px;
    text-decoration:none;
    letter-spacing: 1px;
    }
    
    #ddcolortabs a span{
    float:right;
    display:block;
    /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/
    padding:6px 9px 2px 6px;
    }
    
    #ddcolortabs a span{
    float:none;
    }
    
    
    #ddcolortabs a:hover{
    background-color: #678b3f;
    }
    
    #ddcolortabs a:hover span{
    background-color: #678b3f ;
    }
    
    #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/
    background-color: #678b3f;
    }
    </style>
    <style>
    #SR_date{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
        
    }
    #SR_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 410px;
        top : 10px;
        
    }
    table {          
        margin: 10px;
        font-family: Arial, Helvetica, sans-serif;  
        font-size: .9em;
        border: 1px solid #DDD;
    }
    
    th {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        background: #694;
        color: #FFF;
        padding: 2px 6px;
        border-collapse: separate;
        border: 1px solid #000; 
    }    
    
    td {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        border: 1px solid #DDD;
        text-align: left;
    }
    
    #RequestedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    } 
    
    #ApprovedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #ReceivedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #SI_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 20px;
        
    }
    .LLabelRM {
    display: block;
    float: left;
    width: 7em;
    margin-right: 10px;
    }
    
    .LLabelSecRM {
    display: block;
    float: left;
    width: 7.7em;
    margin-left : 0px;
    }
    
    .LFieldRM {
    float: left;
    margin-right: 595px;   
    }
    
    .LFieldSecRM {
    float: left;
    margin-right: 15px;   
    }
    .LFieldSec1RM {
    float: left;
    margin-right: 350px;   
    }
    #save_btn {
        position: relative;
        top: 25px;
        margin-left: 7px;
    }
    
    </style>
    
    <script type="text/javascript">
    function save_rm(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var si_num = document.getElementById("si_num").value;
        var s_name = document.getElementById("s_name").value;
        var po_num = document.getElementById("po_num").value;
        var qty = document.getElementById("qty").value;
        var mat_code = document.getElementById("mat_code").value;
        var mat_desc = document.getElementById("mat_desc").value;
        var wh_code = document.getElementById("wh_code").value;
        var bin_loc = document.getElementById("bin_loc").value;
    
        document.receiving_form.action="ReceivingMaterialsSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&si_num="+si_num+
        "&s_name="+s_name+"&po_num="+po_num+"&qty="+qty+"&mat_code="+mat_code+"&mat_desc="+mat_desc+"&wh_code="+wh_code+
        "&bin_loc="+bin_loc;
        document.receiving_form.submit();
    }
    </script>
    </head>
    <body>
    <form name="receiving_form">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li id="current"><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    </ul>
    </div>
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>RM# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="9" readonly="readonly" style="font-weight: bold; border: none;"> 
    </div> 
    <div id="SI_number">
     <label class="LLabelRM">SI/DR# :</label>
    <input type="text" name="si_num" id="si_num" class="LFieldRM" value="" size="25">
    <label class="LLabelRM">Supplier Name :</label>
    <input type="text" name="s_name" id="s_name" class="LFieldRM" value="" size="25">
    <label class="LLabelSecRM">PO # :</label>
    <input type="text" name="po_num" id="po_num" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Quantity :</label>
    <input type="text" name="qty" id="qty" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">Material Code :</label>
    <input type="text" name="mat_code" id="mat_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Material Desc. :</label>
    <input type="text" name="mat_desc" id="mat_desc" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">WH Code :</label>
    <input type="text" name="wh_code" id="wh_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">BIN Location :</label>
    <input type="text" name="bin_loc" id="bin_loc" class="LFieldSec1RM" value="" size="25">
    </div> 
    <div id="save_btn">
    <input type="button" name="save" value="save" onclick="save_rm()">
    </div>
    </form>
    </body>
    </html>
    
    <?php
    
        $sql = "INSERT INTO receiving_materials
        (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc)
        VALUES
        ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc')
        ON DUPLICATE KEY UPDATE
        sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num',
        qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc'";
        $res_receiving = mysql_query($sql, $con) or die(mysql_error());
    ?>
    any help is highly appreciated.

    Thank you

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    What will you do when two people are inserting new data at the same time?
    It would be better to use an autoincremental column in your database. The number would have no meaning (no year, month, day) but that's how id numbers should be. They should identify a row of data, without having any extra meanings. You already have the date info in the sr_date column.

    Anyway, looking over your code quickly I found these two problems:
    PHP Code:
    $sql "SELECT sr_number FROM receiving_materials ORDER BY sr_date DESC LIMIT 1"
    If you want to get the highest sr_number, sort by sr_number DESC, not sr_date.
    PHP Code:
    if ($currentDay $currentSRDay) {
      
    $currentSRNum 1;

    You didn't define $currentSRDay in your code.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I revise my code:

    First my php file is ReceivingMaterials.php and it did file your code is work.

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    //$sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
    $sql = "SELECT sr_number FROM receiving_materials 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));
               // $currentSRYear = (int)substr($row['sr_num'],0,2);
               // $currentSRMonth = (int)substr($row['sr_num'],2,2);
               // $currentSRDay = (int)substr($row['sr_num'],4,2);
               // $currentSRNum = (int)substr($row['sr_num'],6,3);
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
                
                
                /*if ($currentYear == $currentSRYear) {
                    if ($currentMonth == $currentSRMonth) {
                        $currentSRNum = $currentSRNum + 1;
                    }
                    if ($currentMonth > $currentSRMonth) {
                        $currentSRNum = 1;
                    }
                    if ($currentDay > $currentSRDay) {
                        $currentSRNum = 1;
                    }
                } 
                  if ($currentYear > $currentRefYear) {      
                    $currentSRNum = 1;                    
                } 
                */
                $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);  
           // $currentSR = $yearMonth . sprintf("%04d", $currentSRNum); 
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    <style type="text/css">
    #ddcolortabs{
    margin-left: 2px;
    padding: 0;
    width: 100%;
    background: transparent;
    voice-family: "\"}\"";
    voice-family: inherit;
    padding-left: 2px;
    }
    
    #ddcolortabs ul{
    font: bold 12px Arial, Verdana, sans-serif;
    margin:0;
    padding:0;
    list-style:none;
    }
    
    #ddcolortabs li{
    display:inline;
    margin:0 2px 0 0;
    padding:0;
    text-transform:uppercase;
    }
    
    
    #ddcolortabs a{
    float:left;
    color: white;
    background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top;
    margin:2px 2px 0 0;
    padding:0px 0 1px 3px;
    text-decoration:none;
    letter-spacing: 1px;
    }
    
    #ddcolortabs a span{
    float:right;
    display:block;
    /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/
    padding:6px 9px 2px 6px;
    }
    
    #ddcolortabs a span{
    float:none;
    }
    
    
    #ddcolortabs a:hover{
    background-color: #678b3f;
    }
    
    #ddcolortabs a:hover span{
    background-color: #678b3f ;
    }
    
    #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/
    background-color: #678b3f;
    }
    </style>
    <style>
    #SR_date{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
        
    }
    #SR_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 410px;
        top : 10px;
        
    }
    table {          
        margin: 10px;
        font-family: Arial, Helvetica, sans-serif;  
        font-size: .9em;
        border: 1px solid #DDD;
    }
    
    th {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        background: #694;
        color: #FFF;
        padding: 2px 6px;
        border-collapse: separate;
        border: 1px solid #000; 
    }    
    
    td {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        border: 1px solid #DDD;
        text-align: left;
    }
    
    #RequestedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    } 
    
    #ApprovedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #ReceivedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #SI_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 20px;
        
    }
    .LLabelRM {
    display: block;
    float: left;
    width: 7em;
    margin-right: 10px;
    }
    
    .LLabelSecRM {
    display: block;
    float: left;
    width: 7.7em;
    margin-left : 0px;
    }
    
    .LFieldRM {
    float: left;
    margin-right: 595px;   
    }
    
    .LFieldSecRM {
    float: left;
    margin-right: 15px;   
    }
    .LFieldSec1RM {
    float: left;
    margin-right: 350px;   
    }
    #save_btn {
        position: relative;
        top: 25px;
        margin-left: 7px;
    }
    
    </style>
    
    <script type="text/javascript">
    function save_rm(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var si_num = document.getElementById("si_num").value;
        var s_name = document.getElementById("s_name").value;
        var po_num = document.getElementById("po_num").value;
        var qty = document.getElementById("qty").value;
        var mat_code = document.getElementById("mat_code").value;
        var mat_desc = document.getElementById("mat_desc").value;
        var wh_code = document.getElementById("wh_code").value;
        var bin_loc = document.getElementById("bin_loc").value;
    
        document.receiving_form.action="ReceivingMaterialsSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&si_num="+si_num+
        "&s_name="+s_name+"&po_num="+po_num+"&qty="+qty+"&mat_code="+mat_code+"&mat_desc="+mat_desc+"&wh_code="+wh_code+
        "&bin_loc="+bin_loc;
        document.receiving_form.submit();
    }
    </script>
    </head>
    <body>
    <form name="receiving_form">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li id="current"><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    </ul>
    </div>
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>RM# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="9" readonly="readonly" style="font-weight: bold; border: none;"> 
    </div> 
    <div id="SI_number">
     <label class="LLabelRM">SI/DR# :</label>
    <input type="text" name="si_num" id="si_num" class="LFieldRM" value="" size="25">
    <label class="LLabelRM">Supplier Name :</label>
    <input type="text" name="s_name" id="s_name" class="LFieldRM" value="" size="25">
    <label class="LLabelSecRM">PO # :</label>
    <input type="text" name="po_num" id="po_num" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Quantity :</label>
    <input type="text" name="qty" id="qty" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">Material Code :</label>
    <input type="text" name="mat_code" id="mat_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Material Desc. :</label>
    <input type="text" name="mat_desc" id="mat_desc" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">WH Code :</label>
    <input type="text" name="wh_code" id="wh_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">BIN Location :</label>
    <input type="text" name="bin_loc" id="bin_loc" class="LFieldSec1RM" value="" size="25">
    </div> 
    <div id="save_btn">
    <input type="button" name="save" value="save" onclick="save_rm()">
    </div>
    </form>
    </body>
    </html>
    and after I click save button:

    it will go to ReceivingMaterialsSave.php

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    $sr_date =date('Y-m-d H:i:s');
    
    //$sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1";
     $sql = "SELECT sr_number FROM receiving_materials 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));
               // $currentSRYear = (int)substr($row['sr_num'],0,2);
               // $currentSRMonth = (int)substr($row['sr_num'],2,2);
               // $currentSRDay = (int)substr($row['sr_num'],4,2);
               // $currentSRNum = (int)substr($row['sr_num'],6,3);
                $currentYear  = (int)(date('y'));
                $currentMonth = (int)(date('m'));
                $currentDay = (int)(date('d'));
                
                
                /*if ($currentYear == $currentSRYear) {
                    if ($currentMonth == $currentSRMonth) {
                        $currentSRNum = $currentSRNum + 1;
                    }
                    if ($currentMonth > $currentSRMonth) {
                        $currentSRNum = 1;
                    }
                    if ($currentDay > $currentSRDay) {
                        $currentSRNum = 1;
                    }
                } 
                  if ($currentYear > $currentRefYear) {      
                    $currentSRNum = 1;                    
                } 
                */
                $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);  
           // $currentSR = $yearMonth . sprintf("%04d", $currentSRNum); 
            
            
    $sr_date = $_GET['sr_date'];
    $sr_number = $_GET['sr_number'];
    $si_num = $_GET['si_num'];
    $s_name = $_GET['s_name'];
    $po_num = $_GET['po_num'];
    $qty = $_GET['qty'];
    $mat_code = $_GET['mat_code'];
    $mat_desc = $_GET['mat_desc'];
    $wh_code = $_GET['wh_code'];
    $bin_loc = $_GET['bin_loc'];        
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    <style type="text/css">
    #ddcolortabs{
    margin-left: 2px;
    padding: 0;
    width: 100%;
    background: transparent;
    voice-family: "\"}\"";
    voice-family: inherit;
    padding-left: 2px;
    }
    
    #ddcolortabs ul{
    font: bold 12px Arial, Verdana, sans-serif;
    margin:0;
    padding:0;
    list-style:none;
    }
    
    #ddcolortabs li{
    display:inline;
    margin:0 2px 0 0;
    padding:0;
    text-transform:uppercase;
    }
    
    
    #ddcolortabs a{
    float:left;
    color: white;
    background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top;
    margin:2px 2px 0 0;
    padding:0px 0 1px 3px;
    text-decoration:none;
    letter-spacing: 1px;
    }
    
    #ddcolortabs a span{
    float:right;
    display:block;
    /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/
    padding:6px 9px 2px 6px;
    }
    
    #ddcolortabs a span{
    float:none;
    }
    
    
    #ddcolortabs a:hover{
    background-color: #678b3f;
    }
    
    #ddcolortabs a:hover span{
    background-color: #678b3f ;
    }
    
    #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/
    background-color: #678b3f;
    }
    </style>
    <style>
    #SR_date{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
        
    }
    #SR_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 410px;
        top : 10px;
        
    }
    table {          
        margin: 10px;
        font-family: Arial, Helvetica, sans-serif;  
        font-size: .9em;
        border: 1px solid #DDD;
    }
    
    th {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        background: #694;
        color: #FFF;
        padding: 2px 6px;
        border-collapse: separate;
        border: 1px solid #000; 
    }    
    
    td {
        font-family: Arial, Helvetica, sans-serif;
        font-size: .7em;
        border: 1px solid #DDD;
        text-align: left;
    }
    
    #RequestedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    } 
    
    #ApprovedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #ReceivedBy{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .8em;
        margin-left: 15px;
        width: auto;
        height: auto;
        float: left;
        top : 10px;
    }
    
    #SI_number{
        position: relative;
        font-family: Arial, Helvetica, sans-serif;
        font-size: .9em;
        margin-left: 10px;
        width: auto;
        height: auto;
        float: left;
        top : 20px;
        
    }
    .LLabelRM {
    display: block;
    float: left;
    width: 7em;
    margin-right: 10px;
    }
    
    .LLabelSecRM {
    display: block;
    float: left;
    width: 7.7em;
    margin-left : 0px;
    }
    
    .LFieldRM {
    float: left;
    margin-right: 595px;   
    }
    
    .LFieldSecRM {
    float: left;
    margin-right: 15px;   
    }
    .LFieldSec1RM {
    float: left;
    margin-right: 350px;   
    }
    #save_btn {
        position: relative;
        top: 25px;
        margin-left: 7px;
    }
    
    </style>
    
    <script type="text/javascript">
    function save_rm(){
        var sr_date = document.getElementById("sr_date").value;
        var sr_number = document.getElementById("sr_number").value;
        var si_num = document.getElementById("si_num").value;
        var s_name = document.getElementById("s_name").value;
        var po_num = document.getElementById("po_num").value;
        var qty = document.getElementById("qty").value;
        var mat_code = document.getElementById("mat_code").value;
        var mat_desc = document.getElementById("mat_desc").value;
        var wh_code = document.getElementById("wh_code").value;
        var bin_loc = document.getElementById("bin_loc").value;
    
        document.receiving_form.action="ReceivingMaterialsSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&si_num="+si_num+
        "&s_name="+s_name+"&po_num="+po_num+"&qty="+qty+"&mat_code="+mat_code+"&mat_desc="+mat_desc+"&wh_code="+wh_code+
        "&bin_loc="+bin_loc;
        document.receiving_form.submit();
    }
    </script>
    </head>
    <body>
    <form name="receiving_form">
    <div id="ddcolortabs">
    <ul>
    <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li>
    <li id="current"><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li>
    <li><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li>
    <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li>
    </ul>
    </div>
    <div id="SR_date">
    <label>Date :</label>
    <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;">    
    </div>
    <div id="SR_number">
    <label>RM# :</label>
    <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="9" readonly="readonly" style="font-weight: bold; border: none;"> 
    </div> 
    <div id="SI_number">
     <label class="LLabelRM">SI/DR# :</label>
    <input type="text" name="si_num" id="si_num" class="LFieldRM" value="" size="25">
    <label class="LLabelRM">Supplier Name :</label>
    <input type="text" name="s_name" id="s_name" class="LFieldRM" value="" size="25">
    <label class="LLabelSecRM">PO # :</label>
    <input type="text" name="po_num" id="po_num" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Quantity :</label>
    <input type="text" name="qty" id="qty" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">Material Code :</label>
    <input type="text" name="mat_code" id="mat_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">Material Desc. :</label>
    <input type="text" name="mat_desc" id="mat_desc" class="LFieldSec1RM" value="" size="25">
    <label class="LLabelSecRM">WH Code :</label>
    <input type="text" name="wh_code" id="wh_code" class="LFieldSecRM" value="" size="25">
    <label class="LLabelSecRM">BIN Location :</label>
    <input type="text" name="bin_loc" id="bin_loc" class="LFieldSec1RM" value="" size="25">
    </div> 
    <div id="save_btn">
    <input type="button" name="save" value="save" onclick="save_rm()">
    </div>
    </form>
    </body>
    </html>
    
    <?php
      /*  $sql = "INSERT INTO receiving_materials
        (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc)
        VALUES
        ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc')
        ON DUPLICATE KEY UPDATE
        sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num',
        qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc' 
        WHERE sr_number = '$sr_number' ORDER BY sr_number";    */
        
        $sql = "INSERT INTO receiving_materials
        (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc)
        VALUES
        ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc')
        ON DUPLICATE KEY UPDATE
        sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num',
        qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc'";
        $res_receiving = mysql_query($sql, $con) or die(mysql_error());    
    ?>
    After it save in database the SR Number still the SR Number that the previous save for example the previous SR number that I save is 1203300006
    Thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •