From ee933513904bba02186406c1426febadd254730f Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 19 Apr 2026 04:15:39 +0000 Subject: [PATCH] updating sales --- api/customers.php | 26 ++ includes/app.php | 7 +- includes/sale_form.php | 673 +++++++++++++++++++++++++++++++++++------ patch_app.php | 17 -- patch_modal.php | 19 -- patch_table.php | 4 - pos.php | 150 ++++++++- print_receipt.php | 284 +++++++++++++++++ sale.php | 371 +++++++++++++++++++---- sales.php | 29 ++ 10 files changed, 1379 insertions(+), 201 deletions(-) create mode 100644 api/customers.php delete mode 100644 patch_app.php delete mode 100644 patch_modal.php delete mode 100644 patch_table.php create mode 100644 print_receipt.php diff --git a/api/customers.php b/api/customers.php new file mode 100644 index 0000000..f7682e1 --- /dev/null +++ b/api/customers.php @@ -0,0 +1,26 @@ + false, 'error' => tr('الاسم مطلوب', 'Name is required')]); + exit; + } + + try { + $pdo = db(); + $stmt = $pdo->prepare('INSERT INTO customers (name, phone) VALUES (?, ?)'); + $stmt->execute([$name, $phone]); + $id = $pdo->lastInsertId(); + + echo json_encode(['success' => true, 'customer' => ['id' => $id, 'name' => $name, 'phone' => $phone]]); + } catch (Throwable $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } + exit; +} diff --git a/includes/app.php b/includes/app.php index 4d391ed..58d9da0 100644 --- a/includes/app.php +++ b/includes/app.php @@ -256,6 +256,7 @@ function ensure_sales_table(): void item_count INT UNSIGNED NOT NULL DEFAULT 0, subtotal DECIMAL(10,2) NOT NULL DEFAULT 0, total_amount DECIMAL(10,2) NOT NULL DEFAULT 0, + status VARCHAR(20) NOT NULL DEFAULT 'completed', notes TEXT DEFAULT NULL, sale_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -272,9 +273,9 @@ function create_sale(array $data): int ensure_sales_table(); $stmt = db()->prepare('INSERT INTO sales_orders - (receipt_no, sale_mode, branch_code, cashier_username, cashier_name, role_name, customer_name, payment_method, items_json, item_count, subtotal, total_amount, notes, sale_date) + (receipt_no, sale_mode, branch_code, cashier_username, cashier_name, role_name, customer_name, payment_method, items_json, item_count, subtotal, total_amount, status, notes, sale_date) VALUES - (:receipt_no, :sale_mode, :branch_code, :cashier_username, :cashier_name, :role_name, :customer_name, :payment_method, :items_json, :item_count, :subtotal, :total_amount, :notes, NOW())'); + (:receipt_no, :sale_mode, :branch_code, :cashier_username, :cashier_name, :role_name, :customer_name, :payment_method, :items_json, :item_count, :subtotal, :total_amount, :status, :notes, NOW())'); $stmt->bindValue(':receipt_no', $data['receipt_no']); $stmt->bindValue(':sale_mode', $data['sale_mode']); @@ -288,6 +289,8 @@ function create_sale(array $data): int $stmt->bindValue(':item_count', $data['item_count'], PDO::PARAM_INT); $stmt->bindValue(':subtotal', $data['subtotal']); $stmt->bindValue(':total_amount', $data['total_amount']); + $stmt->bindValue(':status', $data['status'] ?? 'completed'); + $stmt->bindValue(':status', $data['status'] ?? 'completed'); $stmt->bindValue(':notes', $data['notes']); $stmt->execute(); diff --git a/includes/sale_form.php b/includes/sale_form.php index 44b60cb..c781c65 100644 --- a/includes/sale_form.php +++ b/includes/sale_form.php @@ -1,16 +1,23 @@ query('SELECT id, name, phone FROM customers ORDER BY name ASC')->fetchAll(); +} catch (Throwable $e) { + $customers = []; +} + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $branchCode = trim((string) ($_POST['branch_code'] ?? '')); $customerName = trim((string) ($_POST['customer_name'] ?? '')); $paymentMethod = trim((string) ($_POST['payment_method'] ?? 'cash')); + $saleStatus = trim((string) ($_POST['sale_status'] ?? 'completed')); $notes = trim((string) ($_POST['notes'] ?? '')); $cartJson = (string) ($_POST['cart_json'] ?? '[]'); $items = json_decode($cartJson, true); @@ -20,7 +27,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } 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.'); + $error = tr('أضف صنفاً واحداً على الأقل إلى الفاتورة.', 'Add at least one item to the invoice.'); } else { $normalized = []; $subtotal = 0.0; @@ -47,7 +54,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } if ($normalized === []) { - $error = tr('السلة غير صالحة بعد التحقق من الأصناف.', 'The cart is invalid after product validation.'); + $error = tr('الفاتورة غير صالحة بعد التحقق من الأصناف.', 'The invoice is invalid after product validation.'); } else { $cashierName = current_lang() === 'ar' ? $user['name_ar'] : $user['name_en']; $saleId = create_sale([ @@ -63,11 +70,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { 'item_count' => $itemCount, 'subtotal' => $subtotal, 'total_amount' => $subtotal, + 'status' => $saleStatus, 'notes' => $notes !== '' ? $notes : null, ]); set_flash('success', $saleMode === 'normal' - ? tr('تم حفظ البيع العادي بنجاح.', 'Normal sale saved successfully.') + ? tr('تم حفظ الفاتورة بنجاح.', 'Invoice saved successfully.') : tr('تم حفظ عملية POS بنجاح.', 'POS sale saved successfully.')); redirect_to('sale.php', ['id' => $saleId]); } @@ -76,105 +84,574 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { require __DIR__ . '/header.php'; ?> -
-
-
-
-
-

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

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

- -
-
- -
- -
- -
+ +
+
+ +
+
+
+ +
+
+
+ + +
+ + +
+
+ + +
+ + + + + + + + + + + + + + + +
+ + +
+
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+ + +
+
+ +
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+ + 0.000 +
+
+ + +
+
+ + 0.000 +
+
+ + +
+
+
- -
-
-
-
-
-

- 0 + +
+ + +
+ + + - + + \ No newline at end of file diff --git a/patch_app.php b/patch_app.php deleted file mode 100644 index 1a7d38b..0000000 --- a/patch_app.php +++ /dev/null @@ -1,17 +0,0 @@ - max(0, $base - $used), - 'price' => $item['price'] - , - 'available' => max(0, $base - $used), - 'price' => $item['price'], - 'category_id' => $item['category_id'], - 'supplier_id' => $item['supplier_id'], - 'image_url' => $item['image_url'], - 'vat' => $item['vat'] - , - $content -); -file_put_contents('includes/app.php', $content); - diff --git a/patch_modal.php b/patch_modal.php deleted file mode 100644 index fb4cee1..0000000 --- a/patch_modal.php +++ /dev/null @@ -1,19 +0,0 @@ -<\?= h\(\$row[\'name\']\) \?><\/td>/', "$1\n$1 \n$1 \" alt=\"\" class=\"rounded\" style=\"width: 40px; height: 40px; object-fit: cover;\">\n$1 \n$1
\n$1 \n$1\n$1", $content); -file_put_contents('stock.php', $content); \ No newline at end of file diff --git a/pos.php b/pos.php index ad39345..e0b2815 100644 --- a/pos.php +++ b/pos.php @@ -11,8 +11,10 @@ $allowedBranches = $user['role'] === 'owner' ? array_keys(branches()) : [$user[' try { $pdo = db(); $categories = $pdo->query('SELECT id, name_ar, name_en FROM categories ORDER BY name_ar ASC')->fetchAll(); + $customers = $pdo->query('SELECT id, name, phone FROM customers ORDER BY name ASC')->fetchAll(); } catch (Throwable $e) { $categories = []; + $customers = []; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -75,7 +77,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ]); set_flash('success', tr('تم حفظ عملية POS بنجاح.', 'POS sale saved successfully.')); - redirect_to('sale.php', ['id' => $saleId]); + redirect_to('print_receipt.php', ['id' => $saleId]); } } } @@ -336,9 +338,15 @@ require __DIR__ . '/includes/header.php';
-
- - +
+
+ + +
+
+ + +
+
+
@@ -476,6 +490,31 @@ require __DIR__ . '/includes/header.php';
+ + +