Skip to content

Commit 87327e4

Browse files
committed
11 Feb 2024
1) Edit item - Will cascade update movement, supplier items, delivery items, purchase items. 2) Delete item - Will cascade delete movement, supplier items, delivery items, purchase items. 3) Delete customer - Will cascade delete all related delivery orders, order items, and movement. 4) Delete supplier item > Will cascade delete all related purchase order items and movement. 5) Delete supplier > Will cascade delete all related purchase orders, order items, movement, and supplier items.
1 parent 4bcc8ec commit 87327e4

File tree

9 files changed

+88
-33
lines changed

9 files changed

+88
-33
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Storage Boxx is an open-source PHP Inventory Management System. With a built-in
66
1) Generate item QR code, built-in QR code scanner.
77
2) Create item NFC tags, built-in NFC scanner.
88
3) Passwordless login - QR, NFC, Web Authentication (Biometric, PIN, Face Recognition).
9-
4) Stock level monitoring, push notifications on low stock.
9+
4) Stock monitoring, push notifications on low stock.
1010
5) Customers and delivery order management.
11-
6) Installable progressive web app.
11+
6) Suppliers and purchase order management.
12+
7) Installable progressive web app.
1213
<br><br>
1314

1415
## :camera: SCREENSHOTS

TODO.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
STORAGE BOXX TO DO / WISH LIST
22
==============================
33

4-
PRIORITY
5-
========
6-
*) Edit/Delete item > deal with cascade effects
7-
*) Edit/Delete customer > deal with cascade effects
8-
*) Edit/Delete supplier > deal with cascade effects
9-
10-
11-
GOOD TO HAVE
12-
============
134
* Check Item update, add More Info
145
* Suppliers
156
* Purchases + Projected In/Out

