73 lines
3.8 KiB
PHP
73 lines
3.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/app.php';
|
|
$user = require_roles(['owner', 'manager', 'cashier']);
|
|
$pageTitle = tr('تفاصيل الفاتورة', 'Sale Detail');
|
|
$activeNav = 'sales';
|
|
$id = (int) ($_GET['id'] ?? 0);
|
|
$sale = null;
|
|
$dbError = null;
|
|
if ($id > 0) {
|
|
try {
|
|
$sale = fetch_sale($id);
|
|
} catch (Throwable $e) {
|
|
$dbError = $e->getMessage();
|
|
}
|
|
}
|
|
require __DIR__ . '/includes/header.php';
|
|
?>
|
|
<section class="surface-card mb-4">
|
|
<?php if ($dbError): ?>
|
|
<div class="alert alert-warning"><?= h($dbError) ?></div>
|
|
<?php elseif (!$sale): ?>
|
|
<div class="empty-state">
|
|
<h4><?= h(tr('الفاتورة غير موجودة', 'Sale not found')) ?></h4>
|
|
<p><?= h(tr('قد تكون الفاتورة خارج صلاحية هذا الحساب أو لم تعد موجودة.', 'The sale may be outside this account scope or no longer exists.')) ?></p>
|
|
<a class="btn btn-outline-secondary" href="<?= h(url_for('sales.php')) ?>"><?= h(tr('العودة إلى المبيعات', 'Back to sales')) ?></a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="d-flex justify-content-between align-items-start gap-3 flex-wrap mb-4">
|
|
<div>
|
|
<div class="eyebrow"><?= h(sale_mode_label((string) $sale['sale_mode'])) ?></div>
|
|
<h3 class="h4 mb-1"><?= h($sale['receipt_no']) ?></h3>
|
|
<div class="small text-muted"><?= h(branch_label((string) $sale['branch_code'])) ?> · <?= h(date('Y-m-d H:i', strtotime((string) $sale['sale_date']))) ?></div>
|
|
</div>
|
|
<div class="d-flex gap-2 flex-wrap">
|
|
<button type="button" class="btn btn-dark" data-print-page><?= h(tr('طباعة الإيصال', 'Print receipt')) ?></button>
|
|
<a class="btn btn-outline-secondary" href="<?= h(url_for('sales.php')) ?>"><?= h(tr('العودة للسجل', 'Back to ledger')) ?></a>
|
|
</div>
|
|
</div>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-3"><div class="detail-card"><span><?= h(tr('العميل', 'Customer')) ?></span><strong><?= h((string) ($sale['customer_name'] ?: tr('دون اسم', 'Walk-in'))) ?></strong></div></div>
|
|
<div class="col-md-3"><div class="detail-card"><span><?= h(tr('الدفع', 'Payment')) ?></span><strong><?= h(ucfirst((string) $sale['payment_method'])) ?></strong></div></div>
|
|
<div class="col-md-3"><div class="detail-card"><span><?= h(tr('الكاشير', 'Cashier')) ?></span><strong><?= h((string) $sale['cashier_name']) ?></strong></div></div>
|
|
<div class="col-md-3"><div class="detail-card"><span><?= h(tr('الإجمالي', 'Total')) ?></span><strong><?= h(currency((float) $sale['total_amount'])) ?></strong></div></div>
|
|
</div>
|
|
<div class="table-responsive mb-4">
|
|
<table class="table app-table align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th><?= h(tr('الصنف', 'Item')) ?></th>
|
|
<th><?= h(tr('الكمية', 'Qty')) ?></th>
|
|
<th><?= h(tr('السعر', 'Price')) ?></th>
|
|
<th><?= h(tr('الإجمالي', 'Line total')) ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($sale['items'] as $item): ?>
|
|
<tr>
|
|
<td><?= h(current_lang() === 'ar' ? ($item['name_ar'] ?? $item['sku']) : ($item['name_en'] ?? $item['sku'])) ?></td>
|
|
<td><?= h((string) ($item['qty'] ?? 0)) ?></td>
|
|
<td><?= h(currency((float) ($item['price'] ?? 0))) ?></td>
|
|
<td><?= h(currency((float) ($item['line_total'] ?? 0))) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php if (!empty($sale['notes'])): ?>
|
|
<div class="alert alert-light border mb-0"><strong><?= h(tr('ملاحظات:', 'Notes:')) ?></strong> <?= h((string) $sale['notes']) ?></div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</section>
|
|
<?php require __DIR__ . '/includes/footer.php'; ?>
|