<?php include("conn.php"); // Check connection if (mysqli_connect_errno()) { die("Connection failed: " . mysqli_connect_error()); } //payment method $payment = $_POST["payment"]; // about the item $item_id = $_POST["itemID"]; $item_number = $_POST["itemAmount"]; $total = $_POST["total"]; //online_ordering table!!!!!!!! $sql = "INSERT INTO walk_in_sales (Sal_Date, Payment_Method) VALUES ('".date("Y-m-d H:i:s")."', '$payment')"; mysqli_query($conn, $sql); //--->>>>set the order_id for online_ordering_details table $sql_sid = "SELECT Sal_ID FROM walk_in_sales ORDER BY Sal_ID DESC LIMIT 0, 1"; $rows = mysqli_fetch_array(mysqli_query($conn,$sql_sid)); $sal_id = $rows["Sal_ID"]; //online_ordering_details table!! $min = min(count($item_id), count($item_number)); for($i=0; $i < $min; $i++){ $sql = "INSERT INTO walk_in_sales_details (Sal_ID, Item_ID, Sal_Amount) VALUES ($sal_id, $item_id[$i], $item_number[$i]);"; mysqli_query($conn, $sql); //update the items stock $sql = "UPDATE item SET Item_Stock = Item_Stock - $item_number[$i] WHERE Item_ID = $item_id[$i]"; mysqli_query($conn, $sql); } if (mysqli_query($conn, $sql)) { echo("<script>alert('Successful')</script>"); setcookie("shopping_cart", "", date("0")); } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); die ("<script>window.history.go(-1);</script>") ; } mysqli_close($conn); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <!-- Bootstrap --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <link rel="shortcut icon" href="images/logo.png" type="image/x-icon" /> <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Courgette&display=swap" rel="stylesheet"> <script src="https://kit.fontawesome.com/0c641bf868.js" crossorigin="anonymous"></script> <link href="https://fonts.googleapis.com/css?family=Acme&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Teko:700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet"> <title>Receipt</title> <style> .center{ display: block; margin-left: auto; margin-right: auto; width: 50%; height:150px; width:150px; } .container{ width:800px; border: 1px solid black; } </style> </head> <body> <?php include("conn.php");//add connection to the php page $date = date("Y-m-d H:i:s"); $sql = "SELECT Sal_ID, Sal_Date, Payment_Method FROM walk_in_sales WHERE Sal_date = '$date'"; $result = mysqli_query($conn, $sql); while($rows = mysqli_fetch_array($result)) { $oid = $rows['Sal_ID']; $odate = $rows['Sal_Date']; $method = $rows['Payment_Method']; ?> <div class="container" id="printableArea"> <img src="images/logo.png" class="center"> <h2 style="font-family: 'Acme', sans-serif;text-align:center;">Official Receipt</h2> <div class="content"> <p>Walk In Customer</P> <p style="margin-top:-10px;">Date : <?php echo $odate;?></p> <p style="margin-top:-10px;">Invoice No : # <?php echo $oid;?></p> <p style="margin-top:-10px;">Payment Method : <?php echo $method;?></p> <br/><br/><br/> <table class="table" style="text-align:center;"> <thead class="thead-dark"> <tr> <th scope="col">No.</th> <th scope="col">Item Name</th> <th scope="col">Quantity</th> <th scope="col">Unit Price</th> <th scope="col">Price</th> </tr> </thead> <?php $sql1 = "SELECT od.Item_ID, i.Item_Name, i.Item_Price, od.Sal_Amount FROM walk_in_sales_details od, item i WHERE (od.Item_ID = i.Item_ID) AND Sal_ID = '$oid'"; $result1 = mysqli_query($conn, $sql1); $total = 0; $temp_id = 1; while($row = mysqli_fetch_array($result1)) { ?> <tbody> <tr> <td><?php echo $temp_id?></td> <td><?php echo $row['Item_Name']?></td> <td><?php echo $row['Sal_Amount']?></td> <td>RM <?php echo $row['Item_Price']?></td> <td>RM <?php echo $row['Item_Price']*$row['Sal_Amount']; ?></td> </tr> <?php $total = $total + ($row["Sal_Amount"] * $row["Item_Price"]); $temp_id++; } $tax = $total * 0.06; $subtotal = $total * 1.06; ?> <tr style="background-color:#333; color:whitesmoke; "> <td colspan="4" align="right">Total</td> <td align="center">RM <?php echo number_format($total, 2); ?></td> </tr> <tr style="background-color:#333; color:whitesmoke;"> <td colspan="4" align="right">Tax (6%)</td> <td align="center">RM <?php echo number_format($tax, 2); ?></td> </tr> <tr style="background-color:#333; color:whitesmoke;"> <td colspan="4" align="right">Subtotal</td> <td align="center">RM <?php echo number_format($subtotal, 2); ?></td> </tr> </tbody> </table> </div> <?php } ?> </div> <br/> <button type="button" class="btn btn-success" onclick="printDiv('printableArea')" style="margin-left:580px; width:150px;">Print</button> <a href="pos.php" class="btn btn-danger" style="margin-left:50px; width:150px;">Close</a> <br/> <br/> <br/> <!--Bootstrap js--> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> <script> function printDiv(divName) { var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; } </script> </body> </html>