<?php 
$truck = mysqli_query($conn, "SELECT * FROM `truck_mst`");
$truck_data = array();
while ($truck_row = mysqli_fetch_assoc($truck)) {
  $truck_data[] = $truck_row;
}
?>
<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">MAINTANCE REPORT</h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="content-header bottom35-report bottom40">
  <div class="row">
    <div class="col-md-3 hitz-report">
      <div class="col-lg-12">
        <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-12">
        <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-12">
        <div class="form-group">
          <label class="capital">TRUCK</label>
          <div class="form-group">
            <select class="form-control select2" style="width: 100%;" name="truck_id" id="truck_id">
              <option value></option>
              <?php 
              foreach ($truck_data as $key => $truck_datas) { ?>
              <option value="<?php echo $truck_datas['id']?>"><?php echo $truck_datas['truck_no']?></option>
              <?php } ?>
            </select>
          </div>
        </div>
      </div>
      <div class="col-lg-12">
        <div class="form-group">
          <label class="capital">REPORT TYPE</label>
          <div class="form-group">
            <select class="form-control select2" style="width: 100%;" name="report_type" id="report_type">
              <option value="S">SUMMARY</option>
              <option value="D">DETAILS</option>
            </select>
          </div>
        </div>
      </div>
      <div class="col-lg-12">
        <div class="form-group">
          <button type="button" class="btn btn-primary" id="btn-genrate"><i class="fa fa-refresh" aria-hidden="true"></i></button>
        </div>
      </div>
    </div>
    <div class="col-md-9">
      <div class="box box-info">
        <div class="box-body table-responsive">
          <table id="list_data" class="table table-bordered table-striped list_data">
            <tbody>
              <tr>
                <td colspan="8" class="text-center">No Data found to show !!</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</section>

<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery('#truck_id').select2();
    jQuery('#report_type').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: "OUTSTANDING_REPORT.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 += '&vendor_id=' + jQuery('#vendor_id').val();
    window.open(url, "_blank");
  }
*/
  function getData() {
    var url = "report/maintance_report_data.php?>" + '&start_date=' + jQuery('#start_date').val() + '&end_date=' + jQuery('#end_date').val() + '&truck_id=' + jQuery('#truck_id').val()+ '&report_type=' + jQuery('#report_type').val();
    jQuery.ajax({
      type        : 'GET',
      url         :  url,
      dataType    : 'JSON',
      beforeSend:function(){
        jQuery('#list_data tbody').html('<tr><td colspan="7" 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);
          } else {
            jQuery('#list_data tbody').html('<tr><td colspan="7" class="text-center">No Data found to show !!</td></tr>');
            jQuery('.total-records').html(0);
          }
        }
      }
    });
  }
</script>