:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/kreative_crm/quatation/**
:: Editing File: print_po2_invoice.php
<?php // Enable error reporting for debugging error_reporting(E_ALL); ini_set('display_errors', '1'); // Include your database connection and Composer's autoloader include("db.php"); require_once __DIR__ . '/vendor/autoload.php'; // Check if an ID is provided in the URL if (!isset($_GET['id']) || empty($_GET['id'])) { die("Error: Purchase Order ID is missing."); } $po_id = mysqli_real_escape_string($conn, $_GET['id']); // --- 1. Fetch Master PO Data --- // Join with vendors, billing, and delivery_locations tables $sql_po = "SELECT p.*, pa.name AS vendor_name, pa.address AS vendor_address, pa.phone AS vendor_contact, b.company_name AS billing_name, b.address AS billing_address, b.contact_phone1 AS billing_contact, d.company_name AS delivery_name, d.address AS delivery_address, d.contact_phone1 AS delivery_contact FROM purchase AS p LEFT JOIN party As pa On p.vendor_id = pa.id LEFT JOIN billing AS b ON p.billing_id = b.id LEFT JOIN delivery AS d ON p.delivery_id = d.id WHERE p.id = '$po_id'"; $result_po = mysqli_query($conn, $sql_po); if (mysqli_num_rows($result_po) == 0) { die("Error: No Purchase Order found with this ID."); } $po = mysqli_fetch_assoc($result_po); // --- 2. Fetch PO Items Data --- $sql_items = "SELECT * FROM purchase_items WHERE purchase_id = '$po_id'"; $result_items = mysqli_query($conn, $sql_items); $items = mysqli_fetch_all($result_items, MYSQLI_ASSOC); // --- 3. Utility Function: Proper INR Number-to-Words --- function numberToWords($number) { $decimal = round($number - ($no = floor($number)), 2) * 100; $hundred = null; $digits_length = strlen($no); $i = 0; $str = array(); $words = array(0 => '', 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'); $digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore'); // Logic for Indian number system (Lakhs, Crores) while ($i < $digits_length) { $divider = ($i == 2) ? 10 : 100; $number = floor($no % $divider); $no = floor($no / $divider); $i += $divider == 10 ? 1 : 2; if ($number) { $plural = (($counter = count($str)) && $number > 9) ? 's' : null; $hundred = ($counter == 1 && $str[0]) ? ' and ' : null; $str [] = ($number < 21) ? $words[$number] . ' ' . $digits[$counter] . $plural . ' ' . $hundred : $words[floor($number / 10) * 10] . ' ' . $words[$number % 10] . ' ' . $digits[$counter] . $plural . ' ' . $hundred; } else { $str[] = null; } } $Rupees = implode('', array_reverse($str)); $paise = ''; // Handle the decimal part (Paise) if ($decimal > 0) { $paise = ($decimal < 20) ? $words[$decimal] . ' Paise' : $words[floor($decimal / 10) * 10] . ' ' . $words[$decimal % 10] . ' Paise'; $paise = ' AND ' . $paise; } $final_words = ($Rupees ? $Rupees . 'RUPEES' : '') . $paise; return strtoupper(trim($final_words)) . ' ONLY'; } // ----------------------------------------------------------------- // --- 4. Start building the HTML for the PDF using an output buffer --- ob_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Purchase Order - #<?php echo htmlspecialchars($po['po_no']); ?></title> <style> /* (*** Your CSS code remains here - No changes needed ***) */ /* General Body Styles */ body { font-family: Arial, sans-serif; font-size: 11px; color: #333; margin: 0; padding: 0; } /* Main container */ .invoice-container { width: 100%; margin: auto; background: #fff; padding: 5px; /* box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); */ } /* Header Section */ .po-header { width: 100%; border-bottom: 2px solid #333; padding-bottom: 10px; margin-bottom: 10px; } .header-left, .header-right { display: inline-block; vertical-align: top; } .header-left { width: 40%; } .logo-sk { border: 1px solid #000; padding: 5px 10px; font-size: 18px; font-weight: bold; display: inline-block; margin-right: 5px; } .company-name-main { font-size: 18px; font-weight: bold; display: inline-block; } .header-right { width: 58%; text-align: right; font-size: 24px; font-weight: bold; } /* Detail Boxes (Vendor/Order Info) */ .detail-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; } .detail-box-vendor, .detail-box-order { padding: 5px; border: 1px solid #ddd; vertical-align: top; } .detail-box-vendor { width: 50%; } .detail-box-order { width: 50%; border-left: none; } .detail-box p { margin: 3px 0; line-height: 1.4; } /* Address Boxes */ .address-box { width: 100%; border-collapse: collapse; margin-bottom: 10px; } .address-box-billing, .address-box-delivery { width: 50%; border: 1px solid #ddd; padding: 5px; vertical-align: top; height: 80px; /* Consistent height */ } .address-box-delivery { border-left: none; } .address-box p { margin-top: 5px; } .terms-intro { font-size: 10px; margin-bottom: 15px; padding: 5px; border: 1px dashed #ccc; } /* Items Table */ .items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; } .items-table th, .items-table td { border: 1px solid #ddd; padding: 5px; text-align: left; vertical-align: top; } .items-table thead th { background-color: #f2f2f2; font-weight: bold; text-align: center; } .items-table .col-desc { width: 45%; } .items-table .col-uom { width: 10%; text-align: center; } .items-table .col-qty { width: 10%; text-align: right; } .items-table .col-rate { width: 15%; text-align: right; } .items-table .col-amount { width: 20%; text-align: right; } .sub-item { font-size: 10px; color: #555; padding-left: 10px; display: block; } /* Table Footer */ .items-table tfoot .total-label { text-align: right; font-weight: bold; font-size: 12px; } .items-table tfoot .total-amount { font-weight: bold; font-size: 12px; background-color: #f2f2f2; text-align: right; } /* Remarks and Amount in Words */ .remarks-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; } .remarks-box, .amount-in-words-box { padding: 5px; border: 1px solid #ddd; vertical-align: top; } .remarks-box { width: 60%; } .amount-in-words-box { width: 40%; border-left: none; } .remarks-table p { margin: 3px 0; } /* Payment Terms */ .payment-terms { border-top: 1px solid #333; border-bottom: 1px solid #333; padding: 5px 0; margin-bottom: 20px; font-weight: bold; font-size: 11px; } /* Footer/Signature Section */ .signature-table { width: 100%; margin-bottom: 10px; } .signature-box-vendor, .signature-box-buyer { width: 50%; text-align: center; padding-top: 30px; font-size: 11px; vertical-align: top; } .final-note { text-align: center; font-style: italic; font-size: 10px; color: #777; margin-top: 10px; } </style> </head> <body> <div class="invoice-container"> <table class="po-header"> <tr> <td class="header-left"> <!--<div class="logo-sk">BG</div>--> <div class="company-name-main"><?php echo htmlspecialchars($po['billing_name']); ?></div> </td> <td class="header-right">PURCHASE ORDER - <?php echo $po['po_status'] ?> </td> </tr> </table> <table class="detail-table"> <tr> <td class="detail-box-vendor"> <strong>Vendor Name & Address:</strong> <p> <!-- Vendor code: <?php /* echo htmlspecialchars($po['vendor_code']); */ ?><br> --> <strong><?php echo htmlspecialchars($po['vendor_name']); ?></strong><br> <?php echo nl2br(htmlspecialchars($po['vendor_address'])); ?><br> Contact Person No.: <?php echo htmlspecialchars($po['vendor_contact']); ?> </p> </td> <td class="detail-box-order"> <p><strong>PO NO.:</strong> <?php echo htmlspecialchars($po['po_no']); ?></p> <p><strong>Date:</strong> <?php echo date("d-m-Y", strtotime($po['po_date'])); ?></p> <p><strong>Challan No:</strong> <?php echo htmlspecialchars($po['po_req_no']); ?></p> <p><strong>Farmer Name:</strong> <?php echo htmlspecialchars($po['po_contact_ref']); ?></p> <p><strong>Farmer Contact Person:</strong> <?php echo htmlspecialchars($po['po_contact']); ?></p> <p><strong>Product Name:</strong> <?php echo htmlspecialchars($po['product_name']); ?></p> </td> </tr> </table> <table class="address-box"> <tr> <td class="address-box-billing"> <strong><u>Billing Address:</u></strong> <p> <strong><?php echo htmlspecialchars($po['billing_name']); ?></strong><br> <?php echo nl2br(htmlspecialchars($po['billing_address'])); ?><br> Mob.: <?php echo htmlspecialchars($po['billing_contact']); ?>, Email: <?php /* echo htmlspecialchars($po['billing_email']); */ ?> </p> </td> <td class="address-box-delivery"> <strong><u>Delivery Address:</u></strong> <p> <strong><?php echo htmlspecialchars($po['delivery_name']); ?></strong><br> <?php echo nl2br(htmlspecialchars($po['delivery_address'])); ?><br> Tel. No: <?php echo htmlspecialchars($po['delivery_contact']); ?> </p> </td> </tr> </table> <div class="terms-intro"> Please supply the following subject to Terms specified as given below. The acknowledgement copy of the order must be returned to us duly signed by you within TWO working days without which this order will be deemed as accepted. Please mention our PO Ref Number in all respective documents. </div> <main> <table class="items-table"> <thead> <tr> <th style="width:5%;">S.NO</th> <th class="col-desc">ITEM DESCRIPTION</th> <th class="col-uom">PACK TYPE</th> <th class="col-qty">QUANTITY</th> <th class="col-rate">RATE (INR)</th> <th class="col-amount">AMOUNT (INR)</th> </tr> </thead> <tbody> <?php $sn = 1; $rowCount = count($items); $minRows = 5; // Minimum number of rows to display $emptyRows = $minRows - $rowCount; foreach ($items as $item) { ?> <tr> <td style="text-align:center;"><?php echo $sn++; ?></td> <td class="col-desc"> <?php echo htmlspecialchars($item['item_description']); ?><br> <?php if (!empty($item['pack_type'])): // NOTE: Since pack_type is shown in a separate column now (col-uom), // you might want to remove this nested display or use it for additional sub-details. // Keeping it commented out for cleaner display based on the table structure. /* <span class="sub-item">(Pack Type: <?php echo htmlspecialchars($item['pack_type']); ?>)</span> */ endif; ?> </td> <td class="col-uom"><?php echo htmlspecialchars($item['pack_type']); ?></td> <td class="col-qty"><?php echo number_format($item['quantity'], 2); ?></td> <td class="col-rate"><?php echo number_format($item['rate'], 2); ?></td> <td class="col-amount"><?php echo number_format($item['amount'], 2); ?></td> </tr> <?php } // Add empty rows to maintain minimum height for ($i = 0; $i < $emptyRows; $i++) { echo '<tr><td> </td><td></td><td></td><td></td><td></td><td></td></tr>'; } ?> </tbody> <tfoot> <tr> <td colspan="5" class="total-label">Grand Total</td> <td class="total-amount"><?php echo number_format($po['grand_total'], 2); ?></td> </tr> </tfoot> </table> </main> <table class="remarks-table"> <tr> <td class="remarks-box"> <strong>Logistics & General Remarks:</strong> <p>Driver Name: <?php echo htmlspecialchars($po['driver_name']); ?></p> <p>Driver No: <?php echo htmlspecialchars($po['driver_no']); ?></p> <p>Vehicle No: <?php echo htmlspecialchars($po['vehicle_no']); ?></p> <p>Total Boxes: <?php echo (int)$po['total_box']; ?></p> <p>Remarks: <?php echo nl2br(htmlspecialchars($po['remark'])); ?></p> <p>Incoterms: <?php echo htmlspecialchars($po['incoterms']); ?></p> </td> <td class="amount-in-words-box"> <strong>Amount in words:</strong> <p style="font-style: italic;"><?php echo numberToWords($po['grand_total']); ?></p> </td> </tr> </table> <div class="payment-terms"> <strong>Payment Terms:</strong> <?php echo nl2br(htmlspecialchars($po['terms'])); ?> </div> <table class="signature-table"> <tr> <td class="signature-box-vendor"> <p>For <?php echo htmlspecialchars(strtoupper($po['vendor_name'])); ?></p> <br><br><br> <p>Authorized Signatory (Vendor)</p> </td> <td class="signature-box-buyer"> <p>For <?php echo htmlspecialchars(strtoupper($po['billing_name'])); ?></p> <br><br><br> <p>Authorized Signatory (Buyer)</p> </td> </tr> </table> <div class="final-note"> (This is a system generated Purchase Order and may not require a physical signature.) </div> </div> <?php if (!empty($po['purchase_receipt'])) { ?> <div class="invoice-container"> <br><br> <?php $basePath = 'https://barjeelgroup.in/crm/'; $fullUrl = $basePath . $po['purchase_receipt']; ?> <center> <img src="<?php echo $fullUrl;?>"> </center> </div> <?php } ?> </body> </html> <?php // --- 5. Get the captured HTML content and generate the PDF --- $poHTML = ob_get_clean(); // Create a new mPDF instance $mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => 'A4', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 10, 'margin_bottom' => 10, ]); // Write the HTML content to the PDF $mpdf->WriteHTML($poHTML); // Output the PDF to the browser for inline display ('I') $mpdf->Output('PO-' . $po['po_no'] . '.pdf', 'I'); ?>