diff --git a/assets/js/main.js b/assets/js/main.js
index b21d2c4..1da9f32 100644
--- a/assets/js/main.js
+++ b/assets/js/main.js
@@ -116,7 +116,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (typeof Swal !== 'undefined') {
Swal.fire('Empty Cart', 'Please add items before saving.', 'warning');
} else {
- alert('Cart is empty');
+ Swal.fire({icon: 'warning', text: 'Cart is empty'});
}
}
});
diff --git a/cookies.txt b/cookies.txt
index 0f3bb80..2fea899 100644
--- a/cookies.txt
+++ b/cookies.txt
@@ -2,4 +2,4 @@
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
-127.0.0.1 FALSE / FALSE 0 PHPSESSID une8u6o0qtfojm7tp3ppv39knh
+127.0.0.1 FALSE / FALSE 0 PHPSESSID knhve7lgedl0acegda65ol7h47
diff --git a/edit_online_order.php b/edit_online_order.php
index b8c9aa1..a1f4db4 100644
--- a/edit_online_order.php
+++ b/edit_online_order.php
@@ -563,7 +563,7 @@ renderInvoice();
document.getElementById('smart-sale-form').addEventListener('submit', function(e) {
if (Object.keys(invoiceItems).length === 0) {
e.preventDefault();
- alert('= h(tr('الرجاء إضافة أصناف للفاتورة أولاً.', 'Please add items to the invoice first.')) ?>');
+ Swal.fire({icon: 'warning', text: '= h(tr('الرجاء إضافة أصناف للفاتورة أولاً.', 'Please add items to the invoice first.')) ?>'});
}
});
diff --git a/edit_sale.php b/edit_sale.php
index 405239a..7396512 100644
--- a/edit_sale.php
+++ b/edit_sale.php
@@ -43,6 +43,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$error = tr('اختر فرعاً صالحاً لهذه الصلاحية.', 'Choose a valid branch for this role.');
} elseif (!in_array($paymentMethod, ['cash', 'card', 'transfer', 'pay_later'], true)) {
$error = tr('اختر طريقة دفع صحيحة.', 'Choose a valid payment method.');
+ } elseif ($paymentMethod === 'pay_later' && !$customerId) {
+ $error = tr('يجب اختيار عميل مسجل للدفع الآجل.', 'You must select a registered customer for pay later.');
} elseif (!is_array($items) || $items === []) {
$error = tr('أضف صنفاً واحداً على الأقل إلى الفاتورة.', 'Add at least one item to the invoice.');
} else {
@@ -521,7 +523,7 @@ async function saveNewCustomer() {
const name = document.getElementById('ncName').value.trim();
const phone = document.getElementById('ncPhone').value.trim();
if (!name) {
- alert('= h(tr('الاسم مطلوب', 'Name is required')) ?>');
+ Swal.fire({icon: 'warning', text: '= h(tr('الاسم مطلوب', 'Name is required')) ?>'});
return;
}
@@ -543,10 +545,10 @@ async function saveNewCustomer() {
const Toast = Swal.mixin({ toast: true, position: 'top-end', showConfirmButton: false, timer: 2000 });
Toast.fire({ icon: 'success', title: '= h(tr('تم إضافة العميل', 'Customer added')) ?>' });
} else {
- alert(data.error);
+ Swal.fire({icon: 'warning', text: data.error});
}
} catch(err) {
- alert('Error saving customer');
+ Swal.fire({icon: 'warning', text: 'Error saving customer'});
}
}
@@ -708,9 +710,14 @@ renderInvoice();
// Intercept form submission to check if items exist
document.getElementById('smart-sale-form').addEventListener('submit', function(e) {
+ const paymentMethod = document.querySelector('select[name="payment_method"]').value;
+ const customerId = document.getElementById('formCustomerId').value;
if (Object.keys(invoiceItems).length === 0) {
e.preventDefault();
- alert('= h(tr('الرجاء إضافة أصناف للفاتورة أولاً.', 'Please add items to the invoice first.')) ?>');
+ Swal.fire({icon: 'warning', text: '= h(tr('الرجاء إضافة أصناف للفاتورة أولاً.', 'Please add items to the invoice first.')) ?>'});
+ } else if (paymentMethod === 'pay_later' && !customerId) {
+ e.preventDefault();
+ Swal.fire({icon: 'warning', text: '= h(tr('يجب اختيار عميل مسجل للدفع الآجل.', 'You must select a registered customer for pay later.')) ?>'});
}
});
diff --git a/includes/app.php b/includes/app.php
index 9c5c7bc..965ef32 100644
--- a/includes/app.php
+++ b/includes/app.php
@@ -274,11 +274,12 @@ function catalog(): array
{
try {
$db = db();
- $stmt = $db->query("SELECT items.*, units.name_ar as u_name_ar, units.name_en as u_name_en FROM items LEFT JOIN units ON items.unit_id = units.id");
+ $stmt = $db->query("SELECT items.*, units.name_ar as u_name_ar, units.name_en as u_name_en FROM items LEFT JOIN units ON items.unit_id = units.id ORDER BY items.created_at DESC, items.id DESC");
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
$catalog = [];
foreach ($items as $item) {
$catalog[$item["sku"]] = [
+ "id" => (int)($item["id"] ?? 0),
"sku" => $item["sku"],
"name_ar" => $item["name"],
"name_en" => $item["name"],
@@ -289,6 +290,7 @@ function catalog(): array
"category_id" => $item["category_id"], "in_catalog" => (int)($item["in_catalog"] ?? 0),
"supplier_id" => $item["supplier_id"],
"image_url" => $item["image_url"],
+ "created_at" => $item["created_at"] ?? null,
"unit_id" => $item["unit_id"],
"unit_ar" => $item["u_name_ar"] ?? "قطعة",
"unit_en" => $item["u_name_en"] ?? "pcs"
diff --git a/includes/footer.php b/includes/footer.php
index 84fd362..93f69fd 100644
--- a/includes/footer.php
+++ b/includes/footer.php
@@ -38,6 +38,24 @@ $isPublic = !isset($user) || !$user;
}
});
+