assets/PAGE-cus.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ var cus = {
6060

6161
// (F) DELETE CUSTOMER
6262
// id : customer id
63-
del : id => cb.modal("Please confirm", `Delete customer? This customer will be lost, but orders will remain.`, () => cb.api({
64-
mod : "customers", act : "del",
65-
data : { id : id },
66-
passmsg : "Customer deleted",
67-
onpass : cus.list
68-
})),
63+
del : id => cb.modal(
64+
`<i class="icon icon-warning"></i> Delete Customer?`,
65+
`<strong class="text-danger">This customer will be removed. All related orders and movement history will be deleted as well.</strong>`,
66+
() => cb.api({
67+
mod : "customers", act : "del",
68+
data : { id : id },
69+
passmsg : "Customer deleted",
70+
onpass : cus.list
71+
})
72+
),
6973

7074
// (H) IMPORT CUSTOMERS
7175
import : () => im.init({

assets/PAGE-items.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ var item = {
7676

7777
// (G) DELETE ITEM
7878
// sku : item SKU
79-
del : sku => cb.modal("Please confirm", `Delete ${sku}? All movement history will be lost!`, () => cb.api({
80-
mod : "items", act : "del",
81-
data : { sku : sku },
82-
passmsg : "Item Deleted",
83-
onpass : item.list
84-
})),
79+
del : sku => cb.modal(
80+
`<i class="icon icon-warning"></i> Delete ${sku}?`,
81+
`<strong class="text-danger">All movement history for this item will be deleted, item will also be removed from all orders and suppliers.</strong>`,
82+
() => cb.api({
83+
mod : "items", act : "del",
84+
data : { sku : sku },
85+
passmsg : "Item Deleted",
86+
onpass : item.list
87+
})
88+
),
8589

8690
// (H) IMPORT ITEMS
8791
import : () => im.init({

assets/PAGE-sup-items.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ var items = {
9696

9797
// (G) DELETE ITEM
9898
// sku : item sku
99-
del : sku => cb.modal("Please confirm", `Remove this item from the supplier?`, () => cb.api({
99+
del : sku => cb.modal(
100+
`<i class="icon icon-warning"></i> Remove Item?`,
101+
`<strong class="text-danger">Item will also be removed from all related PO and movement history.</strong>`, () => cb.api({
100102
mod : "suppliers", act : "delItem",
101103
data : { id : items.id, sku : sku },
102104
passmsg : "Supplier item deleted",

assets/PAGE-sup.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ var sup = {
6060

6161
// (F) DELETE SUPPLIER
6262
// id : supplier id
63-
del : id => cb.modal("Please confirm", `Delete supplier? This supplier and its items will be lost!`, () => cb.api({
64-
mod : "suppliers", act : "del",
65-
data : { id : id },
66-
passmsg : "Supplier deleted",
67-
onpass : sup.list
68-
})),
63+
del : id => cb.modal(
64+
`<i class="icon icon-warning"></i> Delete Supplier?`,
65+
`<strong class="text-danger">This supplier will be deleted. Along with all related orders, items, and movement history.`,
66+
() => cb.api({
67+
mod : "suppliers", act : "del",
68+
data : { id : id },
69+
passmsg : "Supplier deleted",
70+
onpass : sup.list
71+
})
72+
),
6973

7074
// (G) SUPPLIER ITEMS CSV DOWNLOAD
7175
csv : id => {

lib/LIB-Customers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ function save ($name, $tel, $email, $addr=null, $id=null) {
2222
}
2323

2424
// (B) DELETE CUSTOMER
25+
// DANGER - CASCADE DELETE!
2526
// $id : customer id
2627
function del ($id) {
28+
$this->DB->start();
29+
$this->DB->query(
30+
"DELETE `item_mvt`
31+
FROM `item_mvt`
32+
LEFT JOIN `deliveries` USING (`d_id`)
33+
WHERE `cus_id`=?", [$id]
34+
);
35+
$this->DB->query(
36+
"DELETE `deliveries`, `deliveries_items`
37+
FROM `deliveries_items`
38+
LEFT JOIN `deliveries` USING (`d_id`)
39+
WHERE `cus_id`=?", [$id]
40+
);
2741
$this->DB->delete("customers", "`cus_id`=?", [$id]);
42+
$this->DB->end();
2843
return true;
2944
}
3045

lib/LIB-Items.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function save ($sku, $name, $unit, $price=0, $low=0, $desc=null, $osku=null) {
3030
}
3131

3232
// (A4) UPDATE ITEM
33+
// DANGER - CASCADE UPDATE!
3334
else {
3435
$this->DB->update(
3536
"items", ["item_sku", "item_name", "item_desc", "item_unit", "item_price", "item_low"],
@@ -39,6 +40,7 @@ function save ($sku, $name, $unit, $price=0, $low=0, $desc=null, $osku=null) {
3940
$this->DB->update("item_mvt", ["item_sku"], "`item_sku`=?", [$sku, $osku]);
4041
$this->DB->update("suppliers_items", ["item_sku"], "`item_sku`=?", [$sku, $osku]);
4142
$this->DB->update("deliveries_items", ["item_sku"], "`item_sku`=?", [$sku, $osku]);
43+
$this->DB->update("purchases_items", ["item_sku"], "`item_sku`=?", [$sku, $osku]);
4244
}
4345
}
4446

@@ -60,12 +62,15 @@ function import ($sku, $name, $unit, $price, $low=0, $desc=null) {
6062
}
6163

6264
// (C) DELETE ITEM
63-
// WARNING : STOCK MOVEMENT WILL BE REMOVED AS WELL
65+
// DANGER - CASCADE DELETE!
6466
// $sku : item SKU
6567
function del ($sku) {
6668
$this->DB->start();
67-
$this->DB->delete("items", "`item_sku`=?", [$sku]);
6869
$this->DB->delete("item_mvt", "`item_sku`=?", [$sku]);
70+
$this->DB->delete("suppliers_items", "`item_sku`=?", [$sku]);
71+
$this->DB->delete("deliveries_items", "`item_sku`=?", [$sku]);
72+
$this->DB->delete("purchases_items", "`item_sku`=?", [$sku]);
73+
$this->DB->delete("items", "`item_sku`=?", [$sku]);
6974
$this->DB->end();
7075
return true;
7176
}

lib/LIB-Suppliers.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@ function save ($name, $tel, $email, $addr=null, $id=null) {
2222
}
2323

2424
// (B) DELETE SUPPLIER
25+
// DANGER - CASCADE DELETE!
2526
// $id : supplier id
2627
function del ($id) {
2728
$this->DB->start();
28-
$this->DB->delete("suppliers", "`sup_id`=?", [$id]);
29+
$this->DB->query(
30+
"DELETE `item_mvt`
31+
FROM `item_mvt`
32+
LEFT JOIN `purchases` USING (`p_id`)
33+
WHERE `sup_id`=?", [$id]
34+
);
35+
$this->DB->query(
36+
"DELETE `purchases_items`
37+
FROM `purchases_items`
38+
LEFT JOIN `purchases` USING (`p_id`)
39+
WHERE `sup_id`=?", [$id]
40+
);
41+
$this->DB->delete("purchases", "`sup_id`=?", [$id]);
2942
$this->DB->delete("suppliers_items", "`sup_id`=?", [$id]);
43+
$this->DB->delete("suppliers", "`sup_id`=?", [$id]);
3044
$this->DB->end();
3145
return true;
3246
}
@@ -121,10 +135,25 @@ function saveItem ($id, $sku, $ssku, $price, $osku=null) {
121135
}
122136

123137
// (G) DELETE ITEM FROM SUPPLIER
138+
// DANGER - CASCADE DELETE!
124139
// $id : supplier id
125140
// $sku : item sku
126141
function delItem ($id, $sku) {
142+
$this->DB->start();
143+
$this->DB->query(
144+
"DELETE `item_mvt`
145+
FROM `item_mvt`
146+
LEFT JOIN `purchases` USING (`p_id`)
147+
WHERE `sup_id`=? AND `item_sku`=?", [$id, $sku]
148+
);
149+
$this->DB->query(
150+
"DELETE `purchases_items`
151+
FROM `purchases_items`
152+
LEFT JOIN `purchases` USING (`p_id`)
153+
WHERE `sup_id`=? AND `item_sku`=?", [$id, $sku]
154+
);
127155
$this->DB->delete("suppliers_items", "`sup_id`=? AND `item_sku`=?", [$id, $sku]);
156+
$this->DB->end();
128157
return true;
129158
}
130159

0 commit comments

Comments
 (0)