From f6212d4e473da880c1ef3f3faef4876c1267342f Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 19 Apr 2026 03:25:43 +0000 Subject: [PATCH] Autosave: 20260419-032550 --- categories.php | 22 +- customers.php | 24 +- index.php | 20 +- pos.php | 774 ++++++++++++++++++++++++++++++++++++++++++++++++- purchases.php | 24 +- sale.php | 20 +- sales.php | 30 +- stock.php | 297 +++++++++++++++---- suppliers.php | 24 +- users.php | 26 +- 10 files changed, 1112 insertions(+), 149 deletions(-) diff --git a/categories.php b/categories.php index a99ccd1..e27a6b1 100644 --- a/categories.php +++ b/categories.php @@ -74,18 +74,18 @@ require __DIR__ . '/includes/header.php';
-
- - +
+
+ - - - - - + + + + + - + @@ -96,10 +96,10 @@ require __DIR__ . '/includes/header.php'; diff --git a/customers.php b/customers.php index 30db595..f3247fd 100644 --- a/customers.php +++ b/customers.php @@ -75,19 +75,19 @@ require __DIR__ . '/includes/header.php';
-
-
IDID
- -
- +
+
+ - - - - - - + + + + + + - + @@ -99,10 +99,10 @@ require __DIR__ . '/includes/header.php'; diff --git a/index.php b/index.php index 6fd54fc..438b035 100644 --- a/index.php +++ b/index.php @@ -95,18 +95,18 @@ require __DIR__ . '/includes/header.php'; -
-
IDID
- -
- +
+
+ - - - - - + + + + + - +
@@ -122,7 +122,7 @@ require __DIR__ . '/includes/header.php';
-
+ diff --git a/pos.php b/pos.php index 0333015..ad39345 100644 --- a/pos.php +++ b/pos.php @@ -1,3 +1,775 @@ query('SELECT id, name_ar, name_en FROM categories ORDER BY name_ar ASC')->fetchAll(); +} catch (Throwable $e) { + $categories = []; +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $branchCode = trim((string) ($_POST['branch_code'] ?? '')); + $customerName = trim((string) ($_POST['customer_name'] ?? '')); + $paymentMethod = trim((string) ($_POST['payment_method'] ?? 'cash')); + $notes = trim((string) ($_POST['notes'] ?? '')); + $cartJson = (string) ($_POST['cart_json'] ?? '[]'); + $items = json_decode($cartJson, true); + + if (!in_array($branchCode, $allowedBranches, true)) { + $error = tr('اختر فرعاً صالحاً لهذه الصلاحية.', 'Choose a valid branch for this role.'); + } elseif (!in_array($paymentMethod, ['cash', 'card', 'transfer'], true)) { + $error = tr('اختر طريقة دفع صحيحة.', 'Choose a valid payment method.'); + } elseif (!is_array($items) || $items === []) { + $error = tr('أضف صنفاً واحداً على الأقل إلى السلة.', 'Add at least one item to the cart.'); + } else { + $normalized = []; + $subtotal = 0.0; + $itemCount = 0; + foreach ($items as $item) { + $sku = (string) ($item['sku'] ?? ''); + $qty = (int) ($item['qty'] ?? 0); + if (!isset($catalog[$sku]) || $qty < 1) { + continue; + } + $product = $catalog[$sku]; + $price = (float) $product['price']; + $lineTotal = $price * $qty; + $normalized[] = [ + 'sku' => $sku, + 'name_ar' => $product['name_ar'], + 'name_en' => $product['name_en'], + 'qty' => $qty, + 'price' => $price, + 'line_total' => $lineTotal, + ]; + $subtotal += $lineTotal; + $itemCount += $qty; + } + + if ($normalized === []) { + $error = tr('السلة غير صالحة بعد التحقق من الأصناف.', 'The cart is invalid after product validation.'); + } else { + $cashierName = current_lang() === 'ar' ? $user['name_ar'] : $user['name_en']; + $saleId = create_sale([ + 'receipt_no' => receipt_code(), + 'sale_mode' => $saleMode, + 'branch_code' => $branchCode, + 'cashier_username' => $user['username'], + 'cashier_name' => $cashierName, + 'role_name' => $user['role'], + 'customer_name' => $customerName !== '' ? $customerName : null, + 'payment_method' => $paymentMethod, + 'items' => $normalized, + 'item_count' => $itemCount, + 'subtotal' => $subtotal, + 'total_amount' => $subtotal, + 'notes' => $notes !== '' ? $notes : null, + ]); + + set_flash('success', tr('تم حفظ عملية POS بنجاح.', 'POS sale saved successfully.')); + redirect_to('sale.php', ['id' => $saleId]); + } + } +} + +require __DIR__ . '/includes/header.php'; +?> + + + + +
+ + +
+ +
+ +
+
+ + +
+
+ +
+
+ + +
+ + + + +
+ + +
+ $item): + $itemSku = h($sku); + $itemName = h(current_lang() === 'ar' ? $item['name_ar'] : $item['name_en']); + $itemPrice = h($item['price']); + $itemCat = h($item['category_id'] ?? ''); + $imageUrl = !empty($item['image_url']) ? h($item['image_url']) : ''; + ?> +
+
+ + <?= $imgAlt ?> + + + +
+
+
+
+
+
+ +
+
+ + +
+
+
+ 0 +
+ +
+ + +
+ +
+ +
+ +

+
+
+ + +
+
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/purchases.php b/purchases.php index 7500345..28e630a 100644 --- a/purchases.php +++ b/purchases.php @@ -55,19 +55,19 @@ require __DIR__ . '/includes/header.php';
-
- - +
+
+ - - - - - - + + + + + + - + @@ -79,10 +79,10 @@ require __DIR__ . '/includes/header.php'; diff --git a/sale.php b/sale.php index 7258b95..c1d1ed4 100644 --- a/sale.php +++ b/sale.php @@ -42,17 +42,17 @@ require __DIR__ . '/includes/header.php';
-
-
- -
- - - - - - +
+
+ + + + + + - + @@ -63,7 +63,7 @@ require __DIR__ . '/includes/header.php';
-
+
diff --git a/sales.php b/sales.php index 26ea230..88b6930 100644 --- a/sales.php +++ b/sales.php @@ -100,20 +100,20 @@ require __DIR__ . '/includes/header.php'; -
- - - - - - - - - - +
+
+ + + + + + + + + - + @@ -140,7 +140,7 @@ require __DIR__ . '/includes/header.php';
@@ -129,10 +129,10 @@ require __DIR__ . '/includes/header.php'; - -
-
+ 1): ?>