<!DOCTYPE html>
<html>
<head>
<!-- TABLES CSS CODE -->
<?php include"comman/code_css_datatable.php"; ?>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Left side column. contains the logo and sidebar -->
  
  <?php include"sidebar.php"; ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Agent Comissions
        <small>View/Search Agent Comissions</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Agent Comissions</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- ********** ALERT MESSAGE START******* -->
        <?php include"comman/code_flashdata.php"; ?>
        <!-- ********** ALERT MESSAGE END******* -->
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header with-border">
            <div class="row">
                <div class="col-md-12">
                    <!-- <div class="col-md-3">
                        <label for="brand_id" class=" control-label">Year</label>
                        <input type="number" name="year" id="year" class="form-control">
                    </div> -->
                    <div class="col-md-3">
                        <label for="month" class=" control-label">Month & Year</label>
                        <input type="month" name="month" id="month" class="form-control">
                    </div>
                    <div class="col-md-3">
                        <label for="com_rate" class=" control-label">Comission Rate</label>
                        <input type="number" name="com_rate" id="com_rate" class="form-control">
                    </div>
                    <div class="col-md-3">
                        <label for="agent_id" class=" control-label">Agent</label>
                          <select class="form-control select2" id="agent_id" name="agent_id"  style="width: 100%;">
                            <?php
                               $query1="select * from db_agent where status='1'";
                               $q1=$this->db->query($query1);
                               if($q1->num_rows($q1)>0)
                                {  echo '<option value="">-Select-</option>'; 
                                    foreach($q1->result() as $res1)
                                  { 
                                    echo "<option value='".$res1->id."'>".$res1->agent."</option>";
                                  }
                                }
                                else
                                {
                                   ?>
                            <option value="">No Records Found</option>
                            <?php
                               }
                               ?>
                         </select>
                    </div>
                    
                  </div>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-striped" width="100%">
                <thead class="bg-primary ">
                <tr>
                  <th>Waybill ID</th>
                  <th>Customer Name</th>
                  <th>Amount</th>
                  <th>Delivery Fee</th>
                  <th>Platform</th>
                  <th>Sale</th>
                  <th>Comission</th>
                </tr>
                </thead>
                <tbody>
				
                </tbody>
                <tfoot>
                    <tr>
                        <th>
                            <th colspan="4" style="text-align: right;">Total</th>
                            <th ><label id="lbl_sale_all"></label></th>
                            <th ><label id="lbl_com_all"></label></th>
                        </th>
                    </tr>
                </tfoot>               
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include"footer.php"; ?>
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<!-- SOUND CODE -->
<?php include"comman/code_js_sound.php"; ?>
<!-- TABLES CODE -->
<?php include"comman/code_js_datatable.php"; ?>

<!-- <script src="<?php echo $theme_link; ?>js/agent.js"></script> -->

 <script type="text/javascript">
     $('#example2').DataTable({
        columnDefs: [
            { className: "dt-body-right", "targets": [ 2,3,5,6 ] }
        ]
     });
var table;
// $(document).ready(function() {
//     //datatables
//     table = $('#example2').DataTable({ 

//         "processing": true, //Feature control the processing indicator.
//         "serverSide": true, //Feature control DataTables' server-side processing mode.
//         "order": [], //Initial no order.
//         "responsive": true,

//         // Load data for the table's content from an Ajax source
//         "ajax": {
//             "url": "<?php //echo site_url('agent/ajax_list')?>",
//             "type": "POST"
//         },

//         //Set column definition initialisation properties.
//         "columnDefs": [
//         { 
//             "targets": [ 2 ], //first column / numbering column
//             "orderable": false, //set not orderable
//         },
//         ],
//     });
//     new $.fn.dataTable.FixedHeader( table );
// });
</script>
<script>
    $('#agent_id').on('change',function(){
      fill_tbData();
    });
</script>
<script>
  function fill_tbData(){
      var month = $('#month').val();
      var com_rate = $('#com_rate').val();
      var agent_id = $('#agent_id').val();

    //console.log(month+"           "+com_rate+"           "+agent_id);
    if(month==""|| com_rate==""){
        toastr["error"]("Sorry! Select month and rate.Try again!");
    }else{
      $.ajax({
        url:"<?php echo site_url('agent/search_agent_com_data')?>",
        type: 'post',
        data: {month:month,com_rate:com_rate,agent_id:agent_id},
        dataType: 'json',
        success: function (data) {
            var table;
            var tot_sale =0;
            var tot_com =0;
            table = $('#example2').DataTable();
            table.clear();
            var indexNo = 1;
            if(data!='') {             
              $.each(data.agent_com_info, function() {
                var s_sale_amt =  parseFloat(this['sale_amt']);
                var s_com_amt =  parseFloat(this['com_amt']);
                table.row.add([this['waybill'],this['customer_name'],this['grand_total'],this['other_charges_amt'],this['platform'],s_sale_amt.toFixed(2),s_com_amt.toFixed(2)]);
                indexNo++;
                tot_sale +=s_sale_amt;
                tot_com +=s_com_amt;
              });
            }else {
            swal("Something Wrong","Data Not Found !!","warning");
            }
            table.draw();
            $('#lbl_sale_all').empty();
            $('#lbl_sale_all').append(tot_sale.toFixed(2));
            $('#lbl_com_all').empty();
            $('#lbl_com_all').append(tot_com.toFixed(2));

        },
        error: function (xhr, ajaxOptions, thrownError) {
          console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
      });
    }
  }
</script>
<script type="text/javascript">
$(document).ready(function () { setTimeout(function() {$( ".alert-dismissable" ).fadeOut( 1000, function() {});}, 3000); });
</script>
<!-- Make sidebar menu hughlighter/selector -->
<script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>
	
</body>
</html>
