|
|
|
รบกวนด้วยครับ ส่งข้อมูลสินค้าไปหลายรายการแต่ อัพเดทแค่รายการเดียว |
|
|
|
|
|
|
|
Code (PHP)
//หน้าฟอร์ม
<?php
session_start();
?>
<?php
if(!isset($_SESSION["intLine"]))
{
echo "ยังไม่มีรายการสั่งซื้อ";
exit();
}
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "mydatabase";
$objCon = mysqli_connect($serverName,$userName,$userPassword,$dbName);
if (!$objCon) {
echo $objCon->connect_error;
exit();
}
?>
<form method="post" action="cussave_order.php" name="autoSumForm" id="autoSumForm" OnSubmit="return fncSubmit();">
<table class="table no-margin">
<thead>
<tr>
<!--<td width="10">#</td>-->
<td width="100">รหัสสินค้า</td>
<td width="400">ชื่อสินค้า</td>
<td width="100">ราคา</td>
<td width="100">จำนวน</td>
<td width="100">ยอดรวม</td>
</tr>
</thead>
<tbody>
<?php
$ProductID = '';
if( isset( $_GET['strProductID'])) {
$ProductID = $_GET['strProductID'];
}
$i = 0;
$Credit = 0;
$Total = 0;
$SumTotal = 0;
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = "SELECT * FROM producttest2 WHERE ProductID = '".$_SESSION["strProductID"][$i]."' ";
$objQuery = mysqli_query($objCon,$strSQL);
$objResult = $objResult = mysqli_fetch_array($objQuery,MYSQLI_ASSOC);
$Total = $_SESSION["strQty"][$i] * $objResult["Price"];
$SumTotal = $SumTotal + $Total;
$Credit = $Credit + $Total;
?>
<tr>
<!--<td><?=$i ;?></td>-->
<td><?=$objResult["Barcode"];?></td>
<td><?=$objResult["ProductName"];?></td>
<td><?=$objResult["Price"];?></td>
<td><?=$_SESSION["strQty"][$i];?></td>
<td><?=number_format($Total,2);?></td>
</tr>
</tbody>
<?php
}
}
?>
<tr>
<td></td>
<!--<td></td>-->
<td colspan="2" align="right">รวม <?=$i ;?> รายการ</td>
<td>ยอดเงินสุทธิ</td>
<td><input name="Sum" type="text" id="Sum" size="10" value="<?php echo $SumTotal;?>" Onchange="JavaScript:return nStr()" readonly ></td>
</tr>
<tr>
<td colspan="2"></td>
<!--<td></td>-->
<td></td>
<td>เงินสดรับ</td>
<td><input name="Received" type="text" id="Received" size="10" Onchange="JavaScript:return nStr()" autofocus ></td>
</tr>
<tr>
<td colspan="2"> </td>
<!--<td></td>-->
<td></td>
<td>เงินทอน</td>
<td><input name="Refund" type="text" id="Refund" size="10" tabindex="2" ></td>
</tr>
<tr>
<td colspan="2"></td>
<!--<td></td>-->
<td></td>
<td>เครดิต <font color="red">*</font> </td>
<td>
<select class="form-control select2" style="width: 100%;" name="Credit" type="text" id="Credit" placeholder="ระบุราคา" required/>
<option selected="0"></option>
<option value="0">ไม่มีเครดิต</option>
<option value="<?php echo $Credit ;?>">เครดิต 30 วัน</option>
</select>
</td>
</tr>
</table>
<br>
<input name="Balance" type="hidden" id="Balance" value="<?php echo $SumTotal ;?>" size="10">
<input name="Subtotal" type="hidden" id="Subtotal" value="<?php echo $Total ;?>" size="10">
<input name="ProductName" type="hidden" id="ProductName" value="<?php echo $objResult["ProductName"];?>" size="10">
<input name="Save" type="hidden" id="Save" value="<?php echo $objResult10["m_name"];?>" size="10">
<br/>
<table class="table no-margin">
<tr>
<td width="50">ชื่อลูกค้า</td>
<td width="250"><input type="text" name="c_name" id="c_name" Class="form-control" value="<?php echo $objResult["CusName"];?>" ></td>
</tr>
<tr>
<td>เบอร์โทร</td>
<td><input type="text" name="c_tel" id="c_tel" Class="form-control" value="<?php echo $objResult["CusTel"];?>"></td>
</tr>
</table>
<br/><br/>
<div> <button type="submit" name="Submit" class="btn btn-success"><i class="fa fa-save"> บันทึก</i></button> <a href="cusclear.php" class="btn btn-warning"><i class="fa fa-refresh"> ยกเลิก</i></a> <a href="customerconfirm.php" class="btn btn-primary"><i class="fa fa-cart-plus"> เพิ่มสินค้า</i></a></div>
</form>
<?php
mysqli_close($objCon);
?>
//หน้าบันทึก
<?php
session_start();
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "mydatabase";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
if (!$conn) {
echo $conn->connect_error;
exit();
}
$Subtotal = $_POST["Subtotal"];
$Balance = $_POST["SumTotal"];
$Received = $_POST["Received"];
$Refund = $_POST["Refund"];
$Credit = $_POST["Credit"];
$Save = $_POST["m_name"];
$strSQL = "
INSERT INTO orders (OrderDate,c_name,c_tel,Balance,Received,Refund,Credit,Save)
VALUES
('".date("Y-m-d H:i:s")."','".$_POST["c_name"]."','".$_POST["c_tel"]."','".$_POST["Balance"]."' ,'".$_POST["Received"]."','".$_POST["Refund"]."','".$_POST["Credit"]."','".$_POST["Save"]."' )
";
$objQuery = mysqli_query($conn,$strSQL);
if(!$objQuery)
{
echo $conn->error;
exit();
}
$strOrderID = mysqli_insert_id($conn);
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = "
INSERT INTO orders_detail (OrderID,ProductID,Qty,Subtotal)
VALUES
('".$strOrderID."','".$_SESSION["strProductID"][$i]."','".$_SESSION["strQty"][$i]."','".$_POST["Subtotal"][$i]."')";
$result = mysqli_query($conn,$strSQL);
if(!$result)
{
echo $conn->error;
exit();
}
else
{
$ID = 1;
$update = "UPDATE producttestqty SET Qty = Qty-'".$_SESSION["strQty"][$i]."' WHERE Barcode = '".$_SESSION["Barcode"][$i]."' ";
$update2 = "DELETE FROM producttest2 WHERE ProductID >='$ID' ";
mysqli_query($conn,$update) or die(mysqli_error($conn));
if(!$update)
{
echo $conn->error;
exit();
}
}
}
}
mysqli_close($conn);
session_destroy();
header("location:showReport.php?OrderID=".$strOrderID);
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2019-02-04 09:06:14 |
By :
HLEW |
View :
586 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|