<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>
<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">LHC REGISTER</h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="content-header bottom35-report bottom40">
    <div class="row">
      <form>
        <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'))?>"/>
                    </div>
                </div>
            </div>
            <div class="col-lg-3">
              <div class="form-group">
                  <label class="capital">OWNER</label>
                  <div class="form-group">
                    <select class="form-control select2" style="width: 100%;" name="owner" id="owner">
                      <option value>ALL</option>
                      <?php 
                      $ven      = "SELECT * FROM `truck_mst`";
                      $ven_res  = mysqli_query($conn,$ven);
                      while ($ven_row = mysqli_fetch_assoc($ven_res)) { ?>
                      <option value="<?php echo $ven_row['id'];?>"><?php echo $ven_row['o_name'];?></option>
                      <?php } ?>
                    </select>
                  </div>
              </div>
            </div>
            <div class="col-lg-2">
              <div class="form-group">
                  <label class="capital">AGENT</label>
                  <div class="form-group">
                    <select class="form-control select2" style="width: 100%;" name="agent" id="agent">
                      <option value>ALL</option>
                      <?php 
                      $lr      = "SELECT * FROM `lhc` WHERE agent !='' GROUP BY agent";
                      $lr_res  = mysqli_query($conn,$lr);
                      while ($lr_row = mysqli_fetch_assoc($lr_res)) { ?>
                      <option value="<?php echo $lr_row['agent'];?>"><?php echo $lr_row['agent'];?></option>
                      <?php } ?>
                    </select>
                  </div>
              </div>
            </div>
            <div class="col-lg-2">
              <div class="form-group">
                  <label class="capital">LHC NO</label>
                  <div class="form-group">
                    <select class="form-control select2" style="width: 100%;" name="lhc_no" id="lhc_no">
                      <option value>ALL</option>
                      <?php 
                      $bill      = "SELECT * FROM `lhc` GROUP BY lhc_no";
                      $bill_res  = mysqli_query($conn,$bill);
                      while ($bill_row = mysqli_fetch_assoc($bill_res)) { ?>
                      <option value="<?php echo $bill_row['lhc_no'];?>"><?php echo $bill_row['lhc_no'];?></option>
                      <?php } ?>
                    </select>
                    <input type="hidden" name="module" id="module" value="LHCREG">
                  </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" formaction='report/excel_export.php?type=LHCREG'><i class="fa fa-file-excel-o" aria-hidden="true"></i> EXCEL </button>
                <button class="btn btn-primary" formaction='report/export_pdf.php' target="_blank"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> PDF</button>
              </div>
            </div>
            
        </div>
      </form>
    </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">LHC DATE</th>
                              <th class="text-center" width="50">TRUCK NO</th>
                              <th class="text-center" width="100">FROM - TO</th>
                              <th class="text-center" width="100">OWNER</th>
                              <th class="text-center" width="100">AGENT</th>
                              <th class="text-center" width="100">LORRY HIRE CHARGES</th>
                              <th class="text-center" width="50">TOTAL ADDITION</th>
                              <th class="text-center" width="50">DISEL</th>
                              <th class="text-center" width="50">TOTAL DEDUCTION</th>
                              <th class="text-center" width="50">ADVANCE</th>
                              <th class="text-center" width="50">PENDING</th>
                              <th class="text-center" width="50">BANK</th>
                              <th class="text-center" width="50">CASH</th>
                              <th class="text-center" width="50">PAYMENT</th>
                            </tr>
                          </thead>
                          <tbody>
                              <tr>
                                  <td colspan="15" 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(document).on('click', '#btn-genrate', function(e){
      getData();
    });
  });
  
  function getData() {
    var url = "report/lhc_register_data.php?>" + '&start_date=' + jQuery('#start_date').val() + '&end_date=' + jQuery('#end_date').val() + '&owner=' + jQuery('#owner').val() + '&agent=' + jQuery('#agent').val()+ '&lhc_no=' + jQuery('#lhc_no').val();
    //jQuery('#list_data .start_date').html(jQuery('#start_date').text());
    //jQuery('#list_data .end_date').html(jQuery('#end_date').text());
    jQuery.ajax({
      type        : 'GET',
      url         :  url,
      dataType    : 'JSON',
      beforeSend:function(){
        jQuery('#list_data tbody').html('<tr><td colspan="15" 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);  
            jQuery('.min_data').html(data.min_data);  
            jQuery('.max_data').html(data.max_data);
            jQuery('.average').html(data.average);
          } else {
            jQuery('#list_data tbody').html('<tr><td colspan="15" class="text-center">No Data found to show !!</td></tr>');
            jQuery('.total-records').html(0);
          }
        }
      }
    });
  }
</script>