D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
inventory.tapaslights.com
/
Filename :
export_pdf.php
back
Copy
<?php require 'vendor/autoload.php'; // adjust path if not using Composer include 'config.php'; use Dompdf\Dompdf; use Dompdf\Options; $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); // Get filters $conditions = []; if (!empty($_GET['from_date'])) { $from = $_GET['from_date'] . " 00:00:00"; $conditions[] = "created_at >= '" . $conn->real_escape_string($from) . "'"; } if (!empty($_GET['to_date'])) { $to = $_GET['to_date'] . " 23:59:59"; $conditions[] = "created_at <= '" . $conn->real_escape_string($to) . "'"; } if (!empty($_GET['transaction_type'])) { $conditions[] = "transaction_type = '" . $conn->real_escape_string($_GET['transaction_type']) . "'"; } $whereClause = $conditions ? "WHERE " . implode(" AND ", $conditions) : ""; $query = "SELECT * FROM material_transactions $whereClause ORDER BY created_at DESC"; $result = $conn->query($query); // Build HTML for PDF $html = '<h2>Material Transactions</h2>'; $html .= '<table border="1" cellspacing="0" cellpadding="5" width="100%"> <thead> <tr> <th>Date</th> <th>Material Name</th> <th>Type</th> <th>Qty</th> <th>Unit</th> <th>Price/Unit</th> <th>Total</th> </tr> </thead> <tbody>'; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $html .= '<tr> <td>' . date('d M Y, h:i A', strtotime($row['created_at'])) . '</td> <td>' . htmlspecialchars($row['material_name']) . '</td> <td>' . ucfirst($row['transaction_type']) . '</td> <td>' . $row['quantity'] . '</td> <td>' . htmlspecialchars($row['unit']) . '</td> <td>Rs.' . number_format($row['price_per_unit'], 2) . '</td> <td>Rs.' . number_format($row['total_price'], 2) . '</td> </tr>'; } } else { $html .= '<tr><td colspan="7" align="center">No data found.</td></tr>'; } $html .= '</tbody></table>'; // Load HTML and render PDF $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); // Direct download (force download) $dompdf->stream("material_transactions.pdf", ["Attachment" => 1]); exit;