<?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);
      $img_file = '../assets/logo/ayush_bill.png';
      $this->Image($img_file, 0, 0, 210, 297, '', '', '', 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(5, 5, 5);
$pdf->SetFont('helvetica', '', '7', '', true);

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

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

  $tr       = "SELECT SUM(`amount`) AS total_res FROM `lhc_payment_status` WHERE `lhc_no` = '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'";
  $tr_res   = mysqli_query($conn,$tr);
  $tr_row   = mysqli_fetch_assoc($tr_res);
  $total_tr = $tr_row['total_res'];

  $lhc_details     = "SELECT * FROM `lhc_details` WHERE `type` = 'add' AND `lhc_id` =  '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."' ORDER BY id DESC";
  $lhc_details_res = mysqli_query($conn,$lhc_details);

  $lhc_det = array();
  $total_add  = 0;
  while ($lhc_details_row = mysqli_fetch_assoc($lhc_details_res)) {
    //$addition = $lhc_details_row['descr'];
    $lhc_det[] = array('title' => $lhc_details_row['tax_mst_id'], 'amount' => $lhc_details_row['amount']);
    $total_add += $lhc_details_row['amount'];
  }

  $lhc_sub     = "SELECT * FROM `lhc_details` WHERE `type` = 'sub' AND `lhc_id` =  '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."' 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'];
  }


  $master_tax       = combine(getAllRecords('tax_mst'), 'id', 'descr');
  $master_accounts  = combine(getAllRecords('act_master'), 'id', 'ac_name');

  $lhc =  "SELECT * FROM `lhc` WHERE `lhc_no` = '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'";
  $lhc_res = mysqli_query($conn,$lhc);
  $lhc_row = mysqli_fetch_assoc($lhc_res);
  
  $agent   = "SELECT * FROM vendor_master WHERE name = '".$lhc_row['agent']."'";
  $agent_res = mysqli_query($conn,$agent);
  $agent_row = mysqli_fetch_assoc($agent_res);


  $owner   = "SELECT * FROM truck_mst WHERE id = '".$lhc_row['owner_name']."'";
  $own_res = mysqli_query($conn,$owner);
  $own_row = mysqli_fetch_assoc($own_res);

  $driver     = "SELECT * FROM truck_mst WHERE d_name = '".$lhc_row['d_name']."'";
  $driver_res = mysqli_query($conn,$driver);
  $driver_row = mysqli_fetch_assoc($driver_res);
  
  if($lhc_row['p_from'] == '1970-01-01' || $lhc_row['p_from'] == ''){
    $p_from = '';
  }else{
    $p_from = risFormatDate($lhc_row['p_from']);
  }

  if($lhc_row['up_to'] == '1970-01-01' || $lhc_row['up_to'] == ''){
    $up_to = '';
  }else{
    $up_to = risFormatDate($lhc_row['up_to']);
  }

  if($lhc_row['p_up_to'] == '1970-01-01' || $lhc_row['p_up_to'] == ''){
    $p_up_to = '';
  }else{
    $p_up_to = risFormatDate($lhc_row['p_up_to']);
  }

  if($lhc_row['date'] == '1970-01-01'|| $lhc_row['date'] == ''){
    $date = '';
  }else{
    $date = risFormatDate($lhc_row['date']);
  }

  if($lhc_det[0]['amount'] == ''){
    $amount = '';
  }else{
    $amount = $lhc_det[0]['amount'];
  }

  if($lhc_det[1]['amount'] == ''){
    $amount1 = '';
  }else{
    $amount1 = $lhc_det[1]['amount'];
  }

  if($lhc_det[2]['amount'] == ''){
    $amount2 = '';
  }else{
    $amount2 = $lhc_det[2]['amount'];  
  }

  if($lhc_det[3]['amount'] == ''){
    $amount3 = '';
  }else{
    $amount3 = $lhc_det[3]['amount'];  
  }

  if($sub[0]['amount'] == ''){
    $sub_0 = "";
  }else{
    $sub_0 = $sub[0]['amount'];  
  }

  if($sub[1]['amount'] == ''){
    $sub_1 = "";
  }else{
    $sub_1 = $sub[1]['amount'];  
  }

  if($sub[2]['amount'] == ''){
    $sub_2 = "";
  }else{
    $sub_2 = $sub[2]['amount'];  
  }

  if($sub[3]['amount'] == ''){
    $sub_3 = "";
  }else{
    $sub_3 = $sub[3]['amount'];  
  }

