Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DatabasesPhase2_GroupE/customerPages/cPayment.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
175 lines (149 sloc)
7.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("../dbCon.php"); | |
$sql = "SELECT * FROM customers WHERE CustomerID = '" . $_SESSION["CustomerID"] . "'"; | |
//echo $sql; | |
if (!$result = $con->query($sql)) {} | |
$row = $result->fetch_assoc(); | |
if ($row) { | |
$CompanyName = $row['CompanyName']; | |
$ContactName = $row['ContactName']; | |
$ContactTitle = $row['ContactTitle']; | |
$Address = $row['Address']; | |
$City = $row['City']; | |
$Region = $row['Region']; | |
$PostalCode = $row['PostalCode']; | |
$Country = $row['Country']; | |
$Phone = $row['Phone']; | |
$Fax = $row['Fax']; | |
} | |
?> | |
<html> | |
<head> | |
<link rel="stylesheet" href="../style.css"> | |
</head> | |
<body> | |
<div id="header"> | |
<ul id="menu" class="blue"> | |
<li><a href="cDashboard.php">Home</a></li> | |
<li><a href="cEditProfile.php">Edit Profile</a></li> | |
<li><a href="cSearchProduct.php">Search Product</a></li> | |
<li><a href="cCreateOrder.php">Create Order</a></li> | |
<li class="active"><a href="cPayment.php">Payment</a></li> | |
<li><a href="cCart.php">Cart</a></li> | |
<li><a href="cPastOrders.php">Past Orders</a></li> | |
<li class='fRight'><a href="logout.php">Log Out</a></li> | |
</ul> | |
</div> | |
<?php | |
if(!isset($_SESSION['RequiredBy']) || !isset($_SESSION['shoppingCart']) || $_SESSION['shoppingCart'] === ""){ | |
?> | |
<div class='form-group'> | |
<h3>Please create an order first!</h3> | |
</div> | |
<?php | |
}else{ | |
?> | |
<div id='contentwrapper' class='form-group'> | |
<form action = "cPayment_save.php" method = "POST"> | |
<?php | |
$totalDue = 0; | |
$_SESSION['fqOrderDetailsInsert'] = ""; | |
// if (!empty($_SESSION)) { | |
$shoppingCart = $_SESSION['shoppingCart']; | |
$shoppingCart = explode(" ", $shoppingCart); | |
echo "<table id='niceTable'> | |
<tr> | |
<th>Product</th> | |
<th>Category</th> | |
<th>Company</th> | |
<th>Quantity</th> | |
<th>Price</th> | |
<th>Stock</th> | |
<th>Amount</th> | |
<th>Sub-total</th> | |
</tr>"; | |
foreach ($shoppingCart as $productID_Quantity){ | |
$productID = explode("_", $productID_Quantity)[0]; | |
$productQuantity = explode("_", $productID_Quantity)[1]; | |
$query ="SELECT * FROM | |
((products as p LEFT JOIN suppliers as s ON p.SupplierID = s.SupplierID) | |
LEFT JOIN categories c ON p.CategoryID = c.CategoryID) | |
LEFT JOIN company co ON s.CompanyId = co.CompanyID | |
WHERE | |
ProductID = " . $productID; | |
$stmt = $con->prepare($query); | |
$stmt ->execute(); | |
$result = $stmt->get_result(); | |
while($row = mysqli_fetch_array($result)) | |
{ | |
echo "<tr>"; | |
echo "<td>" . $row['ProductName'] . "</td>"; | |
echo "<td>" . $row['CategoryName'] . "</td>"; | |
echo "<td>" . $row['CompanyName'] . "</td>"; | |
echo "<td>" . $row['QuantityPerUnit'] . "</td>"; | |
echo "<td>" . "$" . number_format($row['UnitPrice'], 2) . "</td>"; | |
echo "<td>" . $row['UnitsInStock'] . "</td>"; | |
echo "<td>" . $productQuantity . "</td>"; | |
echo "<td>" . "$" . number_format($productQuantity * $row['UnitPrice'],2) . "</td>"; | |
$totalDue = $totalDue + ($productQuantity * $row['UnitPrice']); | |
$_SESSION['fqOrderDetailsInsert'] = $_SESSION['fqOrderDetailsInsert'] . " INSERT INTO `order details` | |
(`OrderID`, `ProductID`, `UnitPrice`, `Quantity`, `Discount`) VALUES ( | |
(SELECT Max(OrderID) FROM orders), " . | |
$productID . "," . | |
$row['UnitPrice'] . "," . | |
$productQuantity . "," . | |
"0" . | |
");"; | |
} | |
$_SESSION['fqOrder'] = " INSERT INTO orders (CustomerID, OrderDate, ShipVia) VALUES (" . | |
"'" . $_SESSION["CustomerID"] . "', " . | |
"Now(), " . | |
$_SESSION['ShipmentMethod'] . ");"; | |
$_SESSION['fqShipments'] = " INSERT INTO shipments (OrderID) VALUES ((SELECT MAX(OrderID) FROM orders));"; | |
$_SESSION['fqShipAddresses'] = " INSERT INTO shipaddresses (ShipmentsID, RequiredDate, ShipVia, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry) VALUES (" . | |
"(SELECT Max(ShipmentsID) FROM shipments), " . | |
"STR_TO_DATE('" . $_SESSION['RequiredBy'] . "', '%Y-%m-%d'), " . | |
$_SESSION["ShipmentCompany"] . ", " . | |
"'" . $_SESSION["Name"] . "', " . | |
"'" . $_SESSION["Address"] . "', " . | |
"'" . $_SESSION["City"] . "', " . | |
"'" . $_SESSION["Region"] . "', " . | |
"'" . $_SESSION["PostalCode"] . "', " . | |
"'" . $_SESSION["Country"] . "');"; | |
echo "</tr>"; | |
// echo $productID; | |
} | |
echo "</table>"; | |
// } | |
$_SESSION['TotalDue'] = $totalDue; | |
echo "<input type='text' name='TotalDue' id='TotalDue' value='" . $totalDue . "'style='display: none'/> "; | |
echo "<hr><h1>Total Due: $" . number_format($totalDue,2) . "</h1>"; | |
// echo $fqOrder . "<hr>" . $fqOrderDetailsInsert . "<hr>" . $fqShipments . "<hr>" . $fqShipAddresses; | |
?> | |
<hr> | |
<h1>Please select a method of payment</h1> | |
<div class="form-group"> | |
<label>Payment Type</label> | |
<select name="PaymentType" id="PaymentType"> | |
<?php | |
$query ="SELECT * FROM paymenttype"; | |
$stmt = $con->prepare($query); | |
$stmt ->execute(); | |
$result = $stmt->get_result(); | |
while($row = mysqli_fetch_array($result)) | |
{ | |
echo "<option value='" . $row['PaymentTypeID'] . "'>" . $row['Name'] . "</option>"; | |
} | |
?> | |
</select> | |
<!-- <input type='text' name='finalQuery' id='finalQuery' value='<?php | |
// echo $fqOrder . $fqOrderDetailsInsert . $fqShipments . $fqShipAddresses; ?>' style='display: none'/> --> | |
<input type="submit" value="Select"> | |
</div> | |
</form> | |
</div> | |
</body> | |
</html> | |
<?php | |
} | |
?> |