|
|
|
รบกวนด้วยครับ ต้อง การ update แบบ วนลูปนะครับ |
|
|
|
|
|
|
|
คิดไม่ออกครับรบกวนพี่ๆๆ ช่วยชี้แนะด้วยครับ
Code (PHP)
<?php
require('layout_top.php');
include '../../Connect/connect.php';
$params = array();
error_reporting(0);
function sqlEscape($sql1)
{
$fix_str = stripslashes($sql1);
$fix_str = str_replace("'","''",$sql1);
$fix_str = str_replace("\0","[NULL]",$fix_str);
return $fix_str;
}
?>
<?php function DateThai($strDate)
{
$strYear = date("Y",strtotime($strDate))+543;
$strMonth= date("n",strtotime($strDate));
$strDay= date("j",strtotime($strDate));
$strHour= date("H",strtotime($strDate));
$strMinute= date("i",strtotime($strDate));
$strSeconds= date("s",strtotime($strDate));
$strMonthCut = Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct"," Nov","Dec");
$strMonthThai=$strMonthCut[$strMonth];
return "$strDay $strMonthThai $strYear, $strHour:$strMinute:$strSeconds";
}
?>
<?php
$po="select * from PUR_PO";
$querypo1=mysqli_query($conn, $po);
$resultpo1=mysqli_fetch_array($querypo1);
?>
<script type="text/javascript">
$( function() {
$( "#docdate,#to" ).datepicker();
} );
$(function () {
$('#desc2,#stqty,#drawno2').attr('readonly', 'true');
$('#desc2,#stqty,#drawno2').css('background-color' , '#CFCFCF');
});
function SubmitTo(select)
{
if(select == "s1")
{
document.form1.action="accept_edit.php";
document.form1.submit();
}
}
window.onload = function() {
document.getElementById("popup1").onclick = function(){
return !window.open(this.href, "pop", "width=800,height=650,scrollbars=yes, resizable=1,menubar=yes");
}
}
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
<form method="get" name="form1" enctype="multipart/form-data">
<div class="container">
<div class="row justify-content-lg-center">
<div class="col-xl-7">
<div class="card border-info">
<div class="card-body">
<div class="form-row">
<div class="form-group col-xl-4">
<label class="col-form-label text-info">Material No.</label>
<input type="text" class="form-control" name='material' id='material' value='<?php echo $_GET['material'];?>'>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">Vendor Conf.Date </label>
<div class="input-group">
<input type="text" class="form-control" name = 'PO1' id="PO1" value='<?php echo $_GET['PO1'];?>'>
<span class="input-group-btn">
<button class="btn btn-secondary spanright" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">TO</label>
<div class="input-group">
<input type="text" class="form-control" name = 'PO2' id='PO2' value='<?php echo $_GET['PO2'] ?>'>
<span class="input-group-btn">
<button class="btn btn-secondary spanright" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-xl-4">
<label class="col-form-label text-info">Drawing No.</label>
<input type="text" class="form-control" name = 'drawing' id ='drawing' value='<?php echo $_GET['drawing']?>'>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">PO Delivery Date</label>
<div class="input-group">
<input type="text" class="form-control" name='Revise1' id='Revise1' value='<?php echo $_GET['Revise1']?>' >
<span class="input-group-btn">
<button class="btn btn-secondary spanright" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">TO</label>
<div class="input-group">
<input type="text" class="form-control" name='Revise2' id='Revise2' value='<?php echo $_GET['Revise2']?>'>
<span class="input-group-btn">
<button class="btn btn-secondary spanright" type="button"><i class="fa fa-calendar"></i></button>
</span>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-xl-4">
<label class="col-form-label text-info">Status</label>
<input type="text" class="form-control" name='status' id='status' value='<?php echo $_GET['status']?>'>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">PO NO.</label>
<input type="text" class="form-control" name='pono' id='pono' value='<?php echo $_GET ['pono']?>'>
</div>
<div class="form-group col-xl-4">
<label class="col-form-label text-info">Mail</label>
<div class="input-group">
<input type="text" class="form-control" id="Revise3">
<span class="input-group-btn">
<button class="btn btn-danger spanright" type="button">Send</button>
</span>
</div>
</div>
</div>
<div class="form-row" style="margin-top: 20px;">
<div class="form-group col-xl-3">
<button type="button" class="btn btn-success" style="width: 100%;"><i class="fa fa-file-excel-o"></i> Excel</button>
</div>
<div class="form-group col-xl-6">
</div>
<div class="form-group col-xl-3">
<button type="button" onClick="Javascript:SubmitTo('s1')" class="btn btn-danger" style="width: 100%;"><i class="fa fa-search"></i> Search</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<form method="post" name="form2">
<?php
$material=$_GET["material"];
$year=substr($_GET["PO1"],6,4);
$month=substr($_GET["PO1"],3,2);
$date=substr($_GET["PO1"],0,2);
$PO1=$year."-".$month."-".$date;
$year=substr($_GET["PO2"],6,4);
$month=substr($_GET["PO2"],3,2);
$date=substr($_GET["PO2"],0,2);
$PO2=$year."-".$month."-".$date;
$drawing=$_GET["drawing"];
$year=substr($_GET["Revise1"],6,4);
$month=substr($_GET["Revise1"],3,2);
$date=substr($_GET["Revise1"],0,2);
$Revise1=$year."-".$month."-".$date;
$year=substr($_GET["PO3"],6,4);
$month=substr($_GET["PO3"],3,2);
$date=substr($_GET["PO3"],0,2);
$PO3=$year."-".$month."-".$date;
$year=substr($_GET["Revise2"],6,4);
$month=substr($_GET["Revise2"],3,2);
$date=substr($_GET["Revise2"],0,2);
$Revise2=$year."-".$month."-".$date;
$year=substr($_GET["to2"],6,4);
$month=substr($_GET["to2"],3,2);
$date=substr($_GET["to2"],0,2);
$to2=$year."-".$month."-".$date;
$status=$_GET["status"];
$pono=$_GET["pono"];
if(isset($material)==NULL)
{
}
else
{
/*$poonline="select * from PUR_PO WHERE MATERIAL = '$material' and CDATE = '$PO1' and CDATE = '$PO2' and STATUS = '$status' and PONO = '$pono'";*/
$poonline="select * from PUR_PO WHERE PONO IS NOT NULL";
/*$poonline= "select c.* from (select DENSE_RANK() OVER (ORDER BY PONO DESC) as ROW, * from PUR_PO where PONO IS NULL "; */
if($material!=NULL)
$poonline.=" and MATERIAL ='".$material."'";
if($PO1!="--")
$poonline.=" and CDATE >='".$PO1."'";
if($PO2!="--")
$poonline.=" and CDATE<= '".$PO2."'";
if($drawing!=NULL)
$poonline.=" and DRAWNO ='".$drawing."'";
if($Revise1!="--")
$poonline.=" and REDELDATE >='".$Revise1."'";
if($Revise2!="--")
$poonline.=" and REDELDATE<='".$Revise2."'";
if($status!=NULL)
$poonline.=" and STATUS ='".$status."'";
if($pono!=NULL)
$poonline.=" and PONO ='".$pono."'";
/*
$poonline.=")c where c.ROW>=$start and c.ROW<=$end ";
$querypo=mysqli_query($conn,$poonline);
$cut1=str_replace("where c.ROW>=$start and c.ROW<=$end","",$poonline); //ตัดออก
$querycount=mysqli_query($conn,$cut1, $params,$options);
$num_rows=mysqli_num_rows($querycount);
$num_po=mysqli_num_rows($num_rows);
if($num_po>0)*/
$querypo=mysqli_query($conn,$poonline);
$num_po=mysqli_num_rows($querypo);
?>
<?php
/*$poonline="select * from PUR_PO WHERE MATERIAL = '533332'";
$querypo=mysqli_query($conn,$poonline);
$num_po=mysqli_num_rows($querypo);
if($num_po>0)*/
?>
<br>
<!--<div class="card border-secondary" style="padding: 10px 15px; margin: 0 15px; width: 1224px;"> -->
<!--<table id="example" class="display" cellspacing="0" width="6000"> -->
<?php
if($num_po==0)
{
echo "<br><br><br><br><br><br><br>";
echo "<h1>Cannot Find!!!</h1>";
$i=1;
}
else
{
?>
<table class="table table-bordered" style="font-size: 13px; background-color: #f8f8f8;">
<!--<table class="table table-bordered table-hover" style="margin-left: 15px; width: 5000px; font-size: 13px; background-color: #f8f8f8;">-->
<thead>
<tr style="background: #696969; color: #fff; border-bottom:none;">
<!--<th style="padding: 3px 5px;" class="verticaltext">Accept</th>-->
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;">Accept</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Quotation</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Vendor <br> Conf.Date</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Vendor <br> Conf.QTY</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Conf.del.by</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Invoice No.</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Status</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Priority</th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>New Item</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>Estimate <br> price</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>C-material</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>C-Desc</font></th>
<!--<th style="padding: 0px 10px 0px; vertical-align:Middle;" class="text-center"><font color = 'red'>C.QTY</font></th>-->
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>C-QTY</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>C-Price</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>C-Del date</font></th>
<th class="textAlignVer" style="padding: 0px 0px 0px; vertical-align:Middle;"><font color = 'red'>Poline</font></th>
<th class="textAlignVer" style="padding: 30px 0px 0px; vertical-align:Middle;"><font color = 'red'>Delete Po<br>line<br><br></font></th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Revise - OCR</th>
<th style="padding: 0px 0px 0px; vertical-align:Middle;">PO No.</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">PO Item</th>
<th style="padding: 0px 10px 0px; vertical-align:Middle;">Material No</th>
<th style="padding: 0px 90px 0px; vertical-align:Middle;">Description</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Darwing No.</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">PO QTY</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">Open QTY</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">Unit Price</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">Amount</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">CUR</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">PO Date</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Delivery Date</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">New Due Date</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">OLD MRP Date</th>
<th style="padding: 0px 5px 0px; vertical-align:Middle;">NEW MRP Date</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">QC Class</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Remark</th>
<th style="padding: 0px 50px 0px; vertical-align:Middle;">Notes</th>
</tr>
</thead>
<tbody>
<?php
$i = $i + 1;
while($resultpo=mysqli_fetch_array($querypo))
{ ?>
<tr>
<td><center><div class="form-group col-xl-100"><input type="radio" name="" value="" id=""></div></center></td>
<td><center><div class="form-group col-xl-100"><input type="text" name="quotation" id="quotation" value="<?php echo $resultpo["QUOTATOIN"];?>" class="form-control"></div></center></td>
<td><center><div class="form-group col-xl-100"><input type="text" name="vendorcdate" id="vendorcdate" value="<?php echo $resultpo["VCONFDATE"];?>" class="form-control"></div></center></td>
<td><center><div class="form-group col-xl-100"><input type="text" name="vendorcqty" id="vendorcqty" value="<?php echo $resultpo["VCONFQTY"];?>" class="form-control"></div></center></td>
<td><center><div class="form-group col-xl-100"><input type="text" name="confdel" id="confdel" value="<?php echo $resultpo["UBY"];?>" class="form-control"></div></center></td>
<td><center><div class="form-group col-xl-100"><input type="text" name="invoice" id="invoice" value="<?php echo $resultpo["VINVNO"];?>" class="form-control"></div></center></td>
<!--<td><center><div class="form-group col-xl-100"><input type="text" name="priority" id="priority" value="<?php echo $_POST["priority"];?>" class="form-control"></div></center></td>-->
<!--<td style="vertical-align:Middle;"><center><input type="checkbox" name="" value="" id=""></center></td>-->
<td><center><?php echo $resultpo["STATUS"];?></center></td>
<td><center><?php echo $resultpo["PRIORITY"];?></center></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['NEWITEM']=='Y') echo '✔'; else if ($resultpo['NEWITEM']=='N') echo 'X'; ?></font></b></center></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['ESTIMATEPRICE']=='Y') echo '✔'; else if ($resultpo['ESTIMATEPRICE']=='N') echo 'X'; ?></font></b></center></td>
<td></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['CDESC']=='Y') echo '✔'; else if ($resultpo['CDESC']=='N') echo 'X'; ?></font></b></center></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['CQTY']=='Y') echo '✔'; else if ($resultpo['CQTY']=='N') echo 'X'; ?></font></b></center></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['CPRICE']=='Y') echo '✔'; else if ($resultpo['CPRICE']=='N') echo 'X'; ?></font></b></center></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['CDELDATE']=='Y') echo '✔'; else if ($resultpo['CDELDATE']=='N') echo 'X'; ?></font></b></center></td>
<td><font color = 'red'><b><center><?php echo $resultpo["POLINE"];?></font></b></td>
<td><font size = '2' color = 'red'> <b><center><?php if($resultpo['CDELLINE']=='Y') echo '✔'; else if ($resultpo['CDELLINE']=='N') echo 'X'; ?></font></b></center></td>
<td></td>
<td><center><?php echo $resultpo["PONO"];?></center></td>
<td></td>
<td><center><?php echo $resultpo["MATERIAL"];?></center></td>
<td><center><?php echo $resultpo["DESCR"];?></center></td>
<td><center><?php echo $resultpo["DRAWNO"];?></center></td>
<td><center><?php echo $resultpo["POQTY"];?></center></td>
<td><center><?php echo $resultpo["OPENQTY"];?></center></td>
<td><center><?php echo $resultpo["UPRICE"];?></center></td>
<td></td>
<td><center><?php echo $resultpo["CUR"];?></center></td>
<td><center><?php echo DateThai ($resultpo["PODATE"]);?></center></td>
<td><center><?php echo DateThai ($resultpo["DELDATE"]);?></center></td>
<td><center><?php echo DateThai ($resultpo["NEWDUEDATE"]);?></center></td>
<td><center><?php echo DateThai ($resultpo["MRPDATE"]);?></center></td>
<td><center><?php echo $resultpo["QCCLASS"];?></center></td>
<td><center><?php echo $resultpo["NOTE"];?></center></td>
<td></td>
<td></td>
<td><div style="display:none"><input type="text" style="width:190px;" maxlength="100" name="potest" id='potest' value="<?php echo $resultpo["PONO"]; echo $_POST['PONO'];?>"></div></td>
</tr>
<?php
$i++;
}
?>
<?php
}
?>
<?php
}
?>
</tbody>
<div class="form-group col-xl-3">
<!--<button style="margin-right: 3px;" class="btn-xs btn btn-warning edit e<?php echo $value['ITEM']?>" data-id="<?php echo $value['ITEM']?>"><i class="fa fa-edit"></i> Update</button>-->
<button style="margin-right: 3px;" type="submit" name="submit" value="update" class="btn-xs btn btn-warning edit " onClick="return confirm('Are you sure you want to update?')"><i class="fa fa-edit"></i> Update</button>
<!--<button type="submit" name="submit" value="update" onClick="return confirm('Are you sure you want to update?')" style="border-radius: 2em; box-shadow: 10px 12px 20px 1px black; background-color:#C0C0C0 ; width:100; height:40px;"><b>UPDATE</b></button> </div>-->
</table>
<?php
$quotation=$_POST['quotation'];
$potest=$_POST['potest'];
$pono=$_POST['pono'];
$vendorcdate=sqlEscape ($_POST["vendorcdate"]);
$vendorcqty=sqlEscape ($_POST["vendorcqty"]);
$confdel=sqlEscape ($_POST["confdel"]);
$invoice=sqlEscape ($_POST["invoice"]);
$statusin=sqlEscape ($_POST["statusin"]);
$priority=sqlEscape ($_POST["priority"]);
if($_POST["submit"]=="update")
{
/*if($quotation==NULL) {echo "<script>alert('Please input item QUOTATOIN type !');</script>"; return 0;}*/
$update="update PUR_PO set QUOTATOIN ='$quotation'
,VCONFDATE='$vendorcdate'
,VCONFQTY ='$vendorcqty'
,UBY ='$confdel'
,VINVNO = '$invoice'";
if($quotation!=NULL) $update.=",STATUS = 'CHANGE'";
if($quotation==NULL) $update.=",STATUS = 'NEW'";
$update.=" where MATERIAL ='$material' AND PONO = '$potest'";
$queryupdate=mysqli_query($conn, $update);
if($queryupdate)
{
echo "<script>alert('Update Complete ✔✔');</script>";
echo "<script>location.href='accept_edit.php?material=$material';</script>";
}
else
{
echo "<script>alert('Update Fail!!!');</script>";return 0;
}
}
?>
</form>
<?php
require('layout_bottom.php');
?>
<script type="text/javascript">
$(document).ready(function()
{
$('#example').DataTable
({
"searching": false,
"pageLength": 50
});
} );
$( function()
{
$( "#Purchase1,#Purchase2,#New1,#New2,#Vendor1,#Vendor2,#PO1,#PO2,#Revise1,#Revise2" ).datepicker({ dateFormat: 'dd-mm-yy' }).val();
} );
</script>
<style>
.verticaltext
{
writing-mode: tb-rl ;
filter: flipv fliph;
font-size:11px;
margin-left:0px;
}
.textAlignVer
{
filter: flipv fliph;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
transform: rotate(-90deg);
position:relative;
width:20px;
white-space:nowrap;
font-size:12px;
margin-bottom:10px;
}
</style>
Tag : PHP, Ms SQL Server 2005, Windows
|
ประวัติการแก้ไข 2018-02-02 19:20:07
|
|
|
|
|
Date :
2018-02-02 19:18:41 |
By :
owenback |
View :
598 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สร้าง input รับข้อมู่ลแบบอาร์เรย์
name="xxx" เปลี่ยนเป็น name="xxx[]"
ืname="PO1" => name="PO1[]"
ทำให้ครบทุกตัว
และตอนบันทึกวนลูปตัวที่เป็น Primary KEY
foreach($_POST['name_is_primary'] as $index=>$id){
$yyy = $_POST['yyy'][index];
$zzz = $_POST['zzz'][index];
}
|
|
|
|
|
Date :
2018-02-03 16:46:07 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|