<?php 
error_reporting(0);

require_once '../assets/plugins/tcpdf/tcpdf.php'; 
include("../config.php");

class MyCustomPDFWithWatermark extends TCPDF{
    public function Header() {
      $bMargin = $this->getBreakMargin();
      $auto_page_break = $this->AutoPageBreak;
      $this->SetAutoPageBreak(false, 0);
      if($with_logo == 'with_copy'){
         $img_file = '../assets/logo/watermark.png';
      }else{
         $img_file = '';
      }   
      $this->Image($img_file, 35, 60, 150, 150, '', '', '', false, 300, '', false, false, 0);
      $this->SetAutoPageBreak($auto_page_break, $bMargin);
      $this->setPageMark();
    }
 public function Footer() {
        // Set the footer content to an empty string
        $this->setPrintFooter(false);
    }    
}
$pdf = new MyCustomPDFWithWatermark(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetMargins(10, 1, 7);
$pdf->SetFont('helvetica', '', '7', '', true);
$with_logo = $_POST['print_type'];
$bill_no  = $_POST['invoice_no'];
$file_type  = implode(",", $_POST['print_type']);
$arrays     = explode(',', $file_type);

$report     = "SELECT * FROM report_setting WHERE company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
$report_res = mysqli_query($conn,$report);
$report_row = mysqli_fetch_assoc($report_res);

$bill             =  "SELECT * FROM `billing` WHERE `invoice_no` = '".$bill_no."'";
$bill_res         = mysqli_query($conn,$bill);
$bill_row         = mysqli_fetch_assoc($bill_res);
$common_remark    = $bill_row['remarks'];
$vendor           = "SELECT * FROM `vendor_master` WHERE `id` = '".$bill_row['vendor_id']."'";
$vendor_res       = mysqli_query($conn,$vendor);
$vendor_row       = mysqli_fetch_array($vendor_res);
$state_code       = substr($vendor_row['gstin'],0,2);

$lr     = "SELECT * FROM `billing` WHERE invoice_no = '".$bill_no."'";
$lr_res = mysqli_query($conn,$lr);
$num    = mysqli_num_rows($lr_res);
$lrs    = array();
while ($lr_row = mysqli_fetch_assoc($lr_res)) { 
  $lrs[] = $lr_row;
}

//$total_count      =  count($lrs);
$gst_paid         = "SELECT * FROM lr_mst WHERE lr_no = '".$bill_row['lr_no']."'";
$gst_paid_res     = mysqli_query($conn,$gst_paid);
$gst_paid_row     = mysqli_fetch_assoc($gst_paid_res);

$bank_det         = "SELECT * FROM company_mst WHERE id = '".$_SESSION['company_id']."'";
$bank_det_res     = mysqli_query($conn,$bank_det);
$bank_det_rows    = mysqli_fetch_assoc($bank_det_res);

$bill_add     = "SELECT * FROM `billing_details` WHERE `type` = 'add' AND `bill_no` =  '".$bill_no."' ORDER BY id DESC";
$bill_add_res = mysqli_query($conn,$bill_add);

$bill_add = array();
$total_add  = 0;
while ($bill_add_row = mysqli_fetch_assoc($bill_add_res)) {
  $bill_add[] = array('title' => $bill_add_row['tax_mst_id'], 'amount' => $bill_add_row['amount']);
  $total_add += $bill_add_row['amount'];
}
$master_tax = combine(getAllRecords('tax_mst'), 'id', 'descr');

if( isset($bill_add[0]['amount']) && !empty($bill_add[0]['amount']) ) {
  $bill_amnt_0 = customFormatMoney($bill_add[0]['amount']); 
  $countaddone = '1';
}else{
  $bill_amnt_0 = '';
}

if( isset($bill_add[1]['amount']) && !empty($bill_add[1]['amount']) ) {
 $bill_amnt_1 = customFormatMoney($bill_add[1]['amount']); 
 $countaddtwo = '1';
}else{
 $bill_amnt_1 = '';
}

if( isset($bill_add[2]['amount']) && !empty($bill_add[2]['amount']) ) {
 $bill_amnt_2 = customFormatMoney($bill_add[2]['amount']);
 $countaddthree = '1';
}else{
 $bill_amnt_2 = '';
}

if( isset($bill_add[3]['amount']) && !empty($bill_add[3]['amount']) ) {
 $bill_amnt_3 = customFormatMoney($bill_add[3]['amount']);
 $countaddfour = '1';
}else{
 $bill_amnt_3 = '';
} 

$count_add_row = $countaddone + $countaddtwo + $countaddthree + $countaddfour;

$lhc_sub     = "SELECT * FROM `billing_details` WHERE `type` = 'sub' AND `bill_no` =  '".$bill_no."' ORDER BY id DESC";
$lhc_sub_res = mysqli_query($conn,$lhc_sub);
$sub = array();
$total_sub = 0;
while ($lhc_sub_row = mysqli_fetch_assoc($lhc_sub_res)) {
 $sub[] = array('title' => $lhc_sub_row['tax_mst_id'], 'amount' => $lhc_sub_row['amount']);
 $total_sub += $lhc_sub_row['amount'];
}

if( isset($sub[0]['amount']) && !empty($sub[0]['amount']) ) {
 $sub_0 = customFormatMoney($sub[0]['amount']);
 $countsub1 = '1';
 $style = ''; 
}else{
 $sub_0 = '';
 $style = "height:17px";
}

if( isset($sub[1]['amount']) && !empty($sub[1]['amount']) ) {
 $sub_1 = customFormatMoney($sub[1]['amount']);
 $countsub2 = '1';
 $style = '';  
}else{
 $sub_1 = '';
 $style = "height:17px";
}

if( isset($sub[2]['amount']) && !empty($sub[2]['amount']) ) {
 $sub_2 = customFormatMoney($sub[2]['amount']);
 $countsub3 = '1';
 $style = '';  
}else{
 $sub_2 = '';
 $style = "height:17px";
}

if( isset($sub[3]['amount']) && !empty($sub[3]['amount']) ) {
 $sub_3 = customFormatMoney($sub[3]['amount']);
 $countsub4 = '1';
 $style = '';  
}else{
 $sub_3 = '';
 $style = "height:17px";
}

$count_sub_row = $countsub1 + $countsub2 + $countsub3 + $countsub4;

$total_add_less_row = (8 - ($count_sub_row + $count_add_row));

$branch     = "SELECT * FROM branch_mst WHERE id = '".$_SESSION['branch_id']."'";
$branch_mst = mysqli_query($conn,$branch);
$branch_row = mysqli_fetch_assoc($branch_mst);

$output  = ''; 

if($with_logo == 'with_copy'){
$image_css = 'block';
$table_css = 'none';

}else{
$image_css = 'none';
$table_css = 'block';
}
$output .= '<!DOCTYPE html>
<html>
   <head>
      <title>BILL COPY</title>
   </head>
   <body>
   <table style="display:'.$image_css.'">
          <tr>
            <td style="width:100%;"><img src="../assets/logo/header.png"></td>
          </tr>
   </table>
   <table style="display:'.$table_css.'">
          <tr>
            <td style="width:100%; height:35px;">&nbsp;</td>
          </tr>

          <tr>
            <td style="width:100%; height:100px;">&nbsp;</td>
          </tr>
   </table>
      <table cellpadding="2" style="width:100%;">';
   
      $output .='
          <tr>
            <td style="text-align:left;width:65%;font-weight:bolder;border-top:0.5px solid grey;border-left:0.5px solid grey;font-size:10px;">M/s. : '.$vendor_row['name'].'</td>
            <td style="text-align:left;width:35%;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-left:0.5px solid grey;font-size:10px;"> Bill No &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: '.substr($bill_row['invoice_no'], 9).'</td>
          </tr>
          <tr>
            <td rowspan="2" style="text-align:left;width:65%;border-left:0.5px solid grey;font-size:8px">'.$vendor_row['address'].'</td>
            <td style="text-align:left;width:35%;font-weight:bolder;border-right:0.5px solid grey;border-left:0.5px solid grey;font-size:10px"> Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: '.risFormatDate($bill_row['bill_date']).'</td>
          </tr>
          <tr>
            <td style="text-align:left;width:35%;font-weight:bolder;border-right:0.5px solid grey;border-left:0.5px solid grey;font-size:10px"> GST Paid By : '.$gst_paid_row['gst_paid_by'].'</td>
          </tr>
          <tr>
            <td style="text-align:left;width:65%;font-weight:bolder;border-left:0.5px solid grey;font-size:10px">GST No. : '.$vendor_row['gstin'].'</td>
            <td style="text-align:left;width:35%;font-weight:bolder;border-right:0.5px solid grey;border-left:0.5px solid grey;font-size:10px"> SAC Code&nbsp;&nbsp;&nbsp;&nbsp; : 996511</td>
          </tr>
          <tr>
            <td style="width:100%;text-align:center;font-weight:bolder;border-left:0.5px solid grey;border-right:0.5px solid grey;border-top:0.5px solid grey;font-size:10px">TAX INVOICE</td>
          </tr>
          <tr>

            <td style="width:10%;text-align:center;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-weight:bolder;border-top:0.5px solid grey;border-left:0.5px solid grey;font-size:8px;">LR.NO</td>

            <td style="width:14%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;"> DATE</td>

            <td style="width:14%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;">FROM</td>

            <td style="width:17%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;">TO</td>

            <td style="width:15%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;">TRUCK NO</td>


            <td style="width:10%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;"> WEIGHT</td>

            <td style="width:10%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:8px;">RATE</td>

            <td style="border-bottom:0.5px solid grey;width:10%;text-align:right;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">FREIGHT</td>
          </tr>';
           $i = 1;
           $total_weight = 0;
           $total_other  = 0;
           $total_amount = 0;
           $total_pcs    = 0;
           $line_count   = 0;
           $cou = 1;
          foreach ($lrs as $i => $lrs) {
            $lr_rematks     = "SELECT * FROM `billing` WHERE invoice_no = '".$bill_no."' AND remark !=''";
            $lr_rematks_res = mysqli_query($conn,$lr_rematks);
            $remark_count   = mysqli_num_rows($lr_rematks_res);
            
            
            $fri      = "SELECT * FROM lr_mst WHERE lr_no = '".$lrs['lr_no']."'";
            $fri_res  = mysqli_query($conn,$fri);
            $fri_row  = mysqli_fetch_assoc($fri_res);

            // if($fri_row['packing'] || $fri_row['remark']){
            //   $line_count += 1;
            // }

            $lr_wise_remark = $fri_row['packing'] .''.$fri_row['remark'];

            $total_weight += $fri_row['weight'];
            $total_other  += $lrs['other_charges'];
            $total_amount += $lrs['lr_amount'];
            // $net_amnt = $total_add - $total_sub + $total_other + $total_amount;
            $total_pcs += $fri_row['pcs'];

            $truck = mysqli_query($conn, "SELECT * FROM `truck_mst` WHERE `truck_no` = '".$fri_row['truck_no']."'");
            $truck_row = mysqli_fetch_assoc($truck);

            $total_count    =  $num + $remark_count + $line_count + count($bill_add) + count($sub);

          $output .='
          <tr>

            <td style="width:10%;text-align:center;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.substr($lrs['lr_no'], 5).'</td>

            <td style="width:14%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;"> '.risFormatDate($lrs['lr_date']).'</td>

            <td style="width:14%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.$lrs['lr_from'].'</td>


            <td style="width:17%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.$lrs['lr_to'].'</td>

            <td style="width:15%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.$fri_row['truck_no'].'</td>

            <td style="width:10%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.$lrs['lr_weight'].'</td>

            <td style="width:10%;text-align:center;font-size:7px;border-left:0.5px solid grey;border-right:0.5px solid grey;font-size:8px;">'.$lrs['lr_rate'].'</td>

            <td style="width:10%;text-align:right;border-right:0.5px solid grey;font-size:7px; border-left:0.5px solid grey;font-size:8px;">'.$lrs['lr_amount'].'</td>
          </tr>
          ';
          $i++; }
          if($total_count < 23) {
            for ($j=1; $j <= ( 23 - $total_count ); $j++) {
            $output .='
            <tr>
              <td style="width:10%;text-align:left;font-weight:bolder;border-left:0.5px solid grey;border-right:0.5px solid grey;"></td>
              <td style="width:14%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:14%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:17%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:15%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:10%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:10%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:10%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
              <td style="width:9%;text-align:left;font-weight:bolder;"></td>
              <td style="width:10%;text-align:left;font-weight:bolder;border-right:0.5px solid grey;"></td>
            </tr>
           ';
           }
         }
         if($bill_add[0]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$bill_add[0]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$bill_amnt_0.'</td>
          </tr>';
        }

        if($bill_add[1]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$bill_add[1]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$bill_amnt_1.'</td>
          </tr>';
        }

        if($bill_add[2]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$bill_add[2]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$bill_amnt_2.'</td>
         </tr>';
        }

        if($bill_add[3]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$bill_add[3]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$bill_amnt_3.'</td>
          </tr>';
        }

        if($sub[0]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$sub[0]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$sub_0.'</td>
         </tr>';
        }

        if($sub[1]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$sub[1]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$sub_1.'</td>
         </tr>';
        }

        if($sub[2]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$sub[2]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$sub_2.'</td>
          </tr>';
        }

        if($sub[3]['title'] != ''){
          $output .='
          <tr>
            <td colspan="7" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey"> </td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.@$master_tax[$sub[3]['title']].'</td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"> '.$sub_3.'</td>
         </tr>';
        }

        $output .='
          <tr>
            <td colspan="5" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey;font-size:9px;"> Rupees(word): '.convertNumber2Words($total_amount).'</td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey;font-size:9px;"> Total</td>
            <td colspan="" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey;font-size:9px"> '.customFormatMoney($total_amount).'</td>
         </tr>
         <tr>
            <td colspan="5" style="font-weight:bolder;text-align:left;border-top:0.5px solid grey;border-left:0.5px solid grey;font-size:8px;"> Reminder : - '.$common_remark.'</td>
            <td colspan="2" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;"></td>
            <td colspan="1" style="font-weight:bolder;text-align:right;border-top:0.5px solid grey;border-right:0.5px solid grey"></td>
         </tr>
         <tr>
            <td style="width:14%;text-align:left;border-left:0.5px solid grey;border-top:0.5px solid grey;font-weight:bolder;font-size:10px;"> Bank Details </td>
            <td style="width:56%;text-align:left;border-top:0.5px solid grey;font-weight:bolder;font-size:10px;"> A/c. Name &nbsp;&nbsp;&nbsp;&nbsp;: '.$bank_det_rows['name'].'</td>
            <td style="width:30%;border-top:0.5px solid grey; border-right:0.5px solid grey;"></td>
         </tr>
         <tr >
            <td style="width:14%;text-align:left;border-left:0.5px solid grey; font-weight:bolder;"></td>
            <td style="width:56%;text-align:left;font-weight:bolder;font-size:10px;font-weight:bolder;"> Bank&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: '.$bank_det_rows['bank_name'].'
            <br> Account No. : '.$bank_det_rows['account_no'].'  
            <br> Branch &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: '.$bank_det_rows['branch'].' </td>
            <td style="width:30%;text-align:right;font-weight:bolder; border-right:0.5px solid grey;"></td>
         </tr>
         <tr>
            <td style="width:14%;text-align:left;border-left:0.5px solid grey;font-weight:bolder;"> </td>
            <td style="width:56%;text-align:left;font-weight:bolder;font-weight:bolder;font-size:10px;"> IFSC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'.$bank_det_rows['ifsc_code'].'</td>
            <td style="width:30%;text-align:center;border-right:0.5px solid grey;font-weight:bolder;"></td>
         </tr>

         <tr>
            <td style="width:33.3%;text-align:left;border-left:0.5px solid grey;font-weight:bolder;border-top:0.5px solid grey;border-right:0.5px solid grey;font-size:10px;"> PAN No. : '.$bank_det_rows['panno'].'</td>
            <td style="width:33.3%;text-align:center;font-weight:bolder;border-top:0.5px solid grey;font-size:10px;"> GST NO.: '.$bank_det_rows['gst'].'</td>
            <td style="width:33.3%;text-align:center;border-right:0.5px solid grey; border-top:0.5px solid grey;border-left:0.5px solid grey;font-weight:bolder;font-size:10px;"> State Code : 24</td>
         </tr>
         
          <tr >
            <td style="width:30%;text-align:left;border-left:0.5px solid grey;border-top:0.5px solid grey;font-weight:bolder;border-bottom:0.5px solid grey;font-size:8px"><table><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr> <tr><td></td></tr><tr><td>Checked By:</td></tr></table> 
            </td>

            <td style="width:35%;text-align:left;border-top:0.5px solid grey;font-weight:bolder;border-bottom:0.5px solid grey;font-size:8px"><table><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr> <tr><td></td></tr><tr><td></td></tr><tr><td>Received By:</td></tr></table></td>';

            if($with_logo == 'with_copy'){
              $output .='
              <td colspan="4" style="width:35%;text-align:left;border-top:0.5px solid grey;font-weight:bolder;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:10px;" align="right"><table><tr> <td> For, Catch-up Logistics</td></tr><tr><td><img src="../assets/logo/catchup-stamp-transformed_1.png"></td></tr><tr><td>Authorized Sign </td></tr></table></td>';
            }else{
              $output .='
              <td colspan="4" style="width:35%;text-align:left;border-top:0.5px solid grey;font-weight:bolder;border-right:0.5px solid grey;border-bottom:0.5px solid grey;font-size:10px;" align="right"><table><tr> <td> For, Catch-up Logistics</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><tr><td>Authorized Sign </td></tr></table></td>';
            }  
              $output .='

            </tr>
      </table>
<table style="display:'.$image_css.'">
    <tr><td></td></tr>
          <tr>
            <td style="width:80%;"><img src="../assets/logo/catch-footer2.png"> </td>
            <td style="width:20%;"><table> <tr><td><b></b></td></tr><tr><td> </td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td><b>______________________</b></td></tr> <tr><td style="font-size:14px;"><b>C a t c h - u p </b></td></tr></table></td>
          </tr>
   </table>
   <table style="display:'.$table_css.'">
          <tr>
            <td style="width:80%; height:50px;">&nbsp;</td>
          </tr>
   </table>
      
   </body>
</html>';
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);


$pdf->AddPage('P', 'A4');
$pdf->writeHTML($output, true, false, false, false, '');
$pdf->SetTitle('BILL COPY'.'-'.$_GET['p1']);
$pdf->Output('bill_copy'.'_'.$_GET['p1'].'.pdf', 'I');
?>