From 4f16b7540ab0d6db043f0e946bea7a329df69185 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 6 May 2026 13:22:44 +0000 Subject: [PATCH] update items filter --- index.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 0d55a39..0a12037 100644 --- a/index.php +++ b/index.php @@ -4731,12 +4731,26 @@ if ($page === 'export') { $headers = ['ID', 'Name', 'Email', 'Phone', 'Tax ID', 'Balance', 'Created At']; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) $rows[] = $row; } elseif ($type === 'items') { - $where = ["1=1"]; - $params = []; - if (!empty($_GET['search'])) { $where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; } + $where = ["i.outlet_id = ?"]; + $params = [current_outlet_id()]; + if (!empty($_GET['search'])) { + $where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)"; + $params[] = "%{$_GET['search']}%"; + $params[] = "%{$_GET['search']}%"; + $params[] = "%{$_GET['search']}%"; + } + if (!empty($_GET['category_id'])) { + $where[] = "i.category_id = ?"; + $params[] = (int)$_GET['category_id']; + } + if (!empty($_GET['supplier_id'])) { + $where[] = "i.supplier_id = ?"; + $params[] = (int)$_GET['supplier_id']; + } $whereSql = implode(" AND ", $where); $stmt = db()->prepare("SELECT i.sku, i.name_en, i.name_ar, c.name_en as category, i.purchase_price, i.sale_price, i.stock_quantity, i.vat_rate FROM stock_items i LEFT JOIN stock_categories c ON i.category_id = c.id + LEFT JOIN suppliers s ON i.supplier_id = s.id WHERE $whereSql ORDER BY i.id DESC"); $stmt->execute($params); $headers = ['SKU', 'Name (EN)', 'Name (AR)', 'Category', 'Purchase Price', 'Sale Price', 'Quantity', 'VAT %']; @@ -4940,14 +4954,22 @@ switch ($page) { break; case 'items': app_debug_file_log('debug.log', date('Y-m-d H:i:s') . " - Items case hit"); - $where = ["i.outlet_id = " . current_outlet_id()]; - $params = []; + $where = ["i.outlet_id = ?"]; + $params = [current_outlet_id()]; if (!empty($_GET['search'])) { $where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; } + if (!empty($_GET['category_id'])) { + $where[] = "i.category_id = ?"; + $params[] = (int)$_GET['category_id']; + } + if (!empty($_GET['supplier_id'])) { + $where[] = "i.supplier_id = ?"; + $params[] = (int)$_GET['supplier_id']; + } $whereSql = implode(" AND ", $where); $countStmt = db()->prepare("SELECT COUNT(*) FROM stock_items i @@ -7185,16 +7207,35 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]); +
-
+
-
+
+ + +
+
+ + +
+
- - + +
-
Limit @@ -7235,6 +7275,7 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]); Name Category Supplier + Sale Price Stock Level Expiry VAT @@ -7269,6 +7310,12 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]); + +
+ +
Incl. VAT:
+
+