110 lines
5.7 KiB
PHP
110 lines
5.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/app.php';
|
|
require_permission('documents');
|
|
|
|
$document = isset($_GET['id']) ? fetch_sales_document_by_id((int)$_GET['id']) : null;
|
|
if (!$document) {
|
|
http_response_code(404);
|
|
exit('Document not found');
|
|
}
|
|
|
|
$payload = $document['payload_data'];
|
|
$documentLabel = sales_document_label((string)$document['record_type']);
|
|
$documentSubtitle = match ((string)$document['record_type']) {
|
|
'sales_quote' => 'عرض سعر قابل للطباعة والحفظ PDF من المتصفح',
|
|
'sales_order' => 'أمر بيع مؤكد وقابل للطباعة أو الحفظ PDF',
|
|
'delivery_note' => 'أمر تسليم جاهز للطباعة مع بيانات العميل والصنف',
|
|
'sales_invoice' => 'فاتورة مبيعات أولية قابلة للطباعة أو الحفظ PDF',
|
|
default => 'مستند مبيعات قابل للطباعة',
|
|
};
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? ('Printable ' . $documentLabel);
|
|
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="ar" dir="rtl">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title><?= e($document['code']) ?> | <?= e(app_name()) ?></title>
|
|
<meta name="description" content="<?= e($projectDescription) ?>">
|
|
<meta name="robots" content="noindex, nofollow">
|
|
<?php if ($projectDescription): ?>
|
|
<meta property="og:description" content="<?= e($projectDescription) ?>">
|
|
<meta property="twitter:description" content="<?= e($projectDescription) ?>">
|
|
<?php endif; ?>
|
|
<?php if ($projectImageUrl): ?>
|
|
<meta property="og:image" content="<?= e($projectImageUrl) ?>">
|
|
<meta property="twitter:image" content="<?= e($projectImageUrl) ?>">
|
|
<?php endif; ?>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.rtl.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
|
</head>
|
|
<body class="print-body">
|
|
<main class="container py-4">
|
|
<div class="print-sheet mx-auto">
|
|
<div class="d-flex justify-content-between align-items-start border-bottom pb-3 mb-4">
|
|
<div>
|
|
<div class="print-eyebrow">Printable Sales Document</div>
|
|
<h1 class="h3 mb-1"><?= e(app_name()) ?></h1>
|
|
<div class="text-secondary"><?= e($documentLabel) ?> — <?= e($documentSubtitle) ?></div>
|
|
</div>
|
|
<div class="text-start">
|
|
<div class="fw-semibold"><?= e($document['code']) ?></div>
|
|
<div class="text-secondary small"><?= e($payload['created_date'] ?? '') ?></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4 mb-4">
|
|
<div class="col-md-6">
|
|
<div class="subtle-card h-100">
|
|
<div class="detail-label mb-2">بيانات العميل</div>
|
|
<div class="fw-semibold"><?= e($payload['customer_name'] ?? '') ?></div>
|
|
<div class="text-secondary small">الفرع: <?= e($payload['branch'] ?? '') ?></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="subtle-card h-100">
|
|
<div class="detail-label mb-2">بيانات المستند</div>
|
|
<div class="small">الحالة: <?= e(order_status_label((string)$document['status'])) ?></div>
|
|
<div class="small">نوع المستند: <?= e($documentLabel) ?></div>
|
|
<?php if (!empty($payload['source_document_code'])): ?>
|
|
<div class="small">المصدر: <?= e((string)$payload['source_document_label']) ?> — <?= e((string)$payload['source_document_code']) ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive mb-4">
|
|
<table class="table app-table mb-0">
|
|
<thead><tr><th>الصنف</th><th>SKU</th><th>الكمية</th><th>سعر الوحدة</th><th>الإجمالي</th></tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><?= e($payload['product_name'] ?? '') ?></td>
|
|
<td><?= e($payload['sku'] ?? '') ?></td>
|
|
<td><?= e((string)($payload['qty'] ?? 0)) ?> <?= e($payload['unit'] ?? '') ?></td>
|
|
<td><?= e(format_money((float)($payload['unit_price'] ?? 0))) ?></td>
|
|
<td><?= e(format_money((float)($payload['subtotal'] ?? 0))) ?></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="row justify-content-end mb-4">
|
|
<div class="col-md-5">
|
|
<div class="sales-summary-box">
|
|
<div class="summary-row"><span>الإجمالي قبل الضريبة</span><strong><?= e(format_money((float)($payload['subtotal'] ?? 0))) ?></strong></div>
|
|
<div class="summary-row"><span>الضريبة 15%</span><strong><?= e(format_money((float)($payload['vat'] ?? 0))) ?></strong></div>
|
|
<div class="summary-row grand"><span>الإجمالي النهائي</span><strong><?= e(format_money((float)($payload['grand_total'] ?? 0))) ?></strong></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-4 mt-4 pt-4 border-top"><div class="col-md-6"><div class="signature-box">توقيع المبيعات</div></div><div class="col-md-6"><div class="signature-box"><?= e($document['record_type'] === 'delivery_note' ? 'توقيع المستلم' : 'توقيع العميل') ?></div></div></div>
|
|
<?php if (!empty($payload['notes'])): ?><div class="subtle-card mt-4"><div class="detail-label mb-2">ملاحظات</div><div><?= e($payload['notes']) ?></div></div><?php endif; ?>
|
|
<div class="d-print-none mt-4 d-flex gap-2 justify-content-end"><a href="sales_orders.php?id=<?= (int)$document['id'] ?>" class="btn btn-outline-secondary">العودة</a><button class="btn btn-dark" onclick="window.print()">طباعة / حفظ PDF</button></div>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|