Server IP : 162.214.80.37 / Your IP : 216.73.216.83 Web Server : Apache System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : imyrqtmy ( 2189) PHP Version : 8.2.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home2/imyrqtmy/public_html/destinytrafficsolutions/admin/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php error_reporting(E_ERROR | E_PARSE); require_once('tcpdf/tcpdf.php'); if (isset($_GET['invoice_number'])) { include("inc/config.php"); $invoice_number = $_GET['invoice_number']; // Fetch invoice details $query = "SELECT * FROM invoices WHERE invoice_number='$invoice_number'"; $query_run = mysqli_query($conn, $query); $row = mysqli_fetch_assoc($query_run); if (!$row) { die('Invoice not found.'); } // Create new PDF instance $pdf = new TCPDF(); // Set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetTitle('Invoice ' . $invoice_number); // Set margins $pdf->SetMargins(15, 20, 15); // Add a page $pdf->AddPage(); // Set font $pdf->SetFont('helvetica', '', 12); // Title $pdf->Cell(0, 10, "INVOICE ", 0, 1, 'C'); $pdf->Ln(5); // Line break // Add the invoice details and logo $pdf->SetFont('helvetica', '', 10); $pdf->SetX(15); // Set X position for the invoice details // Invoice details block $pdf->MultiCell(120, 6, "{$row['own_company']}\n{$row['own_gst']}\n{$row['own_phone']}\n{$row['own_email']}", 0, 'L', 0, 0 ); // Logo block $pdf->Image('dist/images/logo-v2.png', 140, $pdf->GetY(), 40, 20, '', '', '', false, 300); $pdf->Ln(30); // Line break // Add the "Billed To" and invoice details $pdf->SetFont('helvetica', '', 10); $pdf->SetX(15); // Set X position for the invoice details // Invoice details block $pdf->MultiCell(120, 6, "BILL TO\n{$row['cli_company']}\n{$row['cli_gst']}\n{$row['cli_phone']}\n{$row['cli_email']}", 0, 'L', 0, 0 ); // Invoice and due date block $pdf->MultiCell(120, 6, "Invoice No: {$row['invoice_number']}\nInvoice Date: {$row['invoice_date']}\nDue Date: {$row['due_date']}", 0, 'L', 0, 0 ); $pdf->Ln(30); // Line break // Set up table headings $pdf->SetFont('helvetica', '', 9); // Reduced font size $pdf->SetTextColor(0, 0, 0); // Set text color to black // Headings with background color $pdf->SetFillColor(240, 240, 240); // Light gray background for headings $pdf->Cell(20, 8, "DATE", 0, 0, 'C', true); $pdf->Cell(50, 8, "PRODUCT NAME", 0, 0, 'C', true); $pdf->Cell(50, 8, "DESCRIPTION", 0, 0, 'C', true); // $pdf->Cell(25, 8, "TAX", 0, 0, 'C', true); $pdf->Cell(20, 8, "QTY", 0, 0, 'C', true); $pdf->Cell(20, 8, "RATE", 0, 0, 'C', true); $pdf->Cell(30, 8, "AMOUNT", 0, 1, 'C', true); $pdf->SetFont('helvetica', '', 10); // Fetch product data for the invoice // Fetch product data for the invoice $products_query = "SELECT * FROM invoices WHERE invoice_number='$invoice_number'"; $products_run = mysqli_query($conn, $products_query); $pdf->SetFillColor(255, 255, 255); // Reset fill color $subtotal = 0; $gst_total = 0; $qst_total = 0; // Loop through each product entry while ($product = mysqli_fetch_assoc($products_run)) { $product_names = json_decode($product['product_names'], true); // Decode JSON $descriptions = json_decode($product['descriptions'], true); // Decode JSON $quantities = json_decode($product['quantities'], true); // Decode JSON $prices = json_decode($product['prices'], true); // Decode JSON if (!is_array($product_names)) { $product_names = [$product['product_names']]; } if (!is_array($descriptions)) { $descriptions = [$product['descriptions']]; } if (!is_array($quantities)) { $quantities = [$product['quantities']]; } if (!is_array($prices)) { $prices = [$product['prices']]; } for ($i = 0; $i < count($product_names); $i++) { $quantity = isset($quantities[$i]) ? $quantities[$i] : 1; $price = isset($prices[$i]) ? $prices[$i] : 0; $description = isset($descriptions[$i]) ? $descriptions[$i] : '-'; $product_name = isset($product_names[$i]) ? $product_names[$i] : '-'; $amount = $quantity * $price; $gst = $amount * (5 / 100); $qst = $amount * (9.975 / 100); $subtotal += $amount; $gst_total += $gst; $qst_total += $qst; // Output product row in the table $pdf->Cell(20, 8, "{$product['invoice_date']}", 0, 0, 'C'); $pdf->Cell(50, 8, "{$product_name}", 0, 0, 'C'); $pdf->Cell(50, 8, "{$description}", 0, 0, 'C'); $pdf->Cell(20, 8, "{$quantity}", 0, 0, 'C'); $pdf->Cell(20, 8, "{$price}", 0, 0, 'C'); $pdf->Cell(30, 8, "{$amount}", 0, 1, 'C'); } } // Pricing Section with Dotted Lines // Pricing Section with Dotted Lines $pdf->Ln(10); // Line break before the section // Set font styles for sections $pdf->SetFont('helvetica', 'B', 10); $pdf->SetLineStyle(array('width' => 0.2, 'dash' => '2,2', 'color' => array(0, 0, 0))); // Dotted line style // SUBTOTAL $labelWidth = 140; // Width for label (e.g., "SUBTOTAL") $amountWidth = 40; // Width for amount (e.g., amount value) $pdf->Cell($labelWidth, 8, "SUBTOTAL", 0, 0, 'R'); // Label aligned to the right $pdf->Cell($amountWidth, 8, number_format($subtotal, 2), 0, 1, 'R'); // Amount aligned to the right // Dotted Line $pdf->Cell(0, 0, '', 'T', 1, 'C'); // Full-width dotted line // GST $pdf->Cell($labelWidth, 8, "GST @ 5%", 0, 0, 'R'); // Label aligned to the right $pdf->Cell($amountWidth, 8, number_format($gst_total, 2), 0, 1, 'R'); // Amount aligned to the right // Dotted Line $pdf->Cell(0, 0, '', 'T', 1, 'C'); // Full-width dotted line // QST $pdf->Cell($labelWidth, 8, "QST @ 9.975%", 0, 0, 'R'); // Label aligned to the right $pdf->Cell($amountWidth, 8, number_format($qst_total, 2), 0, 1, 'R'); // Amount aligned to the right // Dotted Line $pdf->Cell(0, 0, '', 'T', 1, 'C'); // Full-width dotted line // TOTAL $pdf->SetFont('helvetica', 'B', 10); $pdf->Cell($labelWidth, 8, "TOTAL", 0, 0, 'R'); // Label aligned to the right $pdf->Cell($amountWidth, 8, number_format($subtotal + $gst_total + $qst_total, 2), 0, 1, 'R'); // Total amount // Add TAX SUMMARY Section $pdf->Ln(15); // Line break before the new section $pdf->SetFont('helvetica', 'B', 12); $pdf->Cell(0, 10, "TAX SUMMARY", 0, 1, 'C'); // Title centered // Set font and color for headings $pdf->SetFont('helvetica', '', 9); $pdf->SetFillColor(240, 240, 240); // Light gray background for headings $pdf->Cell(60, 8, "RATE", 0, 0, 'C', true); $pdf->Cell(60, 8, "TAX", 0, 0, 'C', true); $pdf->Cell(60, 8, "NET", 0, 1, 'C', true); // Move to next line // Set font for data rows $pdf->SetFont('helvetica', '', 10); $pdf->SetFillColor(255, 255, 255); // Reset fill color // Add rows for TAX SUMMARY $pdf->Cell(60, 8, "GST @ 5%", 0, 0, 'C'); $pdf->Cell(60, 8, number_format($gst_total, 2), 0, 0, 'C'); $pdf->Cell(60, 8, number_format($subtotal + $gst_total + $qst_total, 2), 0, 1, 'C'); // Move to next line $pdf->Cell(60, 8, "QST @ 9.975%", 0, 0, 'C'); $pdf->Cell(60, 8, number_format($qst_total, 2), 0, 0, 'C'); $pdf->Cell(60, 8, number_format($subtotal + $gst_total + $qst_total, 2), 0, 1, 'C'); // Move to next line $pdf->Output('invoice_' . $invoice_number . '.pdf', 'I'); } ?>