diff --git a/includes/dotenv.php b/includes/dotenv.php index b1af16a..661cce7 100644 --- a/includes/dotenv.php +++ b/includes/dotenv.php @@ -20,7 +20,7 @@ function load_dotenv(): void { [$k, $v] = array_map('trim', explode('=', $line, 2)); if ($k === '') continue; - // Strip potential surrounding quotes + // Strip potential surrounding quotes (single or double) $v = trim($v, "' "); // Set env if not already set or if empty @@ -36,5 +36,4 @@ function load_dotenv(): void { } // Auto-load on include -load_dotenv(); - +load_dotenv(); \ No newline at end of file diff --git a/items.php b/items.php index f6c032b..3955f30 100644 --- a/items.php +++ b/items.php @@ -3,8 +3,10 @@ require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/includes/lang.php'; +$isAjax = isset($_POST['ajax']) || (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); + if (!isset($_SESSION['user_id'])) { - if (isset($_POST['ajax'])) { + if ($isAjax) { header('Content-Type: application/json'); echo json_encode(['success' => false, 'error' => 'Unauthorized']); exit; @@ -15,7 +17,7 @@ if (!isset($_SESSION['user_id'])) { // Initial view check if (!has_permission('view')) { - if (isset($_POST['ajax'])) { + if ($isAjax) { header('Content-Type: application/json'); echo json_encode(['success' => false, 'error' => 'Forbidden']); exit; @@ -124,7 +126,6 @@ function renderServiceList($lang) { // Handle Actions if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; - $isAjax = isset($_POST['ajax']); // Permission mapping for actions $required_permission = 'view'; @@ -278,7 +279,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { ON DUPLICATE KEY UPDATE price = ?"); $stmt->execute([$item_id, $service_id, $price, $price]); - if (isset($_POST['ajax'])) { + if ($isAjax) { header('Content-Type: application/json'); echo json_encode(['success' => true]); exit; @@ -430,8 +431,8 @@ foreach ($prices_raw as $p) {
- - + @@ -954,4 +955,4 @@ document.getElementById('itemImageFile').addEventListener('change', function(e) }); - + \ No newline at end of file diff --git a/receipt.php b/receipt.php index a99e81d..b0a89f5 100644 --- a/receipt.php +++ b/receipt.php @@ -1,4 +1,5 @@ prepare("SELECT o.*, c.name_en as customer_name_en, c.name_ar as customer_name_ar, c.phone as customer_phone, b.name_en as branch_name_en, b.name_ar as branch_name_ar, b.address_en as branch_address_en, b.address_ar as branch_address_ar, b.phone as branch_phone FROM orders o - LEFT JOIN customers c ON o.customer_id = c.id - JOIN branches b ON o.branch_id = b.id + LEFT JOIN customers c ON o.customer_id = c.id + LEFT JOIN branches b ON o.branch_id = b.id WHERE o.id = ?"); $stmt->execute([$order_id]); $order = $stmt->fetch(); @@ -28,319 +29,156 @@ if (!$order) { die("Order not found"); } -// Fetch Order Items -$stmt = db()->prepare("SELECT oi.*, i.name_en as item_en, i.name_ar as item_ar, - s.name_en as service_en, s.name_ar as service_ar +// Fetch items for this order +$stmt = db()->prepare("SELECT oi.*, i.name_en, i.name_ar, s.name_en as service_en, s.name_ar as service_ar FROM order_items oi JOIN items i ON oi.item_id = i.id JOIN services s ON oi.service_id = s.id WHERE oi.order_id = ?"); $stmt->execute([$order_id]); -$order_items = $stmt->fetchAll(); +$items = $stmt->fetchAll(); -// Fetch Payments -$stmt = db()->prepare("SELECT SUM(amount) as total_paid FROM payments WHERE order_id = ?"); -$stmt->execute([$order_id]); -$total_paid = $stmt->fetch()['total_paid'] ?? 0; -$remaining = ($order['total_price'] - $order['loyalty_discount']) - $total_paid; - -// Bilingual Helper for Labels -function b_label($key) { - global $translations; - $en = $translations['en'][$key] ?? $key; - $ar = $translations['ar'][$key] ?? $key; - return '' . $en . ' / ' . $ar . ''; +$lang = $_SESSION['lang'] ?? 'en'; +function is_arabic() { + global $lang; + return $lang === 'ar'; } -// Fallbacks -$display_company_name_en = $company['name_en'] ?: 'Laundry Brand'; -$display_company_name_ar = $company['name_ar'] ?: 'علامة غسيل'; -$display_vat = $company['vat_no'] ?: $company['vat_number']; -$display_ctr = $company['ctr_no']; - +function format_currency($amount) { + return number_format($amount, decimals()) . ' ' . currency(); +} ?> - + - Receipt #<?= $order['order_number'] ?> - + Receipt #<?= $order['id'] ?> + + -
- - -
-
- - - -
+
+ + Back to POS +
+ +
+
+
+ +
- -

-

- -
-
-
-
- -
-
-
-
- -
- / : - -
- - -
- / : - -
- - - -
- / : - -
+
/
+
+ +
VAT:
-
-
-
#
-
-
-
-
-
-
-
-
-
-
- -
- -
-
- -
-
-
-
- +
+ Date: + +
+
+ Order #: + +
+
+ Customer: + +
+
+ Phone: +
- - - - - - - - - - - - - - - - - -
-
-
-
/
-
+
+ +
+
+
/ x
+
+
+
/
+
+ +
-
-
-
-
-
-
-
-
- - 0): ?> -
-
-
-
+
+ Subtotal: +
+ 0): ?> +
+ Discount: + - +
+ + 0): ?> +
+ VAT ( 0 ? round(($order['vat_amount'] / ($order['subtotal'] ?: 1)) * 100) : 0 ?>%): + +
- -
-
-
-
-
-
-
+ Total: +
- 0): ?> -
-
-
-
-
- + + + + - + \ No newline at end of file