diff --git a/index.php b/index.php
index b8f23eb..ad7964f 100644
--- a/index.php
+++ b/index.php
@@ -419,10 +419,12 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
if ($action === 'get_payment_details') {
header('Content-Type: application/json');
$payment_id = (int)$_GET['payment_id'];
- $stmt = db()->prepare("SELECT p.*, i.customer_id, c.name as customer_name
+ $stmt = db()->prepare("SELECT p.*, i.customer_id, i.id as inv_id, c.name as customer_name,
+ o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone
FROM payments p
JOIN invoices i ON p.invoice_id = i.id
- JOIN customers c ON i.customer_id = c.id
+ LEFT JOIN customers c ON i.customer_id = c.id
+ LEFT JOIN outlets o ON i.outlet_id = o.id
WHERE p.id = ?");
$stmt->execute([$payment_id]);
echo json_encode($stmt->fetch(PDO::FETCH_ASSOC));
@@ -540,7 +542,22 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
recordSaleJournal($transaction_id, $net_amount, date('Y-m-d'), $items_for_journal, $tax_amount);
$db->commit();
- echo json_encode(['success' => true, 'invoice_id' => $transaction_id, 'transaction_no' => $transaction_no]);
+
+ $outlet = [];
+ if (!empty($_SESSION['outlet_id'])) {
+ $stmtO = $db->prepare("SELECT name, phone, address FROM outlets WHERE id = ?");
+ $stmtO->execute([$_SESSION['outlet_id']]);
+ $outlet = $stmtO->fetch(PDO::FETCH_ASSOC);
+ }
+
+ echo json_encode([
+ 'success' => true,
+ 'invoice_id' => $transaction_id,
+ 'transaction_no' => $transaction_no,
+ 'outlet_name' => $outlet['name'] ?? null,
+ 'outlet_phone' => $outlet['phone'] ?? null,
+ 'outlet_address' => $outlet['address'] ?? null
+ ]);
} catch (Exception $e) {
$db->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
@@ -3614,9 +3631,10 @@ switch ($page) {
$data['total_pages'] = ceil($total_records / $limit);
$data['current_page'] = $page_num;
- $stmt = db()->prepare("SELECT q.*, c.name as customer_name
+ $stmt = db()->prepare("SELECT q.*, c.name as customer_name, o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone
FROM quotations q
JOIN customers c ON q.customer_id = c.id
+ LEFT JOIN outlets o ON q.outlet_id = o.id
WHERE $whereSql
ORDER BY q.id DESC
LIMIT $limit OFFSET $offset");
@@ -3665,9 +3683,10 @@ switch ($page) {
$data['total_pages'] = ceil($total_records / $limit);
$data['current_page'] = $page_num;
- $stmt = db()->prepare("SELECT q.*, s.name as supplier_name
+ $stmt = db()->prepare("SELECT q.*, s.name as supplier_name, o.name as outlet_name, o.address as outlet_address, o.phone as outlet_phone
FROM lpos q
JOIN suppliers s ON q.supplier_id = s.id
+ LEFT JOIN outlets o ON q.outlet_id = o.id
WHERE $whereSql
ORDER BY q.id DESC
LIMIT $limit OFFSET $offset");
@@ -3736,9 +3755,10 @@ switch ($page) {
$data['total_pages'] = ceil($total_records / $limit);
$data['current_page'] = $page_num;
- $stmt = db()->prepare("SELECT v.*, c.name as customer_name, c.tax_id as customer_tax_id, c.phone as customer_phone
+ $stmt = db()->prepare("SELECT v.*, c.name as customer_name, c.tax_id as customer_tax_id, c.phone as customer_phone, o.name as outlet_name, o.phone as outlet_phone, o.address as outlet_address
FROM $table v
LEFT JOIN $cust_supplier_table c ON v.$cust_supplier_col = c.id
+ LEFT JOIN outlets o ON v.outlet_id = o.id
WHERE $whereSql
ORDER BY v.id DESC LIMIT $limit OFFSET $offset");
$stmt->execute($params);
@@ -6909,7 +6929,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
if (result.success) {
const payModal = bootstrap.Modal.getInstance(document.getElementById('posPaymentModal'));
if (payModal) payModal.hide();
- this.showReceipt(result.invoice_id, discountAmount, loyaltyRedeemed, result.transaction_no);
+ this.showReceipt(result.invoice_id, discountAmount, loyaltyRedeemed, result.transaction_no, result.outlet_name, result.outlet_phone, result.outlet_address);
} else {
Swal.fire('Error', result.error, 'error');
btn.disabled = false;
@@ -6922,7 +6942,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
btn.innerText = originalText;
}
},
- showReceipt(invId, discountAmount, loyaltyRedeemed, transactionNo) {
+ showReceipt(invId, discountAmount, loyaltyRedeemed, transactionNo, outletName, outletPhone, outletAddress) {
const container = document.getElementById('posReceiptContent');
const customerSelect = document.getElementById('posCustomer');
const customerName = (customerSelect && customerSelect.selectedIndex >= 0 && customerSelect.value !== '') ? customerSelect.options[customerSelect.selectedIndex].text : '= $translations['ar']['walk_in_customer'] ?> / = $translations['en']['walk_in_customer'] ?>';
@@ -6963,8 +6983,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
return sum + ((item.price * item.qty) * (vatRate / (100 + vatRate)));
}, 0);
const total = subtotal - discountAmount - loyaltyRedeemed;
- const companyName = "= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?>";
- const companyPhone = "= htmlspecialchars($data['settings']['company_phone'] ?? '') ?>";
+ const companyName = outletName || "= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?>";
+ const companyPhone = outletPhone || "= htmlspecialchars($data['settings']['company_phone'] ?? '') ?>";
+ const companyAddress = outletAddress ? outletAddress.replace(/\n/g, '
') : "= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>";
const companyVat = "= htmlspecialchars($data['settings']['vat_number'] ?? '') ?>";
const companyLogo = "= htmlspecialchars($data['settings']['company_logo'] ?? '') ?>";
@@ -6973,6 +6994,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
- ${companySettings.company_address || ''}
- Phone: ${companySettings.company_phone || ''} | Email: ${companySettings.company_email || ''}
+ ${data.outlet_address ? data.outlet_address.replace(/\n/g, '
') : (companySettings.company_address || '').replace(/\n/g, '
')}
+ Phone: ${data.outlet_phone || companySettings.company_phone || ''} | Email: ${companySettings.company_email || ''}
${companySettings.tax_number ? `
TRN: ${companySettings.tax_number}` : ''}
VAT: ${companySettings.vat_number}
` : ''; - const companyPhone = companySettings.company_phone ? `Tel: ${companySettings.company_phone}
` : ''; + const companyPhone = data.outlet_phone ? `Tel: ${data.outlet_phone}
` : (companySettings.company_phone ? `Tel: ${companySettings.company_phone}
` : ''); // Quotation Header Construction const quotDate = data.quotation_date; @@ -13839,12 +13869,10 @@ document.addEventListener('DOMContentLoaded', function() { ?>= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>
+= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>
VAT: = htmlspecialchars($data['settings']['vat_number'] ?? '') ?>
- -Tel: = htmlspecialchars($data['settings']['company_phone']) ?>
- += nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>
+= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?>