D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
kk.encodersunlimited.com
/
Filename :
export_pdf.php
back
Copy
<?php require 'vendor/autoload.php'; use Dompdf\Dompdf; use Dompdf\Options; // Initialize dompdf $options = new Options(); $options->set('isHtml5ParserEnabled', true); $options->set('isPhpEnabled', true); $dompdf = new Dompdf($options); // Connect to the database include('config.php'); // Get filter values $startDate = isset($_GET['startDate']) ? $_GET['startDate'] : ''; $endDate = isset($_GET['endDate']) ? $_GET['endDate'] : ''; // Build query based on filter $query = "SELECT od.id, p.name, c.category_name, od.gold_weight, od.diamond_weight, od.making_charge, od.profit_percentage, od.total_cost, od.created_at FROM order_details od JOIN products p ON od.product_id = p.id JOIN category c ON od.category_id = c.id"; if ($startDate && $endDate) { $query .= " WHERE od.created_at BETWEEN '$startDate' AND '$endDate'"; } $result = mysqli_query($conn, $query); // Generate HTML content $html = '<html> <head> <style> table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <h1>Sales Report</h1> <table> <thead> <tr> <th>ID</th> <th>Product Name</th> <th>Category</th> <th>Gold Weight</th> <th>Diamond Weight</th> <th>Making Charge</th> <th>Profit %</th> <th>Total Cost</th> <th>Date</th> </tr> </thead> <tbody>'; while ($item = mysqli_fetch_assoc($result)) { $html .= '<tr> <td>' . $item['id'] . '</td> <td>' . $item['name'] . '</td> <td>' . $item['category_name'] . '</td> <td>' . $item['gold_weight'] . '</td> <td>' . $item['diamond_weight'] . '</td> <td>' . $item['making_charge'] . '</td> <td>' . $item['profit_percentage'] . '</td> <td>' . $item['total_cost'] . '</td> <td>' . date('Y-m-d', strtotime($item['created_at'])) . '</td> </tr>'; } $html .= '</tbody> </table> </body> </html>'; // Load HTML content $dompdf->loadHtml($html); // (Optional) Set paper size and orientation $dompdf->setPaper('A4', 'landscape'); // Render PDF (first pass to get page size) $dompdf->render(); // Output the generated PDF (force download) $dompdf->stream("sales_report.pdf", array("Attachment" => true)); ?>