if($lhc_row['cash'] !=''){
  $cash_amount = $lhc_row['cash']; 
}

if($lhc_row['pay_mode_amnt'] !=''){
  $bank_amount = $lhc_row['pay_mode_amnt']; 
}

if($lhc_row['payment_mode'] == 'NEFT'){
  $tra_number = $lhc_row['neft_number'];
  $tra_type   = 'NEFT';

  if($lhc_row['payment_date'] == '1970-01-01'|| $lhc_row['payment_date'] == ''){
    $tra_date = '';
  }else{
    $tra_date = risFormatDate($lhc_row['payment_date']);
  }

}else if($lhc_row['payment_mode'] == 'RTGS'){
  $tra_number = $lhc_row['rtgs_number'];
  $tra_type   = 'RTGS';
  if($lhc_row['payment_date'] == '1970-01-01'|| $lhc_row['payment_date'] == ''){
    $tra_date = '';
  }else{
    $tra_date = risFormatDate($lhc_row['payment_date']);
  }
}else if($lhc_row['payment_mode'] == 'IMPS'){
  $tra_number = $lhc_row['imps_number'];
  $tra_type   = 'IMPS';
  if($lhc_row['payment_date'] == '1970-01-01'|| $lhc_row['payment_date'] == ''){
    $tra_date = '';
  }else{
    $tra_date = risFormatDate($lhc_row['payment_date']);
  }
}else if($lhc_row['payment_mode'] == 'CHEQUE'){
  $tra_number = $lhc_row['cheque_number'];
  $tra_type   = 'CHEQUE';
  if($lhc_row['cheque_date'] == '1970-01-01'|| $lhc_row['cheque_date'] == ''){
    $tra_date = '';
  }else{
    $tra_date = risFormatDate($lhc_row['cheque_date']);
  }
}else{
  $tra_type   = '';
  $tra_date = '';
}

$total = $lhc_row['lorry_hire'] + $amount + $amount1 + $amount2 + $amount3;
/*BALANCE HISTORY*/

$bh = mysqli_query($conn, "SELECT *  FROM `lhc_balance_history` WHERE `lhc_no` = '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'");
$bh_data = array();
while ($bh_row = mysqli_fetch_assoc($bh)) {
  $bh_data[] = $bh_row;
}

