+
@@ -436,7 +442,7 @@ custInput.addEventListener('input', function() {
const q = this.value.toLowerCase().trim();
custDropdown.innerHTML = '';
if (q.length < 2) {
- custDropdown.classList.remove('show');
+ document.getElementById('formCustomerId').value = c.id; custDropdown.classList.remove('show');
return;
}
@@ -452,19 +458,19 @@ custInput.addEventListener('input', function() {
div.innerHTML = `${c.name} ${c.phone ? ''+c.phone+'' : ''}`;
div.onclick = function() {
custInput.value = c.name + (c.phone ? ' - ' + c.phone : '');
- custDropdown.classList.remove('show');
+ document.getElementById('formCustomerId').value = c.id; custDropdown.classList.remove('show');
};
custDropdown.appendChild(div);
});
custDropdown.classList.add('show');
} else {
- custDropdown.classList.remove('show');
+ document.getElementById('formCustomerId').value = c.id; custDropdown.classList.remove('show');
}
});
document.addEventListener('click', function(e) {
if (!custInput.contains(e.target) && !custDropdown.contains(e.target)) {
- custDropdown.classList.remove('show');
+ document.getElementById('formCustomerId').value = c.id; custDropdown.classList.remove('show');
}
});
@@ -499,6 +505,7 @@ async function saveNewCustomer() {
if (data.success) {
customersData.push(data.customer);
custInput.value = data.customer.name + (data.customer.phone ? ' - ' + data.customer.phone : '');
+ document.getElementById('formCustomerId').value = data.customer.id;
newCustomerModalObj.hide();
const Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 2000 });
Toast.fire({ icon: 'success', title: '= h(tr('تم إضافة العميل', 'Customer added')) ?>' });
diff --git a/patch.php b/patch.php
new file mode 100644
index 0000000..55dd624
--- /dev/null
+++ b/patch.php
@@ -0,0 +1,76 @@
+query("SHOW COLUMNS FROM branches LIKE 'avatar'");
+ if (\$stmt2->rowCount() === 0) {
+ \$pdo->exec("ALTER TABLE branches ADD COLUMN avatar varchar(255) DEFAULT NULL");
+ }
+ @file_put_contents(\$flagFile, '1');
+S1;
+
+$r1 = <<query("SHOW COLUMNS FROM branches LIKE 'avatar'");
+ if (\$stmt2->rowCount() === 0) {
+ \$pdo->exec("ALTER TABLE branches ADD COLUMN avatar varchar(255) DEFAULT NULL");
+ }
+ \$stmt3 = \pdo->query("SHOW COLUMNS FROM sales_orders LIKE 'customer_id'");
+ if (\$stmt3->rowCount() === 0) {
+ \$pdo->exec("ALTER TABLE sales_orders ADD COLUMN customer_id int(10) unsigned DEFAULT NULL");
+ }
+ \$stmt4 = \pdo->query("SHOW COLUMNS FROM sales_orders LIKE 'payment_status'");
+ if (\$stmt4->rowCount() === 0) {
+ \$pdo->exec("ALTER TABLE sales_orders ADD COLUMN payment_status varchar(20) NOT NULL DEFAULT 'paid'");
+ }
+ @file_put_contents(\$flagFile, '1');
+R1;
+
+$c = str_replace($s1, $r1, $c);
+
+// add to ensure_sales_table()
+$s2 = <<bindValue(':customer_name', $data['customer_name']);
+ $stmt->bindValue(':payment_method', $data['payment_method']);
+S4;
+
+$r4 = <<bindValue(':customer_id', $data['customer_id'] ?? null, PDO::PARAM_INT);
+ $stmt->bindValue(':customer_name', $data['customer_name']);
+ $stmt->bindValue(':payment_method', $data['payment_method']);
+ $stmt->bindValue(':payment_status', $data['payment_status'] ?? 'paid');
+R4;
+$c = str_replace($s4, $r4, $c);
+
+file_put_contents('includes/app.php', $c);
+echo "Patched includes/app.php\n";
diff --git a/pos.php b/pos.php
index f946e77..ad8ecf7 100644
--- a/pos.php
+++ b/pos.php
@@ -19,15 +19,17 @@ try {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$branchCode = trim((string) ($_POST['branch_code'] ?? ''));
+ $customerId = isset($_POST['customer_id']) && $_POST['customer_id'] !== '' ? (int)$_POST['customer_id'] : null;
$customerName = trim((string) ($_POST['customer_name'] ?? ''));
$paymentMethod = trim((string) ($_POST['payment_method'] ?? 'cash'));
+ $paymentStatus = ($paymentMethod === 'pay_later') ? 'unpaid' : 'paid';
$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)) {
+ } elseif (!in_array($paymentMethod, ['cash', 'card', 'transfer', 'pay_later'], true)) {
$error = tr('اختر طريقة دفع صحيحة.', 'Choose a valid payment method.');
} elseif (!is_array($items) || $items === []) {
$error = tr('أضف صنفاً واحداً على الأقل إلى السلة.', 'Add at least one item to the cart.');
@@ -71,8 +73,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'cashier_username' => $user['username'],
'cashier_name' => $cashierName,
'role_name' => $user['role'],
+ 'customer_id' => $customerId,
'customer_name' => $customerName !== '' ? $customerName : null,
'payment_method' => $paymentMethod,
+ 'payment_status' => $paymentStatus,
'items' => $normalized,
'item_count' => $itemCount,
'subtotal' => $subtotal,
@@ -466,6 +470,7 @@ require __DIR__ . '/includes/header.php';