-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewOrder.php
More file actions
170 lines (167 loc) · 4.19 KB
/
viewOrder.php
File metadata and controls
170 lines (167 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html>
<head>
<title>View orders</title>
<link rel="stylesheet" href="style.css">
<style>
.tot
{
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-weight: 10px;
}
input[type=submit]
{
background-color: #f75757;
color: white;
padding: 18px;
font-size: 20px;
border: none;
cursor: pointer;
font-family: Arial, Helvetica, sans-serif;
}
input[type=submit]:hover{
background-color: #f75757e3;
}
</style>
</head>
<body>
<?php
$con=mysqli_connect("us-cdbr-iron-east-04.cleardb.net","b966a2a16a969f","01d02abd","heroku_0b7502a16e114a3");
session_start();
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
elseif(isset($_SESSION["uid"]))
{?>
<a href="index.php" class="btn">Home</a><br><br><br>
<?php
$uid = mysqli_escape_string($con,$_SESSION["uid"]);
$sql1 = "SELECT * FROM orders WHERE userID = '$uid' AND paid = 'N'";
$res1 = mysqli_query($con,$sql1);
if (!$res1)
{
die('Error: ' . mysqli_error($con));
}
else
{
$subTotal = 0;
echo "<div class='tot'>Not paid orders of userID: ".$uid."</div><br>";
echo '<table>';
echo '<tr><th> OrderID </th><th> ProductID </th><th> Product Name</th><th> Price </th><th> Quantity </th><th> Free </th><th>Total </th><th> EDIT</th></tr>';
while($row1 = mysqli_fetch_array($res1))
{
echo '<tr><td>'.$row1["orderID"] .'</td><td>'.$row1["productID"].'</td>';
$pid = $row1['productID'];
$sql2 = "SELECT name,price,brand FROM product WHERE productID = '$pid' LIMIT 1";
$res2 = mysqli_query($con,$sql2);
if (!$res2)
{
die('Error: ' . mysqli_error($con));
}
else
{
$total = 0;
$totPro = 0;
$free = 0;
$row2 = mysqli_fetch_array($res2);
echo '<td>'.$row2["name"]. '</td><td>'.$row2["price"].'</td>';
$today = date("Y-m-d");
$brnd = $row2['brand'];
$brnd = addslashes($brnd);
$sql3 = "SELECT proID, percent,value,brand FROM promotion WHERE brand LIKE '$brnd' && '$today' BETWEEN sDAte AND eDate LIMIT 1";
$res3 = mysqli_query($con,$sql3);
if (!$res3)
{
die('Error: ' . mysqli_error($con));
}
else
{
if(mysqli_num_rows($res3)>0)
{
$quan = $row1["quantity"];
while($row3 = mysqli_fetch_array($res3))
{
if($row3['proID']==1)
{
$total = (ceil($quan/2))*$row2["price"];
if($quan%2==1)
{
$free = 1;
}
else
{
$free = 0;
}
}
else if($row3['proID']==2)
{
if($quan%3==0)
{
$total = $row2["price"]*(2/3);
$free = 0;
}
else if($quan%3==1)
{
$total = ((2*ceil($quan/3))-1)*$row2["price"];
$free = (ceil($quan/3))-1;
}
else
{
$total = (2*ceil($quan/3))*$row2["price"];
if(ceil($quan/3)==1)
{
$free = 1;
}
else
{
$free = (ceil($quan/3))-1;
}
}
}
else if ($row3['proID']==3)
{
$total = ($quan*$row2["price"])*(1-($row3['percent']/100));
$free = 0;
}
else if($row3['proID']==4)
{
$total =($quan*$row2["price"])-$row3['value'];
$free = 0;
}
$totPro = $totPro + $total;
$subTotal = $subTotal + $totPro;
}
}
echo '<td>'.$row1["quantity"].'</td>';
if($free == 0)
{
echo '<td> - </td>';
}
else
{
echo '<td>'.$free.'</td>';
}
if($totPro>0)
{
echo '<td>'.$totPro.'</td>'; }
else
{
$total = $row1["quantity"]*$row2["price"];
echo '<td>'.$total.'</td>';
$subTotal = $subTotal + $total;
}
echo '<td><form action = "del.php" method="post"><input type="hidden" name="oid" value="'.$row1["orderID"].'">';
echo '<input class="bton" type="submit" name="sub" value="Delete"></form></td></tr>';
}
}
}
echo '</table><br>';
echo "<div class='tot'>Total amount: ".$subTotal." Baht</div>";
}
}
mysqli_close($con);
?>
</body>
</html>