:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/kreativecrm/**
:: Editing File: invoice_pdf.php
<?php require_once('tcpdf_min/tcpdf.php'); include('config/db.php'); if (!isset($_GET['id'])) { die("No invoice ID found."); } $invoice_id = intval($_GET['id']); if ($invoice_id <= 0) { die("Invalid Invoice ID"); } // Fetch invoice + client details $sql = "SELECT i.*, c.name AS client_name, c.address AS client_address, c.phone AS client_contact FROM invoices i LEFT JOIN clients c ON i.client_id = c.id WHERE i.id = $invoice_id"; $result = mysqli_query($conn, $sql); $invoice = mysqli_fetch_assoc($result); if (!$invoice) { die("Invoice not found."); } // Fetch invoice items $items_q = mysqli_query($conn, "SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY id ASC"); // Calculations & safe variables $advance_amount = isset($invoice['advance_amount']) ? (float)$invoice['advance_amount'] : 0.00; $grand_total = isset($invoice['grand_total']) ? (float)$invoice['grand_total'] : 0.00; $balance_due = $grand_total - $advance_amount; // Convert number to words (kept from your code) function convert_number_to_words($number) { $hyphen = '-'; $conjunction = ' and '; $separator = ', '; $negative = 'negative '; $decimal = ' point '; $dictionary = array( 0 => 'Zero', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight', 9 => 'Nine', 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen', 16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen', 19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty', 40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty', 70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninety', 100 => 'Hundred', 1000 => 'Thousand', 100000 => 'Lakh', 10000000 => 'Crore' ); if (!is_numeric($number)) return false; if (($number >= 0 && (int)$number < 0) || (int)$number < 0 - PHP_INT_MAX) return 'Overflow'; if ($number < 0) return $negative . convert_number_to_words(abs($number)); $string = $fraction = null; if (strpos($number, '.') !== false) list($number, $fraction) = explode('.', $number); switch (true) { case $number < 21: $string = $dictionary[$number]; break; case $number < 100: $tens = ((int) ($number / 10)) * 10; $units = $number % 10; $string = $dictionary[$tens]; if ($units) $string .= $hyphen . $dictionary[$units]; break; case $number < 1000: $hundreds = (int) ($number / 100); $remainder = $number % 100; $string = $dictionary[$hundreds] . ' ' . $dictionary[100]; if ($remainder) $string .= $conjunction . convert_number_to_words($remainder); break; default: $baseUnit = pow(1000, floor(log($number, 1000))); $numBaseUnits = (int) ($number / $baseUnit); $remainder = $number % $baseUnit; $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit]; if ($remainder) $string .= $remainder < 100 ? $conjunction : $separator; $string .= convert_number_to_words($remainder); break; } if (null !== $fraction && is_numeric($fraction)) { $string .= $decimal; $words = []; foreach (str_split((string) $fraction) as $number) $words[] = $dictionary[$number]; $string .= implode(' ', $words); } return ucfirst($string); } $amount_in_words = convert_number_to_words(round($grand_total)) . " Rupees only"; $invoice_date = !empty($invoice['invoice_date']) ? date('d-m-Y', strtotime($invoice['invoice_date'])) : ''; // Company Info $company_name = "Kreative Pixelz"; $company_address = "Navi Mumbai, India"; $company_email = "info@kreativepixelz.com"; $company_phone = "+91 90290 00000"; // Build client name/party block safely $client_name_html = ''; if (!empty($invoice['client_name'])) { $client_name_html .= '<strong>' . htmlspecialchars($invoice['client_name']) . '</strong>'; } if (!empty($invoice['party_name'])) { if (!empty($client_name_html)) $client_name_html .= ' — '; $client_name_html .= '<strong>' . htmlspecialchars($invoice['party_name']) . '</strong>'; } $client_address_html = nl2br(htmlspecialchars($invoice['client_address'] ?? '')); $client_contact_html = htmlspecialchars($invoice['client_contact'] ?? ''); // Build items HTML & totals $items_html = ''; $total = 0.00; $i = 1; while ($item = mysqli_fetch_assoc($items_q)) { $qty = (float)($item['quantity'] ?? 0); $price = (float)($item['price'] ?? 0); $tax_percent = isset($item['tax_percent']) ? (float)$item['tax_percent'] : 0; $amount = $qty * $price; $total += $amount; $desc = htmlspecialchars($item['description'] ?? '', ENT_QUOTES); $hsn = htmlspecialchars($item['hsn_code'] ?? '', ENT_QUOTES); $items_html .= "<tr> <td style='padding:6px;border:1px solid #ddd;'>{$i}</td> <td style='padding:6px;border:1px solid #ddd;'>{$desc}</td> <td style='padding:6px;border:1px solid #ddd;'>{$hsn}</td> <td style='padding:6px;border:1px solid #ddd;text-align:right'>{$qty}</td> <td style='padding:6px;border:1px solid #ddd;text-align:right'>" . number_format($price, 2) . "</td> <td style='padding:6px;border:1px solid #ddd;text-align:right'>{$tax_percent}%</td> <td style='padding:6px;border:1px solid #ddd;text-align:right'>" . number_format($amount, 2) . "</td> </tr>"; $i++; } // If there were no items ensure items_html has a placeholder row if (empty($items_html)) { $items_html = "<tr><td colspan='7' style='padding:8px;border:1px solid #ddd;text-align:center'>No items found.</td></tr>"; } // Formatted numbers for HEREDOC $total_formatted = number_format($total, 2); $sub_total_formatted = number_format($invoice['sub_total'] ?? 0, 2); $tax_total_formatted = number_format($invoice['tax_total'] ?? 0, 2); $advance_amount_formatted = number_format($advance_amount, 2); $grand_total_formatted = number_format($grand_total, 2); // QR helper (uses api.qrserver.com) function generateQRCodeDataURI($data, $size = 200) { $url = 'https://api.qrserver.com/v1/create-qr-code/?data=' . urlencode($data) . '&size=' . $size . 'x' . $size; $qr = @file_get_contents($url); if ($qr === false) return ''; return 'data:image/png;base64,' . base64_encode($qr); } // Prepare UPI / QR - customize UPI id and payee name $upi_id = "9768676862@ptsbi"; $payee_name = "Kreative Pixelz"; $amount_for_qr = number_format($total, 2, '.', ''); $note = "Invoice Payment - {$invoice['invoice_no']}"; $upi_string = "upi://pay?pa={$upi_id}&pn=" . rawurlencode($payee_name) . "&am={$amount_for_qr}&cu=INR&tn=" . rawurlencode($note); $qr_image_src = generateQRCodeDataURI($upi_string, 200); // If logo images don't show in TCPDF, use absolute path (example: __DIR__ . '/logo/logo.png') $logo_path = 'logo/logo.png'; if (!file_exists($logo_path)) { // try absolute (optional) $logo_path = __DIR__ . '/logo/logo.png'; if (!file_exists($logo_path)) $logo_path = ''; } // Build final HTML using HEREDOC (variables interpolated safely) $html = <<<HTML <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Invoice #{$invoice['invoice_no']} - {$company_name}</title> <style> body { font-family: 'Roboto', Arial, sans-serif; margin: 0; padding: 10px; background-color: #f4f4f4; } .invoice-container { max-width: 800px; margin: 0 auto; padding: 20px; background-color: #fff; border: 1px solid #ccc; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } /* Header Section */ .invoice-header { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 10px; border-bottom: 3px solid #000; margin-bottom: 15px; } .company-logo h1 { margin: 0; font-size: 28px; color: #000; } .company-info { text-align: right; font-size: 11px; } .company-info p { margin: 2px 0; } /* Title */ .invoice-title h2 { text-align: center; font-size: 20px; margin-top: 0; margin-bottom: 20px; padding: 3px 0; background-color: #12649c; color: #fff; } /* Details Section */ .details-section { display: flex; justify-content: space-between; margin-bottom: 15px; } .invoice-details, .client-details { width: 48%; padding: 5px 10px; border: 1px solid #ddd; font-size: 13px; } .section-title { font-weight: bold; border-bottom: 1px solid #eee; padding-bottom: 3px; margin-top: 0; color: #266c9c; } .invoice-details p, .client-details p { margin: 3px 0; } .client-name { margin-top: 5px; font-size: 15px; } /* Items Table */ .items-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; font-size: 12px; } .items-table th, .items-table td { border: 1px solid #ccc; padding: 6px; text-align: left; } .items-table th { background-color: #12649c; font-weight: bold; text-align: center; color: #fff; } .items-table td:nth-child(4), .items-table td:nth-child(6), .items-table td:nth-child(7) { text-align: right; } .total-row { font-weight: bold; background-color: #e5e5e5; } /* Summary Section */ .summary-section { display: flex; justify-content: space-between; margin-bottom: 15px; } .amount-words { width: 60%; padding: 5px 0; border-top: 1px solid #ccc; font-size: 13px; } .words-text { font-style: italic; font-size: 13px; } .amount-summary { width: 35%; } .summary-table { width: 100%; border-collapse: collapse; } .summary-table td { padding: 4px; border-bottom: 1px solid #eee; font-size: 13px; } .summary-table td:last-child { text-align: right; font-weight: bold; } .balance td { background-color: #e5e5e5; border-top: 2px solid #000; } /* Bank & Terms */ .bank-terms-section { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 20px; padding-top: 10px; border-top: 1px solid #ccc; } .terms { width: 30%; } .bank-details { width: 30%; font-size: 11px; } .bank-details p { margin: 2px 0; } .qr-code { width: 20%; text-align: center; font-weight: bold; } .sign-code { width: 20%; text-align: center; font-weight: bold; } .terms ul { list-style-type: disc; padding-left: 15px; font-size: 11px; } .terms li { margin-bottom: 2px; line-height: normal; } /* Acknowledgment Section */ .acknowledgement-section { margin-top: 20px; padding: 10px; border: 1px solid #000; } .acknowledgement-section .section-title { margin-bottom: 5px !important; padding-bottom: 3px; font-size: 14px; } .acknowledgement-section h2 { font-size: 18px !important; margin: 5px 0 !important; } .ack-details { display: flex; justify-content: space-between; align-items: flex-end; font-size: 12px; } .received-info, .ack-invoice-info, .ack-signature { width: 33%; } .received-info p, .ack-invoice-info p { margin: 2px 0; } .signature-line { border-bottom: 1px solid #000; margin-top: 20px; } .ack-invoice-info > div, .ack-signature > div { margin-top: 15px !important; } /* Footer */ .invoice-footer { text-align: right; margin-top: 20px; padding-top: 10px; border-top: 3px solid #000; font-size: 13px; } strong { color: #12649c; } .invoice-footer p { margin: 2px 0; } .thank-you { font-style: italic; text-align: center; margin-top: 10px !important; } /* Print Styles */ @media print { @page { margin: 0.5cm; } body { background-color: #fff; padding: 0; } .invoice-container { box-shadow: none; border: none; padding: 10px; } } /* Responsive */ @media (max-width: 600px) { .invoice-header, .details-section, .summary-section, .bank-terms-section { flex-direction: column; } .company-info { text-align: left; margin-top: 10px; } .invoice-details, .client-details, .amount-words, .amount-summary, .terms, .bank-details, .qr-code { width: 100%; margin-bottom: 10px; } } </style> </head> <body> <div class="invoice-container"> <header class="invoice-header"> <div class="company-logo"> HTML; if (!empty($logo_path) && file_exists($logo_path)) { // embed logo tag inside HTML safely $html .= "<img src=\"{$logo_path}\" alt=\"{$company_name} Logo\" style='width:100px'>"; } else { $html .= "<h2>{$company_name}</h2>"; } $html .= <<<HTML </div> <div class="company-info"> <strong>{$company_name}</strong><br> {$company_address}<br> Website: www.kreativepixelz.com<br> Phone: {$company_phone} / Email: {$company_email} </div> </header> <div class="invoice-title"> <h2>Tax Invoice</h2> </div> <div class="details-section"> <div class="invoice-details"> <p><strong>Invoice No.:</strong> {$invoice['invoice_no']}</p> <p><strong>Date:</strong> {$invoice_date}</p> <p><strong>Payment Type:</strong> {$invoice['payment_mode']}</p> </div> <div class="client-details"> <p class="section-title"><strong>Bill To / Invoice To</strong></p> <p class="client-name">{$client_name_html}</p> <p>{$client_address_html}</p> <p><strong>Contact:</strong> {$client_contact_html}</p> </div> </div> <table class="items-table" cellpadding="0" cellspacing="0"> <thead> <tr> <th style="width:4%">#</th> <th style="width:48%">Description</th> <th style="width:10%">HSN</th> <th style="width:8%">Qty</th> <th style="width:10%">Price</th> <th style="width:10%">Tax %</th> <th style="width:10%">Amount</th> </tr> </thead> <tbody> {$items_html} <tr class="total-row"> <td colspan="6" style="text-align:right;color:#12649c;"><strong>Total</strong></td> <td style="text-align:right;color:#12649c;"><strong>₹{$total_formatted}</strong></td> </tr> </tbody> </table> <div class="summary-section"> <div class="amount-words" style="width:60%;"> <p><strong>Invoice Amount In Words:</strong></p> <p>{$amount_in_words}</p> </div> <div class="amount-summary" style="width:35%;"> <table class="summary-table"> <tr><td>Sub Total</td><td style="text-align:right">₹{$sub_total_formatted}</td></tr> <tr><td>Tax Total</td><td style="text-align:right">₹{$tax_total_formatted}</td></tr> <tr><td>Advance Total</td><td style="text-align:right">₹{$advance_amount_formatted}</td></tr> <tr><td><strong>Grand Total</strong></td><td style="text-align:right"><strong>₹{$grand_total_formatted}</strong></td></tr> </table> </div> </div> <div class="bank-terms-section" style="margin-top:15px;"> <div style="width:60%;float:left;"> <p style="font-size:14px;"><strong>Terms and conditions</strong></p> <ul> <li>Amount once paid is not refundable.</li> <li>Balance payment has to be done within the stipulated timeline.</li> <li>Additional services except mentioned in quotation would charge extra.</li> <li>GST charges not applicable.</li> </ul> </div> <div style="width:35%;float:right;text-align:left;"> <p style="font-size:14px;"><strong>Bank Details</strong></p> <p><strong>Name:</strong> KOTAK MAHINDRA BANK LIMITED</p> <p><strong>Branch:</strong> Vashi, Navi Mumbai</p> <p><strong>Account No.:</strong> 9614545938</p> <p><strong>IFSC:</strong> KKBK0000669</p> <p><strong>Account Holder:</strong> Salil Dastagir Mulla</p> </div> <div style="clear:both;"></div> <div style="margin-top:12px;text-align:center;"> <p style="font-size:14px;"><strong>SCAN TO PAY</strong></p> <img src="{$qr_image_src}" width="120" height="120" alt="UPI QR Code"> <p style="font-size:12px;margin-top:6px;">Amount: ₹{$total_formatted}</p> </div> </div> <div class="acknowledgement-section" style="margin-top:18px;"> <h3 style="text-align:center;color:#3a6c9c;">Kreative Pixelz</h3> <div style="display:flex;justify-content:space-between;margin-top:10px;"> <div style="width:32%;"> <p><strong>Received From:</strong></p> <p>{$client_name_html}</p> <p>{$client_address_html}</p> <p><strong>Contact:</strong> {$client_contact_html}</p> </div> <div style="width:32%;text-align:center;"> <p><strong>Invoice Details</strong></p> <p>Invoice No.: {$invoice['invoice_no']}</p> <p>Invoice Date: {$invoice_date}</p> <p>Invoice Amount: ₹{$total_formatted}</p> </div> <div style="width:32%;text-align:center;"> <p><strong>Receiver's Seal & Sign</strong></p> <div style="height:60px;border-bottom:1px solid #333;margin-top:40px;"></div> </div> </div> </div> <footer class="invoice-footer"> <p><b>This is a computer generated invoice & hence does not require any signature</b></p> </footer> </div> </body> </html> HTML; // Initialize TCPDF and output $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($company_name); $pdf->SetTitle('Invoice - ' . $invoice['invoice_no']); $pdf->SetMargins(10, 10, 10, true); $pdf->AddPage(); // Write HTML and output $pdf->writeHTML($html, true, false, true, false, ''); $pdf->Output('invoice_' . $invoice_id . '.pdf', 'I'); exit; ?>