@extends('layouts.admin')

@section('content')
<div class="row">
    <div class="col-12">
        <div class="card mt-2">
            <div class="card-header">
                <h3 class="card-title">
                 Collectors List
                </h3>
              
            </div>
            <div class="card-body table-responsive">
          


@csrf
<div class="row ">

<div class="col-lg-2 form-group">
                <label class="required">Finances</label>
                <select class="form-control {{ $errors->has('level') ? 'is-invalid' : '' }}" name="finances" id="finances">
                    <option value >
                        {{ trans('global.pleaseSelect') }}</option>
                        @foreach($finances as $orgCode => $finances)
                        <option value="{{ $orgCode }}" {{ (in_array($orgCode, old('finances', [])) || isset($collector) && $collector->finances->contains($orgCode)) ? 'selected' : '' }}>
                            {{ $finances }}
                        </option>
                    @endforeach
                </select>
               
            </div>

                <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
                
           
            
            <div class="form-group col-lg-1">
            <label class="required">&nbsp</label>
                <button class="btn btn-primary btn-block float-right" name="btnload" id="btnload" type="submit">
                   Load
               </button>
             
              </div>
              <div class="col-lg-1 form-group">
                <label class="required">&nbsp</label>
                <a href="{{ route('admin.get_registered_collector') }}" class="btn btn-secondary btn-block float-right">Reset</a>
                
              </div>
              </div>
              
</div>
<div class="table-responsive">
                <table class="table table-head-fixed table-bordered text-nowrap" id="data-table">
                    <thead>
                        <tr>
                            <th width="30px"><input type="checkbox" class="check" id="check_all"></th>
                            <th>Finance</th>
                            <th>Collector Name</th>
                            <th>Mobile</th>
                            <th>Action</th>
                            
                        </tr>
                    </thead>
                    <tbody class="text-nowrap">
                       
                       
                    </tbody>
                </table>
                </div>
            </div>
        </div>
    </div>
</div>

@endsection

@section('scripts')

<script>
function approveform(id){
  if(confirm("Are you sure you want to approve the form?") == false) {
              return false;
          }
    var url = "{{ url('approve-form') }}/"+id;
      $.ajax({
        url: url,
        method: 'get',
        success: function(result){
              alert(result);
              $("#btnload").click()

              //window.location.reload(false); 
          }});
}
function rejectform(id){
  
    $('#rejectid').val(id);
  $('.modal').modal();
}


 
    $(document).ready(function() {


     
    $("#btnload").button().click(function(){
      
        var datas = {
        "_token": $('#token').val(),
        "finances": $('#finances').val(),
    };
        var t = $('.table').DataTable({
            dom: 'Blfrtip',
            "lengthMenu": [[10, 100, 500, 1000], [10, 100, 500, 1000]],
            searchable:false,
          processing: true,
        serverSide: true,
        responsive: true,
        destroy: true,
        "buttons": [
                          
                          {
                              "extend": 'excel',
                              "text": 'Excel',
                              "titleAttr": 'Excel',                               
                              "action": newexportaction,
                              className: 'btn btn-warning',
                   exportOptions: {
                   columns: ':not(:last-child)',
               
               }
                          },
               
],
        
        "ajax": {
    "url": '{{ route('admin.get_registered_collector') }}',
    "type": "POST",
    "data":datas,
},

       
        columns: [
               {  data : 'DT_RowIndex',
                orderable: false, 
                    searchable: false,
         render : function(data, type, row) {
             datasss = data+'<input type="checkbox" class="approve_class" name="sel_app[]" value="submission_no" >'
           return datasss;
                                        }},
                   
                { "data": "finance" },
                {"data": "name"},
                {"data": "mobile"},
                
                {  data : 'action',
         render : function(data, type, row) {
            
           return data;

  
       },
       },    
            ]    
           
        });

        var buttons = new $.fn.dataTable.Buttons(t, {
            buttons: [
                {
                    extend: 'excel',
                    className: 'btn btn-warning',
                    exportOptions: {
                    columns: ':not(:last-child)',
                
                }
                },
               
            ],
}).container().appendTo($('#buttons'));
      
    });
    
    
    $('#check_all').on('click',function(){
        if(this.checked){
            $('.approve_class').each(function(){
                this.checked = true;
            });
        }else{
             $('.approve_class').each(function(){
                this.checked = false;
            });
        }
    });
    
  
});   


</script>
@endsection
