diff --git a/assets/images/items/item_69a5695c9ca064.49414552.jpg b/assets/images/items/item_69a5695c9ca064.49414552.jpg new file mode 100644 index 0000000..7434719 Binary files /dev/null and b/assets/images/items/item_69a5695c9ca064.49414552.jpg differ diff --git a/assets/images/items/item_69a5697ac55c21.80460234.jpg b/assets/images/items/item_69a5697ac55c21.80460234.jpg new file mode 100644 index 0000000..e06f669 Binary files /dev/null and b/assets/images/items/item_69a5697ac55c21.80460234.jpg differ diff --git a/assets/images/items/item_69a569a491f0e1.37331888.jpg b/assets/images/items/item_69a569a491f0e1.37331888.jpg new file mode 100644 index 0000000..52e18f9 Binary files /dev/null and b/assets/images/items/item_69a569a491f0e1.37331888.jpg differ diff --git a/db/migrations/05_simplify_prices_index.sql b/db/migrations/05_simplify_prices_index.sql new file mode 100644 index 0000000..e730937 --- /dev/null +++ b/db/migrations/05_simplify_prices_index.sql @@ -0,0 +1,5 @@ +-- Drop the old index with variant_id +DROP INDEX unique_price ON prices; + +-- Add a new unique index without variant_id +CREATE UNIQUE INDEX unique_price ON prices (branch_id, item_id, service_id); diff --git a/pos.php b/pos.php index dad9080..ab9856a 100644 --- a/pos.php +++ b/pos.php @@ -2,7 +2,7 @@ $title = 'pos'; require_once __DIR__ . '/includes/header.php'; -$branch_id = $_SESSION['branch_id']; +$branch_id = $_SESSION['branch_id'] ?? 1; // Get all categories $categories = db()->query("SELECT * FROM categories ORDER BY name_en ASC")->fetchAll(); @@ -15,166 +15,207 @@ $stmt = db()->prepare("SELECT i.*, c.name_en as cat_en, c.name_ar as cat_ar $stmt->execute(); $items_raw = $stmt->fetchAll(); -// Get all services and prices for this branch -$stmt = db()->prepare("SELECT p.item_id, p.service_id, p.price, - s.name_en as service_en, s.name_ar as service_ar +// Get all services +$services_raw = db()->query("SELECT * FROM services ORDER BY name_en ASC")->fetchAll(); + +// Get all prices for this branch +$stmt = db()->prepare("SELECT p.item_id, p.service_id, p.price FROM prices p - JOIN services s ON p.service_id = s.id WHERE p.branch_id = ?"); $stmt->execute([$branch_id]); -$all_prices = $stmt->fetchAll(); +$prices_raw = $stmt->fetchAll(); + +$prices = []; +foreach ($prices_raw as $p) { + $prices[$p['item_id']][$p['service_id']] = (float)$p['price']; +} $items = []; foreach ($items_raw as $i) { - $items[$i['id']] = [ - 'id' => $i['id'], - 'name_en' => $i['name_en'], - 'name_ar' => $i['name_ar'], - 'category_id' => $i['category_id'], - 'image_url' => $i['image_url'], - 'vat_percent' => (float)$i['vat_percent'], - 'services' => [] - ]; -} - -foreach ($all_prices as $p) { - if (!isset($items[$p['item_id']])) continue; + $item_services = []; + foreach ($services_raw as $s) { + if (isset($prices[$i['id']][$s['id']])) { + $item_services[] = [ + 'id' => $s['id'], + 'name_en' => $s['name_en'], + 'name_ar' => $s['name_ar'], + 'price' => $prices[$i['id']][$s['id']] + ]; + } + } - $items[$p['item_id']]['services'][] = [ - 'id' => $p['service_id'], - 'name_en' => $p['service_en'], - 'name_ar' => $p['service_ar'], - 'price' => (float)$p['price'] - ]; + // Only include if has services + if (!empty($item_services)) { + $items[$i['id']] = [ + 'id' => $i['id'], + 'name_en' => $i['name_en'], + 'name_ar' => $i['name_ar'], + 'category_id' => $i['category_id'], + 'image_url' => $i['image_url'], + 'vat_percent' => (float)($i['vat_percent'] ?? 15), + 'services' => $item_services + ]; + } } // Get all customers for this branch $stmt = db()->prepare("SELECT * FROM customers WHERE branch_id = ? ORDER BY name_en ASC"); $stmt->execute([$branch_id]); $customers = $stmt->fetchAll(); + +$pageTitle = $lang == 'en' ? 'Point of Sale' : 'نقطة البيع'; ?> -
-
- -
- - - - -
- -
-
-
-
- - +
+
+ +
+
+

+
+ +
- + + +
+ + + + +
+
- -
-
-
+
+
- + -
- +
+
- % VAT + + % VAT +
-
- +
+

-
- -
-
-
-
- -
- -
- -
- - +
+
+ +
+
+ +
+
+ + + +
+
+
+ +
+
+ +
+ +
+ +
+
+ +
+ + +
+
+ +
+
+
+ +

+
+
+ +
- -
-
- -

-
-
- -
-
- - 0.00 SAR -
-
- - 0.00 SAR -
-
- - 0.00 SAR -
- -
- -