-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_table_functions.php
132 lines (118 loc) · 5.83 KB
/
print_table_functions.php
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
<html>
<head>
<style>
table :hover {
background-color: RGBA(243, 111, 39, 0.2) !important;
}
</style>
</head>
</html>
<?php
function generateProductsQuery($whereCondition)
{
// Pobieranie wszystkich nazw produktów, cen etc.
return "SELECT o.idOrders, m.name AS pizza, o.number, m.price * o.number * (1 - (d.discount/100)) AS price FROM orders o
INNER JOIN ordersdetails od ON od.idOrders = o.idOrders
INNER JOIN menu m ON o.idProduct = m.id
LEFT OUTER JOIN discounts d ON d.code = od.discountCode
$whereCondition ORDER BY o.idOrders";
}
function generateDetailsQuery($whereCondition)
{
// DISTINCT żeby pobrać tylko jeden wiersz
// Pobieranie jedego wiersza dla każdego zamówienia do wyświetlenia miasta, adresu etc.
return "SELECT DISTINCT o.idOrders, od.discountCode, od.name, od.city, od.address, od.phone, u.email FROM ordersdetails od
INNER JOIN orders o ON od.idOrders = o.idOrders
INNER JOIN users u ON o.idUser = u.id
$whereCondition ORDER BY o.idOrders";
}
/**
* Prints table of orders
*
* @param array $dataArr array from table `orders`
* @param array $countArr array that contains how many products each order has
* @param sth $detailsSth statement handler from table `ordersdetails`
* @param bool $button1Visibility boolean that indicates button1 visibility
* @param string $retPath name of file that should be loaded ather logic file of a button
* @param string $button1Status status that will be set after pressing button1 ('Anulowano'. 'Zrealizowano', 'W trakcie realizacji')
* @param bool $confirmButton boolean that indicates button2 visibility
* @param string $button2Status status that will be set after pressing button2 ('Anulowano'. 'Zrealizowano', 'W trakcie realizacji')
*/
function printTable($dataArr, $countArr, $detailsSth, $retPath = "", $button1Visibility = false, $button1Status = "", $button2Visibility = false, $button2Status = "")
{
$prevOrderId = -1;
$orderPriceSum = 0;
$currentOrderElement = 1; // Do wyświetlenia podsumowania zamówienia
echo '<table class="center table " style="width: 80%; margin-left:auto; margin-right:auto">
<tr>
<th class="tableUnderline">Produkt</th>
<th class="tableUnderline">Ilość</th>
<th class="tableUnderline">Cena</th>
<th class="tableUnderline">ID zam.</th>
<th class="tableUnderline">Kod prom.</th>
<th class="tableUnderline">Imię</th>
<th class="tableUnderline">Miasto</th>
<th class="tableUnderline">Adres</th>
<th class="tableUnderline">Telefon</th>
<th class="tableUnderline">Email</th>';
if ($button1Visibility || $button2Visibility) {
// Wyświetlić tylko jeśli będą jakieś przyciski
echo '<th class="tableUnderline">Akcja</th>';
}
echo '</tr>';
foreach ($dataArr as $row) {
$orderCount = 1;
foreach ($countArr as $key => $val) {
if ($val['idOrders'] == $row['idOrders']) {
$orderCount = $countArr[$key]['count'] + 1;
break;
}
}
$price = number_format($row['price'], 2);
echo "
<tr>
<td class='align-middle'>{$row['pizza']}</td>
<td class='align-middle'>{$row['number']}</td>
<td class='align-middle'>$price zł</td>
";
$orderPriceSum += $row['price'];
if ($prevOrderId != $row['idOrders']) {
$prevOrderId = $row['idOrders'];
$rowDetails = $detailsSth->fetch();
echo "
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$row['idOrders']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['discountCode']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['name']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['city']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['address']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['phone']}</td>
<td rowspan='$orderCount'class='align-middle tableUnderline'>{$rowDetails['email']}</td>";
if ($button1Visibility || $button2Visibility) {
echo "<td rowspan='$orderCount' class='align-middle tableUnderline'>";
if ($button1Visibility) {
echo "
<form method='post' action='edit_orders_logic.php?status=$button1Status&retPath=$retPath'>
<button name='orderID' class='btn btn-outline-success align-middle' style='width: 50px' type='submit' value='{$row['idOrders']}'>✔</button>
</form> ";
}
if ($button2Visibility) {
echo "
<form method='post' action='edit_orders_logic.php?status=$button2Status&retPath=$retPath'>
<button name='orderID' value='{$row['idOrders']}' class='btn btn-outline-danger align-middle' style='width: 50px; margin-top: 5px' type='submit'>✘</button>
</form> ";
}
echo "</td>";
}
}
echo "</tr>";
$currentOrderElement++;
if ($currentOrderElement == $orderCount) {
$orderPriceSum = number_format($orderPriceSum, 2);
echo " <td class='align-middle tableUnderline' ><h4>Suma:</h4> </td> ";
echo " <td colspan='2'class='align-middle tableUnderline' ><h4>$orderPriceSum zł</h4> </td> ";
$orderPriceSum = 0;
$currentOrderElement = 1;
}
}
echo '</table>';
}