diff --git a/fingerprint.php b/fingerprint.php new file mode 100644 index 0000000..7bd2870 --- /dev/null +++ b/fingerprint.php @@ -0,0 +1,3 @@ += 3 && $thousands <= 10) $tStr = numberToWordsArabic($thousands) . " آلاف"; + else $tStr = numberToWordsArabic($thousands) . " ألف"; + + return $tStr . ($rem ? " و " . numberToWordsArabic($rem) : ""); + } + return (string)$num; +} + // Login Logic $login_error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) { @@ -289,6 +313,46 @@ if (isset($_GET['action']) || isset($_POST['action'])) { echo json_encode(['success' => true]); exit; } + + if ($action === 'get_invoice_items') { + header('Content-Type: application/json'); + $invoice_id = (int)$_GET['invoice_id']; + $stmt = db()->prepare("SELECT ii.*, i.name_en, i.name_ar, i.sku + FROM invoice_items ii + JOIN stock_items i ON ii.item_id = i.id + WHERE ii.invoice_id = ?"); + $stmt->execute([$invoice_id]); + echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)); + exit; + } + + if ($action === 'get_return_details') { + header('Content-Type: application/json'); + $return_id = (int)$_GET['return_id']; + $type = $_GET['type'] ?? 'sale'; + + if ($type === 'purchase') { + $stmt = db()->prepare("SELECT pr.*, c.name as party_name FROM purchase_returns pr LEFT JOIN customers c ON pr.supplier_id = c.id WHERE pr.id = ?"); + $stmt->execute([$return_id]); + $return = $stmt->fetch(PDO::FETCH_ASSOC); + if ($return) { + $stmtItems = db()->prepare("SELECT pri.*, i.name_en, i.name_ar, i.sku FROM purchase_return_items pri JOIN stock_items i ON pri.item_id = i.id WHERE pri.return_id = ?"); + $stmtItems->execute([$return_id]); + $return['items'] = $stmtItems->fetchAll(PDO::FETCH_ASSOC); + } + } else { + $stmt = db()->prepare("SELECT sr.*, c.name as party_name FROM sales_returns sr LEFT JOIN customers c ON sr.customer_id = c.id WHERE sr.id = ?"); + $stmt->execute([$return_id]); + $return = $stmt->fetch(PDO::FETCH_ASSOC); + if ($return) { + $stmtItems = db()->prepare("SELECT sri.*, i.name_en, i.name_ar, i.sku FROM sales_return_items sri JOIN stock_items i ON sri.item_id = i.id WHERE sri.return_id = ?"); + $stmtItems->execute([$return_id]); + $return['items'] = $stmtItems->fetchAll(PDO::FETCH_ASSOC); + } + } + echo json_encode($return); + exit; + } } // Redirect to login if not authenticated @@ -355,14 +419,25 @@ function numberToWordsOMR($number) { $number = number_format((float)$number, 3, '.', ''); list($rials, $baisas) = explode('.', $number); - $rialsWords = numberToWords((int)$rials); - $baisasWords = numberToWords((int)$baisas); + $rialsWordsEn = numberToWords((int)$rials); + $baisasWordsEn = numberToWords((int)$baisas); - $result = $rialsWords . " Omani Rials"; + $enResult = $rialsWordsEn . " Omani Rials"; if ((int)$baisas > 0) { - $result .= " and " . $baisasWords . " Baisas"; + $enResult .= " and " . $baisasWordsEn . " Baisas"; } - return $result . " Only"; + $enResult .= " Only"; + + $rialsWordsAr = numberToWordsArabic((int)$rials); + $baisasWordsAr = numberToWordsArabic((int)$baisas); + + $arResult = $rialsWordsAr . " ريال عماني"; + if ((int)$baisas > 0) { + $arResult .= " و " . $baisasWordsAr . " بيسة"; + } + $arResult .= " فقط"; + + return $enResult . " / " . $arResult; } function getPromotionalPrice($item) { @@ -519,6 +594,108 @@ if (isset($_POST['add_hr_department'])) { } } + if (isset($_POST['add_sales_return'])) { + $invoice_id = (int)$_POST['invoice_id']; + $return_date = $_POST['return_date'] ?: date('Y-m-d'); + $notes = $_POST['notes'] ?? ''; + $item_ids = $_POST['item_ids'] ?? []; + $quantities = $_POST['quantities'] ?? []; + $prices = $_POST['prices'] ?? []; + + if ($invoice_id && !empty($item_ids)) { + $db = db(); + try { + $db->beginTransaction(); + + // Get customer_id from invoice + $stmtInv = $db->prepare("SELECT customer_id FROM invoices WHERE id = ?"); + $stmtInv->execute([$invoice_id]); + $customer_id = $stmtInv->fetchColumn(); + + $total_return = 0; + foreach ($quantities as $i => $qty) { + $total_return += (float)$qty * (float)$prices[$i]; + } + + // Insert Sales Return + $stmt = $db->prepare("INSERT INTO sales_returns (invoice_id, customer_id, return_date, total_amount, notes) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$invoice_id, $customer_id, $return_date, $total_return, $notes]); + $return_id = $db->lastInsertId(); + + // Insert Return Items and Update Stock + $stmtItem = $db->prepare("INSERT INTO sales_return_items (return_id, item_id, quantity, unit_price, total_price) VALUES (?, ?, ?, ?, ?)"); + $stmtStock = $db->prepare("UPDATE stock_items SET stock_quantity = stock_quantity + ? WHERE id = ?"); + + foreach ($item_ids as $i => $item_id) { + $qty = (float)$quantities[$i]; + if ($qty > 0) { + $price = (float)$prices[$i]; + $line_total = $qty * $price; + $stmtItem->execute([$return_id, $item_id, $qty, $price, $line_total]); + $stmtStock->execute([$qty, $item_id]); + } + } + + $db->commit(); + $message = "Sales Return processed successfully!"; + } catch (Exception $e) { + $db->rollBack(); + $message = "Error processing return: " . $e->getMessage(); + } + } + } + + if (isset($_POST['add_purchase_return'])) { + $invoice_id = (int)$_POST['invoice_id']; + $return_date = $_POST['return_date'] ?: date('Y-m-d'); + $notes = $_POST['notes'] ?? ''; + $item_ids = $_POST['item_ids'] ?? []; + $quantities = $_POST['quantities'] ?? []; + $prices = $_POST['prices'] ?? []; + + if ($invoice_id && !empty($item_ids)) { + $db = db(); + try { + $db->beginTransaction(); + + // Get supplier_id (customer_id column) from invoice + $stmtInv = $db->prepare("SELECT customer_id FROM invoices WHERE id = ?"); + $stmtInv->execute([$invoice_id]); + $supplier_id = $stmtInv->fetchColumn(); + + $total_return = 0; + foreach ($quantities as $i => $qty) { + $total_return += (float)$qty * (float)$prices[$i]; + } + + // Insert Purchase Return + $stmt = $db->prepare("INSERT INTO purchase_returns (invoice_id, supplier_id, return_date, total_amount, notes) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$invoice_id, $supplier_id, $return_date, $total_return, $notes]); + $return_id = $db->lastInsertId(); + + // Insert Return Items and Update Stock + $stmtItem = $db->prepare("INSERT INTO purchase_return_items (return_id, item_id, quantity, unit_price, total_price) VALUES (?, ?, ?, ?, ?)"); + $stmtStock = $db->prepare("UPDATE stock_items SET stock_quantity = stock_quantity - ? WHERE id = ?"); + + foreach ($item_ids as $i => $item_id) { + $qty = (float)$quantities[$i]; + if ($qty > 0) { + $price = (float)$prices[$i]; + $line_total = $qty * $price; + $stmtItem->execute([$return_id, $item_id, $qty, $price, $line_total]); + $stmtStock->execute([$qty, $item_id]); + } + } + + $db->commit(); + $message = "Purchase Return processed successfully!"; + } catch (Exception $e) { + $db->rollBack(); + $message = "Error processing return: " . $e->getMessage(); + } + } + } + // --- Biometric Devices Handlers --- if (isset($_POST['add_biometric_device'])) { $name = $_POST['device_name'] ?? ''; @@ -1193,6 +1370,12 @@ switch ($page) { } $data['items_list'] = $items_list_raw; $data['customers_list'] = db()->query("SELECT id, name FROM customers WHERE type = '" . ($type === 'sale' ? 'customer' : 'supplier') . "' ORDER BY name ASC")->fetchAll(); + + if ($type === 'sale') { + $data['sales_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM invoices WHERE type = 'sale' ORDER BY id DESC")->fetchAll(); + } else { + $data['purchase_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM invoices WHERE type = 'purchase' ORDER BY id DESC")->fetchAll(); + } break; case 'sales_returns': @@ -7899,12 +8082,12 @@ document.addEventListener('DOMContentLoaded', function() { ${companyPhone}
No: ${quotNo}
-Date: ${quotDate}
-Valid Until: ${quotValid}
+No / رقم: ${quotNo}
+Date / التاريخ: ${quotDate}
+Valid Until / صالح لغاية: ${quotValid}
To
+To / إلى
Terms & Conditions:
+Terms & Conditions / الشروط والأحكام:
Generated by ${companyName}
+Generated by / تم إنشاؤه بواسطة ${companyName}
Invoice No:
-Date:
-Status:
+Invoice No / رقم الفاتورة:
+Date / التاريخ:
+Status / الحالة:
Bill To
+Bill To / فاتورة إلى
VAT:
-Phone:
+VAT / الضريبة:
+Phone / الهاتف:
Payment Details
-Method:
-Currency: OMR
+Payment Details / تفاصيل الدفع
+Method / الطريقة:
+Currency / العملة: OMR / ريال عماني
| Item Description | -Qty | -Unit Price | -VAT % | -Total | +Item Description / وصف الصنف | +Qty / الكمية | +Unit Price / سعر الوحدة | +VAT % / الضريبة % | +Total / الإجمالي |
|---|
| Date | -Method | -Amount | +Date / التاريخ | +Method / الطريقة | +Amount / المبلغ |
|---|
Customer Signature
+Customer Signature / توقيع العميل
Authorized Signatory
+Authorized Signatory / التوقيع المعتمد
= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>
Receipt No
+Receipt No / رقم السند
Date
+Date / التاريخ
Amount Paid
+Amount Paid / المبلغ المدفوع
| ITEM | -TOTAL | +ITEM / الصنف | +TOTAL / الإجمالي |
|---|
Thank You for your business!
+Thank You for your business! / شكراً لتعاملكم معنا!