« Back to History
jobwork_send_view.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php ini_set('display_errors', 1); error_reporting(E_ALL); /* ================= DOMPDF NAMESPACE (TOP ONLY) ================= */ use Dompdf\Dompdf; use Dompdf\Options; /* ================= AUTH ================= */ require_once __DIR__ . '/../modules/auth/page_acl.php'; $ctx = page_require_access('jobwork_send', []); // 🔒 mandatory $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; /* ================= INPUT ================= */ $challan_no = $_GET['challan_no'] ?? ''; $is_pdf = isset($_GET['pdf']); if ($challan_no === '') { die('Invalid access'); } /* ================= LOAD DOMPDF ONLY IF NEEDED ================= */ if ($is_pdf) { require_once __DIR__ . '/../lib/dompdf/autoload.inc.php'; } /* ================= COMPANY ================= */ $st = $pdo->prepare("SELECT name FROM companies WHERE id = ?"); $st->execute([$company_id]); $company = $st->fetch(PDO::FETCH_ASSOC); $company_name = $company['name'] ?? 'Company'; /* ================= HEADER ================= */ $st = $pdo->prepare(" SELECT challan_no, challan_date, party_name FROM chalan_data WHERE company_id = ? AND challan_no = ? "); $st->execute([$company_id, $challan_no]); $header = $st->fetch(PDO::FETCH_ASSOC); if (!$header) { die('Challan not found'); } /* ================= ITEMS ================= */ $st = $pdo->prepare(" SELECT stock_type, yarn_type, company, denier, color, boxes, weight FROM jobwork_send WHERE company_id = ? AND challan_no = ? "); $st->execute([$company_id, $challan_no]); $items = $st->fetchAll(PDO::FETCH_ASSOC); /* ================= TOTAL ================= */ $total_boxes = 0; $total_weight = 0; foreach ($items as $r) { $total_boxes += (float)$r['boxes']; $total_weight += (float)$r['weight']; } /* ================= HTML ================= */ ob_start(); ?> <!DOCTYPE html> <html> <head> <style> @page { size:A4; margin:15mm; } body { font-family: Arial, sans-serif; font-size:12px; } table { width:100%; border-collapse:collapse; } th,td { border:1px solid #000; padding:6px; text-align:center; } .no-print { text-align:right; margin-bottom:15px; } @media print { .no-print { display:none; } } </style> </head> <body> <?php if (!$is_pdf): ?> <div class="no-print"> <button onclick="window.print()">🖨 Print</button> <a href="?challan_no=<?= $challan_no ?>&pdf=1">📄 PDF</a> </div> <?php endif; ?> <h2 style="text-align:center"><?= htmlspecialchars($company_name) ?></h2> <h3 style="text-align:center">JOB WORK CHALLAN</h3> <table style="border:none;margin-bottom:15px"> <tr> <td style="border:none"> <b>Job Work Party:</b><br> <?= htmlspecialchars($header['party_name']) ?> </td> <td style="border:none;text-align:right"> <b>Challan No:</b> <?= $header['challan_no'] ?><br> <b>Date:</b> <?= date('d-m-Y', strtotime($header['challan_date'])) ?> </td> </tr> </table> <table> <tr> <th>Sr</th> <th>Stock</th> <th>Yarn</th> <th>Company</th> <th>Denier</th> <th>Color</th> <th>Boxes</th> <th>Weight</th> </tr> <?php foreach ($items as $i=>$r): ?> <tr> <td><?= $i+1 ?></td> <td><?= htmlspecialchars($r['stock_type']) ?></td> <td><?= htmlspecialchars($r['yarn_type']) ?></td> <td><?= htmlspecialchars($r['company']) ?></td> <td><?= htmlspecialchars($r['denier']) ?></td> <td><?= htmlspecialchars($r['color']) ?></td> <td><?= $r['boxes'] ?></td> <td><?= number_format($r['weight'],2) ?></td> </tr> <?php endforeach; ?> <tr> <th colspan="6">TOTAL</th> <th><?= $total_boxes ?></th> <th><?= number_format($total_weight,2) ?></th> </tr> </table> <br><br> <table style="border:none"> <tr> <td style="border:none;text-align:center">Prepared By</td> <td style="border:none;text-align:center">Received By</td> <td style="border:none;text-align:center">Authorized Sign</td> </tr> </table> </body> </html> <?php $html = ob_get_clean(); /* ================= OUTPUT ================= */ if ($is_pdf) { $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper('A4','portrait'); $dompdf->render(); $dompdf->stream("JobWork_Challan_$challan_no.pdf", ["Attachment"=>1]); } else { echo $html; }