<style type="text/css">
.text-right{
   text-align: right !important;
}
.text-left{
   text-align: left !important;
}
.hitz-report {
   background: #fff !important;
   padding: 6px 0px 9px 0 !important;
}
</style>
<?php 
$vendor = mysqli_query($conn, "SELECT * FROM `vendor_master` WHERE `type` = 'A' ORDER BY name ASC");
$data = array();
while ($rows = mysqli_fetch_assoc($vendor)) {
   $data[] = $rows;
}

?>
<section class="content-header">
   <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
         <h3 class="capital font15 padding5 bold">PENDING LHC FOR BALANCE PAYMENT</h3>
      </div>
   </div>
</section>
<hr class="bottom35">
<section class="content-header bottom35-report bottom40">
   <div class="row">
      <div class="col-md-12 hitz-report">
            <div class="col-lg-2">
               <div class="form-group">
                  <label class="capital">START DATE</label>
                  <div class="input-group date">
                     <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                     </div>
                     <input type="text" size="35" id="start_date" name="start_date" class="form-control date-picker start_date" placeholder="DATE" autocomplete="off" value="<?php echo risFormatDate(date('01-04-Y'))?>"/>
                  </div>
               </div>
            </div>
            <div class="col-lg-2">
               <div class="form-group">
                  <label class="capital">END DATE</label>
                  <div class="input-group date">
                     <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                     </div>
                     <input type="text" size="35" id="end_date" name="end_date" class="form-control date-picker end_date" placeholder="DATE" autocomplete="off" value="<?php echo risFormatDate(date('d-m-Y'))?>"/>
                     <input type="hidden" name="module" id="module" value="PLFBP">
                  </div>
               </div>
            </div>
            <div class="col-lg-3">
              <div class="form-group">
                  <label class="capital">BROKER</label>
                  <div class="form-group">
                     <select class="form-control select2" style="width: 100%;" name="agent_id" id="agent_id">
                     <option value>ALL</option>
                     <?php foreach ($data as $key => $datas) { ?>
                     <option value="<?php echo $datas['name']?>"><?php echo $datas['name']?></option>
                     <?php } ?> 
                     </select>
                    <input type="hidden" name="module" id="module" value="PLFL">
                  </div>
              </div>
            </div>
            <div class="col-md-3" style="position: relative;top: 10px;">
               <div class="form-group">
                  <button type="button" class="btn btn-primary" id="btn-genrate"><i class="fa fa-refresh" aria-hidden="true"></i></button>
                  <button type='submit' class="btn btn-primary" id="btnExport"><i class="fa fa-file-excel-o" aria-hidden="true"></i> EXCEL </button>
                  <button type='button' class="btn btn-primary" id="ExportPdf" target="_BLANK"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> PDF</button>
                </div>
            </div>
         </div>
   </div>
   <br/>
   <div class="row">
      <div class="col-md-12">
         <div class="col-md-12">
            <div class="box box-info">
               <div class="box-body table-responsive">
                  <table id="list_data" class="table table-bordered table-striped list_data">
                     <thead>
                        <tr>
                          <th class="text-center" width="50">LHC NO</th>
                          <th class="text-center" width="50">DATE</th>
                          <th class="text-center" width="50">LR NO</th>
                          <th class="text-center" width="50">TRUCK NO</th>
                          <th class="text-center" width="120">FROM - TO</th>
                          <th class="text-center" width="150">CONSIGNOR</th>
                          <th class="text-center" width="170">CONSIGNEE</th>
                          <th class="text-center" width="150">AGENT</th>
                          <th class="text-center" width="70">T.AMOUNT</th>
                          <th class="text-center" width="70">ADVANCE</th>
                          <th class="text-center" width="70">ADDITION</th>
                          <th class="text-center" width="70">DEDUCTION</th>
                          <th class="text-center" width="70">PEN.AMOUNT</th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td colspan="11" class="text-center">No Data found to show !!</td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
         </div>
      </div>
   </div>
</section>
<script type="text/javascript">
  jQuery(document).ready(function() {
    $('#owner').select2();
    $('#agent').select2();
    $('#lhc_no').select2();
    jQuery('#agent_id').select2();
    jQuery(document).on('click', '#btn-genrate', function(e){
      getData();
    });
    jQuery(document).on('click', '#btnExport', function(e){
      ExportExcel();
    });
    jQuery(document).on('click', '#ExportPdf', function(e){
      exportReport();
    });
  });

  function ExportExcel(){
    $("#list_data").table2excel({
      filename: "PENDING LHC BALANCE PAYMENT REGISTER.xls"
    });
  }

  function exportReport() {
    var url = "report/export_pdf.php?module=" + jQuery('#module').val();
    url += '&start_date=' + jQuery('#start_date').val();
    url += '&end_date=' + jQuery('#end_date').val();
    url += '&p1=' + jQuery('#agent_id').val();
    window.open(url, "_blank");
    // $a.attr("href", url );
    //jQuery("body").append($a);
    //$a[0].click();
    //$a.remove();
  }
  function getData() {
    var url = "report/pending_lhc_balance_payment_data.php?>" + '&start_date=' + jQuery('#start_date').val() + '&end_date=' + jQuery('#end_date').val() + '&agent_id=' + jQuery('#agent_id').val();
    jQuery.ajax({
      type        : 'GET',
      url         :  url,
      dataType    : 'JSON',
      beforeSend:function(){
        jQuery('#list_data tbody').html('<tr><td colspan="10" class="text-center"><i class="fa fa-2x fa-spin fa-spinner"></i> Loading Data....</td></tr>');
      },
      success: function(data) {
        if(data.status == 'success') {
          if(data.tbody != '') {
            jQuery('#list_data tbody').html(data.tbody);
            jQuery('.total-records').html(data.total_count);  
          } else {
            jQuery('#list_data tbody').html('<tr><td colspan="10" class="text-center">No Data found to show !!</td></tr>');
            jQuery('.total-records').html(0);
          }
        }
      }
    });
  }
</script>