« Back to History
cms_detail_print.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('cms_detail_print'); if (!class_exists(\Dompdf\Dompdf::class)) { foreach ([ __DIR__ . '/lib/dompdf/autoload.inc.php', __DIR__ . '/vendor/autoload.php', ] as $dompdfAutoload) { if (is_file($dompdfAutoload)) { require_once $dompdfAutoload; if (class_exists(\Dompdf\Dompdf::class)) { break; } } } } $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; if (!function_exists('h')) { function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } } if (!function_exists('render_cms_detail_report_html')) { function render_cms_detail_report_html(array $row, array $items, int $total, string $monthLabel, int $id, bool $isPdf = false): string { $pdfUrl = '?'.http_build_query([ 'id' => $id, 'export' => 'pdf', ]); ob_start(); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CMS Detail<?= $isPdf ? ' PDF' : ' Preview' ?></title> <style> body { font-family: Arial, sans-serif; margin: <?= $isPdf ? '18px' : '24px' ?>; color: #000; } .actions { margin-bottom: 18px; text-align: right; } .actions button, .actions a { display: inline-block; border: 1px solid #111; background: #111; color: #fff; padding: 8px 14px; text-decoration: none; font-size: 13px; line-height: 1.2; cursor: pointer; margin-left: 8px; } h1 { text-align: center; margin-bottom: 6px; font-size: <?= $isPdf ? '22px' : '28px' ?>; } .sub { text-align: center; margin-bottom: 20px; font-size: <?= $isPdf ? '12px' : '14px' ?>; } table { width: 100%; border-collapse: collapse; font-size: <?= $isPdf ? '12px' : '14px' ?>; } th, td { border: 1px solid #000; padding: <?= $isPdf ? '7px 8px' : '8px 10px' ?>; } th { text-align: right; width: 30%; } td { text-align: left; } .total-row th, .total-row td { font-weight: bold; border-top: 2px solid #000; } .remarks { margin-top: 16px; font-size: <?= $isPdf ? '12px' : '14px' ?>; } <?php if (!$isPdf): ?> @media print { body { margin: 0; } .actions { display: none; } } <?php else: ?> @page { margin: 16px; } <?php endif; ?> </style> </head> <body> <?php if (!$isPdf): ?> <div class="actions"> <button type="button" onclick="window.print()">Print</button> <a href="<?= h($pdfUrl) ?>">Export PDF</a> </div> <?php endif; ?> <h1>Maa Sharda Textiles : CMS Detail</h1> <div class="sub"> <?= h($row['year']) ?> | <?= h($monthLabel) ?> <?= h($row['period']) ?> </div> <table> <?php foreach ($items as $name => $amount): ?> <tr> <th><?= h(number_format($amount)) ?></th> <td><?= h($name) ?></td> </tr> <?php endforeach; ?> <tr class="total-row"> <th><?= h(number_format($total)) ?></th> <td>TOTAL</td> </tr> </table> <?php if (!empty($row['remarks'])): ?> <div class="remarks"> <strong>Remarks:</strong> <?= h($row['remarks']) ?> </div> <?php endif; ?> </body> </html> <?php return (string)ob_get_clean(); } } $id = (int)($_GET['id'] ?? 0); if ($id <= 0) { exit('Invalid CMS ID'); } $stmt = $pdo->prepare(" SELECT * FROM cms_detail WHERE id = :id AND company_id = :cid LIMIT 1 "); $stmt->execute([ ':id' => $id, ':cid' => $company_id ]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { exit('CMS Detail not found'); } /* ---------- Labels ---------- */ $monthLabel = date('M', mktime(0, 0, 0, (int)$row['month'], 1)); /* ---------- Amounts ---------- */ $items = [ 'Warper' => (int)$row['warper_amount'], 'Pasaria' => (int)$row['pasaria_amount'], 'Pissing' => (int)$row['pissing_amount'], 'Loom Karigar Salary' => (int)$row['loom_salary_amount'], 'Monthly Salary' => (int)$row['monthly_salary_amount'], 'Semi Monthly Salary' => (int)$row['semi_monthly_salary_amount'], ]; $total = array_sum($items); if (($_GET['export'] ?? '') === 'pdf') { if (!class_exists(\Dompdf\Dompdf::class)) { http_response_code(503); exit('PDF export is not available right now.'); } $dompdf = new \Dompdf\Dompdf([ 'isRemoteEnabled' => false, 'defaultFont' => 'DejaVu Sans', ]); $dompdf->loadHtml(render_cms_detail_report_html($row, $items, $total, $monthLabel, $id, true), 'UTF-8'); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $dompdf->stream('cms_detail_' . $id . '.pdf', ['Attachment' => true]); exit; } echo render_cms_detail_report_html($row, $items, $total, $monthLabel, $id);