PDA

View Full Version : auto generate did not work



newphpbees
30 Mar 2012, 01:27 AM
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:



<?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

shophere2012
30 Mar 2012, 03:19 AM
Nowadys, more and more ladies would choose flat irons to do their hair style at home.



Healthy Hair Essential: An Ionic Blow-Dryer

Nothing makes hair feel like straw more quickly than the blast of heat from a blow-dryer. A good ionic one emits charged particles that can cut drying time in half and encourage the cuticle to lie flat. We like the T3 Tourmaline Professional Featherweight Ceramic Ionic Hair Dryer.

Healthy Hair Essential: A Silicone-Emitting Flatiron
Most flatirons leave hair feeling silky, but that comes at a price: The heat can crack hair’s cuticle. But the Remington Style Therapy Frizz Therapy flatiron is actually good for hair. Its plates have a porous ceramic coating that emits a silicone-based conditioner that has been shown to eliminate frizz more effectively than a traditional ceramic iron.

www.flatironssale.us