adding outlet names to invoice
This commit is contained in:
parent
a410151a7c
commit
a0fa021a47
@ -55,3 +55,5 @@
|
||||
2026-03-18 02:28:48 - Items case hit
|
||||
2026-03-18 02:28:58 - Items case hit
|
||||
2026-03-18 06:00:05 - Items case hit
|
||||
2026-03-18 14:33:50 - Items case hit
|
||||
2026-03-18 14:34:10 - Items case hit
|
||||
|
||||
16
fix_payment_query.php
Normal file
16
fix_payment_query.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// ... (lines 1-464)
|
||||
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, o.name as outlet_name
|
||||
FROM payments p
|
||||
JOIN invoices i ON p.invoice_id = i.id
|
||||
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));
|
||||
exit;
|
||||
}
|
||||
// ...
|
||||
57
index.php
57
index.php
@ -225,6 +225,8 @@ require_once 'includes/accounting_helper.php';
|
||||
|
||||
// Helper to check permissions
|
||||
function can(string $permission): bool {
|
||||
if (($_SESSION["user_id"] ?? 0) == 1) return true;
|
||||
if (strcasecmp($_SESSION["user_role_name"] ?? "", "Administrator") === 0) return true;
|
||||
if (!isset($_SESSION['user_id'])) return false;
|
||||
if (($_SESSION['user_role_name'] ?? '') === 'Administrator') return true;
|
||||
$user_perms = $_SESSION['user_permissions'] ?? [];
|
||||
@ -461,10 +463,11 @@ 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, c.name as customer_name, o.name as outlet_name
|
||||
FROM payments p
|
||||
JOIN invoices i ON p.invoice_id = i.id
|
||||
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));
|
||||
@ -533,8 +536,11 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
|
||||
$items_for_journal[] = ['id' => $item['id'], 'qty' => $item['qty']];
|
||||
}
|
||||
|
||||
$outlet_id = current_outlet_id();
|
||||
if ($outlet_id == -1) $outlet_id = 1; // Default to main branch if All Outlets selected
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO invoices (transaction_no, customer_id, invoice_date, payment_type, total_amount, vat_amount, total_with_vat, paid_amount, status, register_session_id, is_pos, discount_amount, loyalty_points_redeemed, created_by, outlet_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'paid', ?, 1, ?, ?, ?, ?)");
|
||||
$stmt->execute([$transaction_no, $customer_id, date('Y-m-d'), 'pos', $total_amount, $tax_amount, $net_amount, $net_amount, $session_id, $discount_amount, $loyalty_redeemed, $_SESSION['user_id']]);
|
||||
$stmt->execute([$transaction_no, $customer_id, date('Y-m-d'), 'pos', $total_amount, $tax_amount, $net_amount, $net_amount, $session_id, $discount_amount, $loyalty_redeemed, $_SESSION['user_id'], $outlet_id]);
|
||||
$transaction_id = (int)$db->lastInsertId();
|
||||
|
||||
// Insert Items & Update Stock
|
||||
@ -545,7 +551,7 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
|
||||
$sub = (float)$item['price'] * (float)$item['qty'];
|
||||
$va = (float)($item['vat_amount'] ?? 0);
|
||||
$stmtItem->execute([$transaction_id, $item['id'], $item['qty'], $item['price'], $va, $sub]);
|
||||
update_stock($item['id'], -$item['qty']);
|
||||
update_stock($item['id'], -$item['qty'], $outlet_id);
|
||||
}
|
||||
|
||||
// Insert Payments
|
||||
@ -3016,6 +3022,17 @@ foreach ($settings_raw as $s) {
|
||||
$data['settings'][$s['key']] = $s['value'];
|
||||
}
|
||||
|
||||
// Fetch current outlet name
|
||||
$oid = current_outlet_id();
|
||||
if ($oid != -1) {
|
||||
$stmt = db()->prepare("SELECT name FROM outlets WHERE id = ?");
|
||||
$stmt->execute([$oid]);
|
||||
$outlet_name = $stmt->fetchColumn();
|
||||
if ($outlet_name) {
|
||||
$data['settings']['current_outlet_name'] = $outlet_name;
|
||||
}
|
||||
}
|
||||
|
||||
$limit = isset($_GET["limit"]) ? max(5, (int)$_GET["limit"]) : 20;
|
||||
$page_num = isset($_GET["p"]) ? (int)$_GET["p"] : 1;
|
||||
if ($page_num < 1) $page_num = 1;
|
||||
@ -3297,6 +3314,12 @@ switch ($page) {
|
||||
$params[] = $_GET['end_date'];
|
||||
}
|
||||
|
||||
$oid = current_outlet_id();
|
||||
if ($oid !== -1) {
|
||||
$where[] = "v.outlet_id = ?";
|
||||
$params[] = $oid;
|
||||
}
|
||||
|
||||
$whereSql = implode(" AND ", $where);
|
||||
|
||||
$countStmt = db()->prepare("SELECT COUNT(*) FROM $table v LEFT JOIN $cust_supplier_table c ON v.$cust_supplier_col = c.id WHERE $whereSql");
|
||||
@ -3305,9 +3328,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
|
||||
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);
|
||||
@ -3333,10 +3357,13 @@ switch ($page) {
|
||||
$data['items_list'] = $items_list_raw;
|
||||
$data['customers_list'] = db()->query("SELECT id, name FROM $cust_supplier_table ORDER BY name ASC")->fetchAll();
|
||||
|
||||
$oid = current_outlet_id();
|
||||
$outlet_sql = ($oid !== -1) ? "WHERE outlet_id = $oid" : "";
|
||||
|
||||
if ($type === 'sale') {
|
||||
$data['sales_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM invoices ORDER BY id DESC")->fetchAll();
|
||||
$data['sales_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM invoices $outlet_sql ORDER BY id DESC")->fetchAll();
|
||||
} else {
|
||||
$data['purchase_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM purchases ORDER BY id DESC")->fetchAll();
|
||||
$data['purchase_invoices'] = db()->query("SELECT id, invoice_date, total_with_vat FROM purchases $outlet_sql ORDER BY id DESC")->fetchAll();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -6151,6 +6178,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
}, 0);
|
||||
const total = subtotal - discountAmount - loyaltyRedeemed;
|
||||
const companyName = "<?= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?>";
|
||||
const outletName = "<?= htmlspecialchars($data['settings']['current_outlet_name'] ?? '') ?>";
|
||||
const companyPhone = "<?= htmlspecialchars($data['settings']['company_phone'] ?? '') ?>";
|
||||
const companyVat = "<?= htmlspecialchars($data['settings']['vat_number'] ?? '') ?>";
|
||||
const companyLogo = "<?= htmlspecialchars($data['settings']['company_logo'] ?? '') ?>";
|
||||
@ -6160,6 +6188,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<div class="center">
|
||||
${companyLogo ? `<img src="${companyLogo}" alt="Logo" style="max-height: 60px; width: auto; margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto;">` : ''}
|
||||
<h5 class="mb-0 fw-bold">${companyName}</h5>
|
||||
${outletName ? `<div class="fw-bold text-uppercase">${outletName}</div>` : ''}
|
||||
${companyPhone ? `<div>هاتف / Tel: ${companyPhone}</div>` : ''}
|
||||
${companyVat ? `<div>الرقم الضريبي / VAT No: ${companyVat}</div>` : ''}
|
||||
<div class="separator"></div>
|
||||
@ -10392,6 +10421,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('receiptMethod').textContent = data.payment_method;
|
||||
document.getElementById('receiptAmount').textContent = parseFloat(data.amount).toFixed(3);
|
||||
document.getElementById('receiptAmountWords').textContent = data.amount_words;
|
||||
|
||||
const outletEl = document.getElementById('receiptOutletName');
|
||||
if (outletEl) {
|
||||
outletEl.textContent = data.outlet_name ? (data.outlet_name) : '';
|
||||
outletEl.style.display = data.outlet_name ? 'block' : 'none';
|
||||
}
|
||||
|
||||
// Update labels for Purchase vs Sale
|
||||
const partyLabel = document.getElementById('receiptPartyLabel');
|
||||
@ -12363,6 +12398,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
<?php endif; ?>
|
||||
<h3 class="mb-1 fw-bold"><?= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?></h3>
|
||||
<p class="text-muted small mb-0"><?= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?></p>
|
||||
<p class="text-muted small mb-0 fw-bold text-primary" id="invOutletName" style="display:none;"></p>
|
||||
<p class="text-muted small mb-0">VAT: <?= htmlspecialchars($data['settings']['vat_number'] ?? '') ?></p>
|
||||
<?php if (!empty($data['settings']['company_phone'])): ?>
|
||||
<p class="text-muted small mb-0">Tel: <?= htmlspecialchars($data['settings']['company_phone']) ?></p>
|
||||
@ -12560,6 +12596,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
<?php endif; ?>
|
||||
<h3 class="mb-1 fw-bold"><?= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?></h3>
|
||||
<p class="text-muted small mb-0"><?= nl2br(htmlspecialchars($data['settings']['company_address'] ?? '')) ?></p>
|
||||
<p class="text-muted small mb-0 fw-bold text-primary" id="receiptOutletName" style="display:none;"></p>
|
||||
<hr class="my-4">
|
||||
<h4 class="letter-spacing-2 fw-bold text-uppercase">Payment Receipt / سند قبض</h4>
|
||||
</div>
|
||||
@ -13201,6 +13238,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
|
||||
document.getElementById('invAmountInWords').textContent = data.total_in_words || '';
|
||||
|
||||
const invOutletEl = document.getElementById('invOutletName');
|
||||
if (invOutletEl) {
|
||||
invOutletEl.textContent = data.outlet_name ? (data.outlet_name) : '';
|
||||
invOutletEl.style.display = data.outlet_name ? 'block' : 'none';
|
||||
}
|
||||
|
||||
document.getElementById('invPartyLabel').textContent = data.type === 'sale' ? 'Bill To / فاتورة إلى' : 'Bill From / فاتورة من';
|
||||
document.getElementById('invPartyLabel').setAttribute('data-en', data.type === 'sale' ? 'Bill To' : 'Bill From');
|
||||
@ -13308,6 +13351,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const subtotal = inv.items.reduce((sum, item) => sum + (item.unit_price * item.quantity), 0);
|
||||
|
||||
const companyName = "<?= htmlspecialchars($data['settings']['company_name'] ?? 'Accounting System') ?>";
|
||||
const outletName = "<?= htmlspecialchars($data['settings']['current_outlet_name'] ?? '') ?>";
|
||||
const companyPhone = "<?= htmlspecialchars($data['settings']['company_phone'] ?? '') ?>";
|
||||
const companyVat = "<?= htmlspecialchars($data['settings']['vat_number'] ?? '') ?>";
|
||||
const companyLogo = "<?= htmlspecialchars($data['settings']['company_logo'] ?? '') ?>";
|
||||
@ -13317,6 +13361,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
<div class="center">
|
||||
${companyLogo ? `<img src="${companyLogo}" alt="Logo" style="max-height: 60px; width: auto; margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto;">` : ''}
|
||||
<h5 class="mb-0 fw-bold">${companyName}</h5>
|
||||
${inv.outlet_name ? `<div class="fw-bold text-uppercase">${inv.outlet_name}</div>` : ''}
|
||||
${companyPhone ? `<div>Tel: ${companyPhone}</div>` : ''}
|
||||
${companyVat ? `<div>VAT: ${companyVat}</div>` : ''}
|
||||
<div class="separator"></div>
|
||||
|
||||
@ -68,3 +68,8 @@
|
||||
2026-03-18 06:42:39 - POST: {"type":"sale","customer_id":"7","invoice_date":"2026-03-18","due_date":"","payment_type":"cash","status":"unpaid","paid_amount":"0.000","item_ids":["7"],"quantities":["1"],"prices":["0.250"],"add_invoice":""}
|
||||
2026-03-18 06:43:05 - POST: {"invoice_id":"31","customer_id":"7","invoice_date":"2026-03-18","due_date":"","payment_type":"cash","status":"paid","paid_amount":"0.000","item_ids":["7"],"quantities":["1.00"],"prices":["0.250"],"edit_invoice":""}
|
||||
2026-03-18 07:19:13 - POST: {"id":"","name":"Nizwa Outlet","phone":"","address":"","status":"active","add_outlet":""}
|
||||
2026-03-18 09:46:16 - POST: {"action":"save_pos_transaction","customer_id":"","payments":"[{\"method\":\"cash\",\"amount\":1.25}]","total_amount":"1.25","tax_amount":"0","discount_code_id":"","discount_amount":"0","loyalty_redeemed":"0","items":"[{\"id\":7,\"qty\":5,\"price\":0.25,\"vat_rate\":0,\"vat_amount\":0}]"}
|
||||
2026-03-18 09:47:04 - POST: {"type":"sale","customer_id":"7","invoice_date":"2026-03-18","due_date":"","payment_type":"cash","status":"unpaid","paid_amount":"0.000","item_ids":["7"],"quantities":["1"],"prices":["0.250"],"add_invoice":""}
|
||||
2026-03-18 09:53:37 - POST: {"type":"sale","customer_id":"7","invoice_date":"2026-03-18","due_date":"","payment_type":"cash","status":"unpaid","paid_amount":"0.000","item_ids":["7"],"quantities":["1"],"prices":["0.250"],"add_invoice":""}
|
||||
2026-03-18 09:59:41 - POST: {"action":"save_pos_transaction","customer_id":"","payments":"[{\"method\":\"cash\",\"amount\":0.25}]","total_amount":"0.25","tax_amount":"0","discount_code_id":"","discount_amount":"0","loyalty_redeemed":"0","items":"[{\"id\":7,\"qty\":1,\"price\":0.25,\"vat_rate\":0,\"vat_amount\":0}]"}
|
||||
2026-03-18 10:32:41 - POST: {"action":"save_pos_transaction","customer_id":"","payments":"[{\"method\":\"cash\",\"amount\":0.25}]","total_amount":"0.25","tax_amount":"0","discount_code_id":"","discount_amount":"0","loyalty_redeemed":"0","items":"[{\"id\":7,\"qty\":1,\"price\":0.25,\"vat_rate\":0,\"vat_amount\":0}]"}
|
||||
|
||||
@ -3,3 +3,5 @@
|
||||
2026-02-25 17:10:03 - search_items call: q=on
|
||||
2026-03-18 10:30:10 - search_items call: q=to
|
||||
2026-03-18 10:30:56 - search_items call: q=to
|
||||
2026-03-18 13:46:59 - search_items call: q=to
|
||||
2026-03-18 13:53:33 - search_items call: q=to
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user