Skip to content

Commit a0a8361

Browse files
committed
7 Feb 2024
1) Added "item sort order" to delivery items table. 2) Updated report and delivery library to adapt sort order.
1 parent f619879 commit a0a8361

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

lib/LIB-Delivery.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ function save ($name, $tel, $email, $address, $date, $items, $notes=null, $stat=
3939

4040
// (A4) ADD ITEMS
4141
$items = json_decode($items, true);
42-
$data = []; $sku = [];
42+
$data = []; $sku = []; $n = 0;
4343
foreach ($items as $i) {
44-
$data = array_merge($data, [$id], $i);
44+
$data = array_merge($data, [$id, $n], $i);
4545
$sku[] = "\"$i[0]\"";
46+
$n++;
4647
}
4748
$this->DB->insert("deliveries_items",
48-
["d_id", "item_sku", "item_price", "item_qty"],
49+
["d_id", "item_sort", "item_sku", "item_price", "item_qty"],
4950
$data
5051
);
5152

@@ -103,7 +104,8 @@ function get ($id) {
103104
"SELECT d.`item_sku` s, i.`item_name` n, i.`item_unit` u, d.`item_price` p, d.`item_qty` q
104105
FROM `deliveries_items` d
105106
LEFT JOIN `items` i USING (`item_sku`)
106-
WHERE `d_id`=?", [$id]
107+
WHERE `d_id`=?
108+
ORDER BY `item_sort`", [$id]
107109
);
108110
$d["items"] = [];
109111
while ($r = $this->DB->stmt->fetch(PDO::FETCH_NUM)) {

lib/LIB-Report.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,8 @@ function getMonitor () {
175175
// (G) DELIVERY ORDER
176176
function deliver ($id) {
177177
$this->Settings->defineN("DELIVER_STAT", true);
178-
$order = $this->DB->fetch("SELECT * FROM `deliveries` WHERE `d_id`=?", [$id]);
179-
$items = $this->DB->fetchAll(
180-
"SELECT d.`item_sku`, d.`item_price`, d.`item_qty`, i.`item_unit`, i.`item_name`
181-
FROM `deliveries_items` d
182-
LEFT JOIN `items` i USING (`item_sku`)
183-
WHERE `d_id`=?", [$id]);
178+
$this->Core->load("Delivery");
179+
$order = $this->Delivery->get($id);
184180
$this->htop([
185181
["l", HOST_ASSETS."REPORT-deliver.css"]
186182
]);

lib/SQL-Storage-Boxx-0.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ CREATE TABLE `deliveries_items` (
169169
`d_id` bigint(20) NOT NULL,
170170
`item_sku` varchar(255) NOT NULL,
171171
`item_price` decimal(12,2) NOT NULL DEFAULT 0.00,
172-
`item_qty` decimal(12,2) NOT NULL
172+
`item_qty` decimal(12,2) NOT NULL,
173+
`item_sort` bigint(20) NOT NULL DEFAULT 0
173174
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
174175

175176
ALTER TABLE `deliveries_items`
176-
ADD PRIMARY KEY (`d_id`,`item_sku`);
177+
ADD PRIMARY KEY (`d_id`,`item_sku`),
178+
ADD KEY `item_sort` (`item_sort`);

pages/REPORT-deliver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
<th>Unit Price</th>
3939
<th>Amount</th>
4040
</tr></thead>
41-
<tbody><?php foreach ($items as $i) { ?>
41+
<tbody><?php foreach ($order["items"] as $i) { ?>
4242
<tr>
43-
<td><?=$i["item_qty"]?> <?=$i["item_unit"]?></td>
44-
<td>[<?=$i["item_sku"]?>] <?=$i["item_name"]?></td>
45-
<td><?=$i["item_price"]?></td>
46-
<td><?=$i["item_price"]?></td>
43+
<td><?=$i[3]?> <?=$i[2]?></td>
44+
<td>[<?=$i[0]?>] <?=$i[1]?></td>
45+
<td><?=$i[4]?></td>
46+
<td><?=$i[3] * $i[4]?></td>
4747
</tr>
4848
<?php } ?></tbody>
4949
</table>

0 commit comments

Comments
 (0)