$balance_history = mysqli_query($conn, "SELECT * FROM `lhc_balance_history` WHERE `lhc_no` = '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."' ORDER BY id DESC");
$balance_history_row = mysqli_fetch_assoc($balance_history);
$payment_type        = explode(',', $balance_history_row['payment_type']);
$total_cash_balance = 0;
foreach ($payment_type as $key => $payment_types) {
  if($payment_types == 'C'){
    $cash_tag    = 'CASH';
    $bcash_amount = customFormatMoney($balance_history_row['cash']);
    $total_cash_balance += $balance_history_row['cash'];
    $cpayment_date = $balance_history_row['payment_date'];
  }

  if($payment_types == 'B'){
    $bank_tag = 'BANK';
    $bbank_amount = customFormatMoney($balance_history_row['pay_mode_amnt']);
    if($balance_history_row['payment_mode'] == 'IMPS'){
      $bank_serial = $balance_history_row['imps_number'];
      $btra_type   = 'IMPS';
    }else if($balance_history_row['payment_mode'] == 'RTGS'){
      $bank_serial = $balance_history_row['rtgs_number'];
      $btra_type   = 'RTGS';
    }else if($balance_history_row['payment_mode'] == 'NEFT'){
      $bank_serial = $balance_history_row['neft_number'];
      $btra_type   = 'NEFT';
    }else{
      $bank_serial = $balance_history_row['cheque_number'];
      $btra_type   = 'CHEQUE';
    }
    
    $payment_date = risFormatDate($balance_history_row['payment_date']);
    $bbank_name   = $balance_history_row['bank_name'];
    $bankname = mysqli_query($conn, "SELECT * FROM `act_master` WHERE `id` = '".$bbank_name."'");
    $bankname_row = mysqli_fetch_assoc($bankname);
    $xbankname   = $bankname_row['ac_name'];
  }
}
$output  = ''; 
$output .= '<!DOCTYPE html>
<html>
   <head>
      <title>LHC COPY</title>
   </head>
   <style>
      table {
         border: 1px solid black;
         border-collapse: collapse;
      }
      
   </style>
   <body style="font-size: 6.8px;font-family: verdana !important;height:15px;">
      <div>';
      $output .='<img src="../assets/logo/gati_logo.png" style="width:600px;height:100px;"><hr/><span style="font-size: 12px;text-align:center;"><b></b></span>';
      $output .='</div>
      <table cellpadding="5" style="width: 100%">
         <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;text-align:left;width:15%;border-top:1px solid black;" colspan="2"><b>LHC No.</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:13%;border-top:1px solid black;font-size:8px;"><b>Date</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:34%;vertical-align: baseline;font-size:8px;border-top:1px solid black;"><b>LORRY No.</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:18%;border-top:1px solid black;"><b>From-STN</b></td>
           <td style="border-bottom:1px solid black;text-align:center;width:20%;border-top:1px solid black;"><b>To-STN</b></td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;text-align:center;font-size:10px;font-weight:bolder; width:15%;border-top:1px solid black;" colspan="2">'.substr($lhc_row["lhc_no"],4).'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:13%;font-size:8px;border-top:1px solid black;">'.risFormatDate($lhc_row['lhc_date']).'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:34%;font-size:8px;vertical-align: baseline;border-top:1px solid black;">'.$lhc_row['truck_no'].'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:18%;border-top:1px solid black;font-size:8px;">'.$lhc_row['from_place'].'</td>
           <td style="border-bottom:1px solid black;text-align:center;width:20%;border-top:1px solid black;font-size:8px;">'.$lhc_row['to_place'].'</td>
          </tr>
          <tr> 
           <td style="border-top:1px solid black;border-right:1px solid black;text-align:center;width:15%;border-top:1px solid black;" colspan="2"><b>BROKER NAME</b> </td>
           <td colspan="2" style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:65%;border-top:1px solid black;font-size:8px;font-size:10px"><b>'.$lhc_row['agent'].'</b></td>
           
           <td style="border-bottom:1px solid black;text-align:left;width:20%;border-top:1px solid black;font-size:8px;"><b>Phone</b>'.$lhc_row['o_mobile'].'</td>
          </tr>
          <tr> 
           <td style=" border-right:1px solid black;text-align:center;width:15%;" colspan="2"><b>& PAN Details</b></td>
           <td  style="border-right:1px solid black;text-align:left;width:65%;font-size:10px"><b>'.$agent_row['pan'].' - '.$agent_row['proprietor'].'</b></td>
            
           <td style="border-bottom:1px solid black;text-align:left;width:20%;border-top:1px solid black;font-size:8px;"><b>Mobile</b> '.$lhc_row['mobile'].'</td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;font-size:7px;text-align:center;width:10%;border-top:1px solid black;" colspan="2"><b>SR. No.</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:11%;font-size:7px;border-top:1px solid black;"><b>CN No.</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:13%;font-size:7px;vertical-align: baseline;border-top:1px solid black;"><b>No.of Pkgs.</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:31%;font-size:7px;border-top:1px solid black;"><b>Content</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:10%;font-size:7px;border-top:1px solid black;"><b>Weight IN</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:13%;font-size:7px;border-top:1px solid black;"><b>Destination</b></td>
           <td style="border-bottom:1px solid black;text-align:center;width:12%;border-top:1px solid black;font-size:7px;"><b>Freight</b></td>
          </tr>
          ';

          $lr   = "SELECT * FROM `lhc` WHERE lhc_no = '".$id."' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'";
          $lr_res = mysqli_query($conn,$lr);
          $lr_num = mysqli_num_rows($lr_res);
          $lrs = array();
          while ($lr_row = mysqli_fetch_assoc($lr_res)) { 
            $lrs[] = $lr_row;
          }
          
          $i = 1;
          $lastColumnPrinted  = false;
          foreach ($lrs as $i => $lrs) { 
          $fri   = "SELECT * FROM lr_mst WHERE lr_no like '%".$lrs['lr_no']."%' AND branch_id = '".$_SESSION['branch_id']."' AND company_id = '".$_SESSION['company_id']."'";
          
          $fri_res = mysqli_query($conn,$fri);
          $fri_row = mysqli_fetch_assoc($fri_res);
          $output .='
          <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;font-size:7px;text-align:center;width:10%;border-top:1px solid black;" colspan="2">'.++$i.'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:11%;border-top:1px solid black;font-size:7px;">'.substr($lrs["lr_no"],4).'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:13%;vertical-align: baseline;font-size:7px;border-top:1px solid black;">'.$fri_row['pcs'].'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:31%;font-size:7px;border-top:1px solid black;">'.$fri_row['nature_of_goods'].'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:10%;font-size:7px;border-top:1px solid black;">'.$lrs['weight'].'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:13%;font-size:7px;border-top:1px solid black;">'.$lrs['to_place'].'</td>
           <td style="border-bottom:1px solid black;text-align:center;width:12%;border-top:1px solid black;font-size:7px;">'.$lrs['lorry_hire'].'</td>
          </tr>
          ';
          $i++; }
          if( mysqli_num_rows($lrs) < 2 ) {
            for ($j=1; $j <= ( 2 - mysqli_num_rows($lrs) ); $j++) {
              $output .='
              <tr> 
               <td style="border-right:1px solid black;text-align:center;width:10%;font-size:7px;" colspan="2"></td>
               <td style="border-right:1px solid black;text-align:center;width:11%;font-size:7px;"></td>
               <td style="border-right:1px solid black;text-align:center;width:13%;font-size:7px;vertical-align: baseline;"></td>
               <td style="border-right:1px solid black;text-align:center;width:31%;font-size:7px;"></td>
               <td style="border-right:1px solid black;text-align:center;width:10%;font-size:7px;"></td>
               <td style="border-right:1px solid black;text-align:center;width:13%;font-size:7px;"></td>
               <td style="text-align:center;width:12%;font-size:7px;"></td>
              </tr>';
            }
          }
          $output .='
          <tr> 
           <td style="border-bottom:1px solid black;font-size:8px;border-top:1px solid black;border-right:1px solid black;text-align:left;width:12%;border-top:1px solid black;" ><b>Lorry Type</b></td>
           <td colspan="2" style="border-bottom:1px solid black;text-align:left;width:23%;font-size:8px; border-top:1px solid black;">'.$lhc_row['lorry_type'].'</td>
           
           <td style="border-bottom:1px solid black;font-size:7px;border-left:1px solid black; border-right:1px solid black;text-align:left;width:8%;border-top:1px solid black;"><b>Chsis No</b></td>
           <td style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;">'.$lhc_row['chasis_no'].'</td>
           <td style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:center;width:10%;border-top:1px solid black;"><b>Engine</b></td>
           <td style="border-bottom:1px solid black;text-align:left;font-size:8px;width:25%;border-top:1px solid black;">'.$lhc_row['engine_no'].'</td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:12%;border-top:1px solid black;" ><b>Permit No.</b></td>
           <td colspan="2" style="border-bottom:1px solid black;text-align:left;width:23%;font-size:8px;border-top:1px solid black;">'.$lhc_row['permit_no'].'</td>
           
           <td style="border-bottom:1px solid black;border-left:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:8%;border-top:1px solid black;"><b>From</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;font-size:8px;width:22%;border-top:1px solid black;">'.$p_from.'</td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:10%;font-size:8px;border-top:1px solid black;"><b>UP To</b></td>
           <td style="border-bottom:1px solid black;text-align:left;width:25%;border-top:1px solid black;font-size:8px;">'.$up_to.'</td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;font-size:8px;border-top:1px solid black;border-right:1px solid black;text-align:left;width:12%;border-top:1px solid black;" ><b>Insurance Co.</b></td>
           <td colspan="2" style="border-bottom:1px solid black;text-align:left;width:53%;font-size:8px;border-top:1px solid black;">'.$lhc_row['insurance_no'].'</td>
           
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-left:1px solid black;border-right:1px solid black;text-align:center;width:10%;border-top:1px solid black;"><b>Branch</b></td>
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:25%;border-top:1px solid black;">'.$lhc_row['branch'].'</td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;font-size:8px;border-top:1px solid black;border-right:1px solid black;text-align:left;width:12%;border-top:1px solid black;" ><b>Policy No.</b></td>
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;text-align:left;width:53%;border-top:1px solid black;">'.$lhc_row['policy_no'].'</td>
           
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-left:1px solid black;border-right:1px solid black;text-align:center;width:10%;border-top:1px solid black;"><b>UP To</b></td>
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:25%;border-top:1px solid black;">'.$p_up_to.'</td>
          </tr>
          <tr> 
           <td colspan="2" style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;text-align:center;font-size:8px; width:37%;border-top:1px solid black;" colspan="2"><b>Driver Name & Address </b></td>
           <td colspan="3" style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;font-size:8px;width:28%;vertical-align: baseline;border-top:1px solid black;"><b>Owner Name & Address </b></td>
           <td  style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;font-size:8px;"><b>DETAILS</b></td>
           <td style="border-bottom:1px solid black;text-align:left;width:13%;border-top:1px solid black;font-size:8px;"><b>AMOUNT</b></td>
          </tr>
          <tr> 
           <td colspan="2" style="border-bottom:1px solid black;border-top:1px solid black;border-right:1px solid black;font-size:8px;text-align:left;width:37%;border-top:1px solid black;" colspan="2">'.$lhc_row['d_name'].'</td>
           <td colspan="3" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:28%;vertical-align: baseline;border-top:1px solid black;">'.$own_row['o_name'].'</td>
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>HIRE</b></td>
           <td style="border-bottom:1px solid black;text-align:right;font-size:8px;width:13%;border-top:1px solid black;">'.customFormatMoney($lhc_row['lorry_hire']).'</td>
          </tr>
          <tr> 
           <td rowspan="3" style="border-bottom:1px solid black;font-size:8px;border-top:1px solid black;border-right:1px solid black;text-align:left;width:37%;border-top:1px solid black;" colspan="2">'.$lhc_row['d_address'].'</td>
           <td rowspan="3" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:28%;vertical-align: baseline;border-top:1px solid black;">'.$own_row['o_address'].'</td>
           <td  style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$lhc_det[0]['title']].'</b></td>
           <td  style="border-bottom:1px solid black;text-align:right;font-size:8px;width:13%;border-top:1px solid black;">'.$amount.'</td>
          </tr>
            <tr> 
           <td  style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$lhc_det[1]['title']].'</b></td>
           <td   style="border-bottom:1px solid black;text-align:right;font-size:8px;width:13%;border-top:1px solid black;">'.$amount1.'</td>
          </tr>
          <tr> 
           <td  style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$lhc_det[2]['title']].'</b></td>
           <td   style="border-bottom:1px solid black;text-align:right;font-size:8px;width:13%;border-top:1px solid black;">'.$amount2.'</td>
          </tr>
          <tr> 
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-top:1px solid black;border-right:1px solid black;text-align:left;width:37%;border-top:1px solid black;" colspan="2">'.$driver_row['d_city'].'</td>
           <td colspan="3" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:28%;vertical-align: baseline;border-top:1px solid black;">'.$own_row['o_city'].'</td>
           <td colspan="2" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$lhc_det[3]['title']].'</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;">'.$amount3.'</td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;border-top:1px solid black;text-align:left;font-size:8px;width:8%;border-top:1px solid black;" colspan="2"><b>LIC NO.</b></td>
           <td style="border-bottom:1px solid black;border-top:1px solid black;font-size:8px; text-align:left;width:10%;border-top:1px solid black;" colspan="2">'.substr($lhc_row["lic_no"],9).'</td>
           <td style="border-bottom:1px solid black;text-align:left;width:8%;font-size:8px;border-top:1px solid black;"><b>DATE</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;font-size:8px;width:11%;border-top:1px solid black;">'.$date.'</td>
           <td colspan="3" style="border-bottom:1px solid black;text-align:left;width:10%;font-size:8px;vertical-align: baseline;border-top:1px solid black;"><b>PAN NO</b> :</td>
           <td colspan="3" style="border-bottom:1px solid black;border-right:1px solid black;font-size:8px;text-align:left;width:18%;vertical-align: baseline;border-top:1px solid black;">'.$lhc_row['pan_no'].'</td>
           <td colspan="2" style="border-bottom:1px solid black;border-right:1px solid black;font-size:8px;text-align:left;width:22%;border-top:1px solid black;font-size:9px;"><b>Total</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;font-size:8px;border-top:1px solid black;">'.customFormatMoney($total).'</td>
          </tr>
          <tr> 
           <td colspan="2" style="border-top:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:37%;border-top:1px solid black;" colspan="2"><b>Isused</b>&nbsp;&nbsp;&nbsp;&nbsp;'.$lhc_row['issued_from'].'</td>
           <td colspan="3" style="text-align:left;font-size:7px;width:8%;vertical-align: baseline;border-top:1px solid black;"><b>MOBILE</b> :</td>
           <td colspan="3" style="border-right:1px solid black;font-size:8px;text-align:left;width:20%;vertical-align: baseline;border-top:1px solid black;">'.$lhc_row['o_mobile'].'</td>
           <td colspan="2" style="border-bottom:1px solid black;border-right:1px solid black;font-weight:bolder;font-size:8px; text-align:left;width:22%;border-top:1px solid black;font-size:9px;">Advance</td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;font-size:8px;">'.customFormatMoney($lhc_row['adv_amnt']).'</td>
          </tr>
          <tr> 
           <td rowspan="2" style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:37%;"><b>From </b></td>
           <td rowspan="2" style="border-bottom:1px solid black;text-align:left;width:8%;vertical-align: baseline;"></td>
           <td rowspan="2" style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;width:20%;vertical-align: baseline;"></td>
           <td  style="border-bottom:1px solid black;border-right:1px solid black;font-weight:bolder;font-size:8px; text-align:left;width:22%;border-top:1px solid black;font-size:8px;">'.@$master_tax[$sub[0]['title']].'</td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;font-size:8px;">'.$sub_0.'</td>
          </tr>
            <tr> 
           <td  style="border-bottom:1px solid black;font-size:8px;border-right:1px solid black;text-align:left;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$sub[1]['title']].'</b></td>
           <td style="border-bottom:1px solid black;text-align:right;font-size:8px;width:13%;border-top:1px solid black;">'.$sub_1.'</td>
          </tr>';

          if($lhc_row['payment_to'] == 'AGENT'){
          $output .='
          <tr> 
           <td rowspan="2" style="border-bottom:1px solid black;border-top:1px solid black;font-size:8px;border-right:1px solid black;text-align:center;width:65%;border-top:1px solid black;font-size:10px"><b>Lorry Advance Paid Through<br/>'.$agent_row['pan'].' - '.$agent_row['proprietor'].'</b></td>

           <td  style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;font-size:8px;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$sub[2]['title']].'</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;">'.$sub_2.'</td>
          </tr>';
          }else{
          $output .='
          <tr> 
           <td rowspan="2" style="border-bottom:1px solid black;border-top:1px solid black;font-size:8px;border-right:1px solid black;text-align:center;width:65%;border-top:1px solid black;"><b>Lorry Advance Paid Through<br/>'.$lhc_row['pan_no'].' - '.$own_row['o_name'].'</b></td>

           <td  style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;font-size:8px;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$sub[2]['title']].'</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;">'.$sub_2.'</td>
          </tr>';
          }

          $output .='
          <tr> 
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:left;font-size:8px;width:22%;border-top:1px solid black;"><b>'.@$master_tax[$sub[3]['title']].'</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;">'.$sub_3.'</td>
          </tr>
          <tr> 
           <td style="border-top:1px solid black;font-size:8px;text-align:left;width:14%;border-top:1px solid black;" colspan="2"><b></b></td>
           <td style="text-align:left;width:13%;border-top:1px solid black;font-size:8px;"><b></b></td>
           <td style="text-align:left;width:10%;font-size:8px;vertical-align: baseline;border-top:1px solid black;"><b></b></td>
           <td colspan="2" style="border-right:1px solid black;font-size:8px;text-align:left;width:28%;border-top:1px solid black;"><b></b></td>
           <td  style="border-right:1px solid black;text-align:left;font-size:8px;width:22%;border-top:1px solid black;"><b>Deduction</b></td>
           <td style="border-bottom:1px solid black;text-align:right;width:13%;border-top:1px solid black;font-size:8px;"> '.customFormatMoney($total =$sub_0 + $sub_1 + $sub_2 + $sub_3).'</td>
          </tr>
          
          <tr> 
           <td style="font-size:8px;text-align:left;width:14%;" colspan="2"></td>
           <td style="text-align:center;width:13%;font-size:8px;"></td>
           <td style="text-align:center;width:10%;vertical-align: baseline;font-size:8px;"></td>
           <td colspan="2" style="border-right:1px solid black;text-align:left;width:28%;font-size:8px;"></td>
           <td style="border-right:1px solid black;text-align:left;width:22%;font-weight:bolder;font-size:8px; ">Balance</td>
           <td style="text-align:right;width:13%;border-top:1px solid black;">'.customFormatMoney($total =$lhc_row['balance']).'</td>
          </tr>

          <tr> 
           <td style="border-top:1px solid black;border-right:1px solid black;text-align:center;width:27%;"></td>
           <td style="border-right:1px solid black;text-align:center;width:48%; border-top:1px solid black;"></td>
           <td style="text-align:center;width:3%;border-top:1px solid black;"></td>
           <td style="text-align:center;width:20%;border-top:1px solid black;"></td>
           <td style="text-align:center;width:2%;border-top:1px solid black;"></td>
          </tr>
          <tr> 
           <td style="border-right:1px solid black;text-align:center;width:27%;"></td>
           <td style="text-align:center;width:48%;border-right:1px solid black;"></td>
           <td style="text-align:center;width:3%;"></td>
           <td style="text-align:center;width:20%;"></td>
           <td style="text-align:center;width:2%;"></td>
          </tr>
          <tr> 
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:27%;"><b>Passed By</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:48%;"><b>Prepared By</b></td>
           <td style="border-bottom:1px solid black;border-right:1px solid black;text-align:center;width:25%;"><b>Driver\'s Signature</b></td>
          </tr>
          <tr>
             <th width="7%" style="border-bottom:1px solid black;font-weight:bolder">SR.NO</th>
             <th width="10%" style="border-bottom:1px solid black;font-weight:bolder">DATE</th>
             <th width="20%" style="border-bottom:1px solid black;font-weight:bolder">PAYMENT MODE</th>
             <th width="28%" style="border-bottom:1px solid black;font-weight:bolder">REF.NO</th>
             <th width="15%" style="border-bottom:1px solid black;font-weight:bolder">PAYMENT TYPE</th>
             <th width="20%" style="text-align:right;border-bottom:1px solid black;font-weight:bolder">AMOUNT</th>
          </tr>';
          if(count($bh_data) > 0){
             $cou = 1;
             $total = 0;
             foreach ($bh_data as $key => $bh_datas) {
                $total += $bh_datas['adj_amnt'];
                $a = explode(',', $bh_datas['payment_type']);
                foreach ($a as $key => $a_data) {
                   if($a_data == 'C'){
                      $output .='
                      <tr>
                      <td width="5%">'.$cou++.'</td>
                      <td width="10%">'.risFormatDate($bh_datas['payment_date'], 'd-m-Y').'</td>
                      <td width="20%">CASH</td>
                      <td width="30%"></td>
                      <td width="15%"></td>
                      <td width="20%" style="text-align:right">'.customFormatMoney($bh_datas['cash']).'</td>
                      </tr>';
                   }else{
                      if($bh_datas['payment_mode'] == 'NEFT'){
                         $pmode = 'NEFT';
                         $pref  = $bh_datas['neft_number'].'-'.$xbankname;
                      }else if($bh_datas['payment_mode'] == 'IMPS'){
                         $pmode = 'IMPS';
                         $pref  = $bh_datas['imps_number'].'-'.$xbankname;
                      }else if($bh_datas['payment_mode'] == 'RTGS'){
                         $pmode = 'RTGS';
                         $pref  = $bh_datas['rtgs_number'].'-'.$xbankname;
                      }else{
                         $pmode = 'CHEQUE';
                         $pref  = $bh_datas['cheque_number'].'-'.$xbankname;
                      }
                      $output .='
                      <tr>
                      <td width="5%">'.$cou++.'</td>
                      <td width="10%">'.risFormatDate($bh_datas['payment_date'], 'd-m-Y').'</td>
                      <td width="20%">BANK</td>
                      <td width="30%">'.$pref.'</td>
                      <td width="15%">'.$pmode.'</td>
                      <td width="20%" style="text-align:right">'.customFormatMoney($bh_datas['adj_amnt']).'</td>
                     </tr>';
                   }
                }
             }
          }
          $output .='
          <tr>
            <td width="80%" style="border-top:1px solid black;font-weight:bolder">TOTAL </td>
            <td width="20%" style="text-align:right;border-top:1px solid black;font-weight:bolder">'.customFormatMoney($total).'</td>
          </tr>
      </table>
   </body>
</html>';
$pdf->AddPage('P', 'A4');
$pdf->writeHTML($output, true, false, false, false, '');
$pdf->SetTitle($title);
$pdf->Output('lhc_no'.'_'.substr($lhc_row["lhc_no"],5).'.pdf', 'I');
?>