diff --git a/pages-invoice.php b/pages-invoice.php index 68b5d343..9a1f79b4 100644 --- a/pages-invoice.php +++ b/pages-invoice.php @@ -237,68 +237,7 @@ function fetchInvoiceItems($invoice_id) { $stmt->execute(); $invoice = $stmt->fetch(PDO::FETCH_ASSOC); - // Handle PDF generation (GET request for invoice) -if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['invoice_id'])) { - // Sanitize the input - $invoice_id = filter_var($_GET['invoice_id'], FILTER_SANITIZE_NUMBER_INT); - // Fetch the invoice details - $query = "SELECT * FROM invoices WHERE invoice_id = :invoice_id"; - $stmt = $connection->prepare($query); - $stmt->bindParam(':invoice_id', $invoice_id, PDO::PARAM_INT); - $stmt->execute(); - $invoice = $stmt->fetch(PDO::FETCH_ASSOC); - - // Check if the invoice was found - if ($invoice) { - // Fetch the invoice items - $queryItems = "SELECT * FROM invoice_items WHERE invoice_id = :invoice_id"; - $stmtItems = $connection->prepare($queryItems); - $stmtItems->bindParam(':invoice_id', $invoice_id, PDO::PARAM_INT); - $stmtItems->execute(); - $items = $stmtItems->fetchAll(PDO::FETCH_ASSOC); - - // Initialize the PDF document - $pdf = new FPDF(); - $pdf->AddPage(); - - // Set up title and invoice details - $pdf->SetFont('Arial', 'B', 16); - $pdf->Cell(0, 10, 'Invoice', 0, 1, 'C'); - $pdf->SetFont('Arial', 'I', 12); - $pdf->Cell(0, 10, 'Invoice Number: ' . htmlspecialchars($invoice['invoice_number']), 0, 1); - $pdf->Cell(0, 10, 'Customer Name: ' . htmlspecialchars($invoice['customer_name']), 0, 1); - $pdf->Cell(0, 10, 'Order Date: ' . htmlspecialchars($invoice['order_date']), 0, 1); - $pdf->Cell(0, 10, 'Total Amount: $' . number_format($invoice['total_amount'], 2), 0, 1); - $pdf->Ln(10); - - // Set up table header for items - $pdf->SetFont('Arial', 'B', 12); - $pdf->Cell(80, 10, 'Item Name', 1); - $pdf->Cell(30, 10, 'Quantity', 1); - $pdf->Cell(30, 10, 'Price', 1); - $pdf->Cell(30, 10, 'Total', 1); - $pdf->Ln(); - - // Set up table data for each item - $pdf->SetFont('Arial', '', 12); - foreach ($items as $item) { - $total = $item['quantity'] * $item['price']; // Calculate total for each item - $pdf->Cell(80, 10, htmlspecialchars($item['item_name']), 1); - $pdf->Cell(30, 10, number_format((float)$item['quantity']), 1); // Format quantity - $pdf->Cell(30, 10, '$' . number_format((float)$item['price'], 2), 1); - $pdf->Cell(30, 10, '$' . number_format((float)$total, 2), 1); - $pdf->Ln(); - } - - // Output the PDF as a download - $pdf->Output('D', 'Invoice_' . htmlspecialchars($invoice['invoice_number']) . '.pdf'); - exit; - } else { - echo 'Invoice not found.'; - exit; - } -} } @@ -808,9 +747,7 @@ class="rounded-top img-fluid mb-4">
- + @@ -836,99 +773,6 @@ class="rounded-top img-fluid mb-4">
- - - - -