<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">BILLING SUMMERY</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">VENDOR</label>
               <div class="form-group">
                  <select class="form-control select2" style="width: 100%;" name="vendor_id" id="vendor_id">
                     <option value>ALL</option>
                     <?php 
                        $ven      = "SELECT * FROM `vendor_master` WHERE `status` = '0'";
                        $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['name'];?></option>
                     <?php } ?>
                  </select>
                  <input type="hidden" name="module" id="module" value="BREGSUM">
               </div>
            </div>
         </div>
         <div class="col-lg-12">
            <div class="form-group">
               <label class="capital">BILL</label>
               <div class="form-group">
                  <select class="form-control select2" style="width: 100%;" name="bill_no" id="bill_no">
                     <option value>ALL</option>
                     <?php 
                        $bill      = "SELECT * FROM `billing` GROUP BY invoice_no";
                        $bill_res  = mysqli_query($conn,$bill);
                        while ($bill_row = mysqli_fetch_assoc($bill_res)) { ?>
                     <option value="<?php echo $bill_row['invoice_no'];?>"><?php echo $bill_row['invoice_no'];?></option>
                     <?php } ?>
                  </select>
                  <input type="hidden" name="module" id="module" value="BREGSUM">
               </div>
            </div>
         </div>
         <div class="col-lg-12">
            <div class="form-group">
               <label class="capital">PAID BY</label>
               <div class="form-group">
                  <select class="form-control select2" name="gst_paid_by" id="gst_paid_by">
                    <option></option>
                    <option value="CONSIGNOR">CONSIGNOR</option>
                    <option value="CONSIGNEE">CONSIGNEE</option>
                    <option value="TRANSPORTER">TRANSPORTER</option>
                    <option value="OTHER">OTHER</option>
                    <option value="NOT APPLICABLE">NOT APPLICABLE</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>
               
               <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 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">
                  <thead>
                     <tr>
                        <th class="text-center" width="50">BILL NO</th>
                        <th class="text-center" width="70">BILL DATE</th>
                        <th class="text-left">PARTY</th>
                        <th class="text-center" width="5">GST</th>
                        <th class="text-center" width="5">GROSS AMOUNT</th>
                        <th class="text-center" width="5">TOTAL ADDITION</th>
                        <th class="text-center" width="5">TOTAL DEDUCTION</th>
                        <th class="text-center" width="5">NET AMOUNT</th>
                        <th class="text-center" width="5">TOTAL GST</th>
                        <th class="text-center" width="5">PAID BY</th>
                     </tr>
                  </thead>
                  <tbody>
                     <tr>
                        <td colspan="10" 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() {
    $('#vendor_id').select2();
    $('#lr_no').select2();
    $('#bill_no').select2();
    $('#gst_paid_by').select2();
    jQuery(document).on('click', '#btn-genrate', function(e){
      getData();
    });

    jQuery(document).on('click', '#ExportPdf', function(e){
      exportReport();
    });

    jQuery(document).on('click', '#btnExport', function(e){
      ExportExcel();
    });

  });
  
  function ExportExcel(){
    $("#list_data").table2excel({
      filename: "billing_summery.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();
    url += '&bill_no=' + jQuery('#bill_no').val();
    window.open(url, "_blank");
    // $a.attr("href", url );
    //jQuery("body").append($a);
    //$a[0].click();
    //$a.remove();
  }
  
  function getData() {
    var url = "report/billing_summery_data.php?>" + '&start_date=' + jQuery('#start_date').val() + '&end_date=' + jQuery('#end_date').val() + '&vendor_id=' + jQuery('#vendor_id').val() + '&bill_no=' + jQuery('#bill_no').val() + '&gst_paid_by=' + jQuery('#gst_paid_by').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="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);  
            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="10" class="text-center">No Data found to show !!</td></tr>');
            jQuery('.total-records').html(0);
          }
        }
      }
    });
  }
</script>