@include('dashboard.include.header')

  
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0"></h1>
            <a href="/reseller">Go Back</a>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/home">Home</a></li>
              <li class="breadcrumb-item active">Reseller Commision</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">

        <div class="card card-success">
        <div class="card-header">
            <h3 class="card-title">Add Commision</h3>
        </div>
            <div class="card-body">
            @foreach($datas2 as $dadetail)
            <div class="row">
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label for="">Reseller Name &nbsp;&nbsp;: &nbsp;&nbsp;</label>{{ $dadetail->companyname}}
                    </div>
                </div>
                <div class="col-md-5"> 
                    <label for="">Address&nbsp;&nbsp; : &nbsp;&nbsp;</label>{{ $dadetail->address}}
                </div>
                <div class="col-md-3"> 
                    <label for="">Phone Number&nbsp;&nbsp; : &nbsp;&nbsp;</label>{{ $dadetail->phone}}
                </div>
            </div>
            @endforeach
            <hr> <br>

            <form class="form-horizontal" method="POST" action="/addcommision">
                {{csrf_field()}}
            <div class="row">
            @foreach($datas2 as $datad)<input type="hidden" class="form-control" value="{{$datad->id}}" name="sid" required> @endforeach
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label>Reseller Company</label>
                        <select class="form-control select2" name="reseller" style="width: 100%;" required>
                            <option value="" selected="selected" disabled>Select</option>
                            @foreach($resel as $data)
                            @if($data->id != $nowid)
                            <option value="{{$data->id}}">{{$data->companyname}}</option>
                            @endif
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-md-3"> 
                    <div class="form-group">
                        <label for="">Commision </label><input type="number" class="form-control" name="Commision" placeholder="Commision" required>
                    </div>
                </div>        
                <div class="col-md-1" style="padding-top:30px;"><button type="submit" class="btn btn-block btn-primary">Add</button> </div>
           
            </div> 
            </form>
<hr> <br>
            <table id="example2" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Reseller Company</th>
                                <th>Commision</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                    @foreach($supdata as $supdatad)
                        <tr>
                            <td>{{ $supdatad->id}}</td>
                            <td>{{ $supdatad->comgetreseller->companyname}}</td>
                            <td>{{ $supdatad->commischarge}}</td>
                            <td class="text-center">
                            @if($supdatad->status=='0')
                            <span class="badge badge-warning">Not Activate</span>
                            @elseif($supdatad->status=='1')
                            <span class="badge badge-success">Active</span>
                            @endif
                            </td> 
                            <td class="text-center">
                            <button type="button" class="btn btn-primary btn-xs" data-res="{{$supdatad->resellerid}}"  data-reseller="{{$supdatad->commisereseller}}" data-charge="{{$supdatad->commischarge}}" data-status="{{$supdatad->status}}" data-id="{{$supdatad->id}}" data-toggle="modal" data-target="#bankmodel">Edit</button>
                                <a href="" data-supllierid="{{$supdatad->resellerid}}" data-id="{{$supdatad->id}}" class="btn btn-danger btn-xs button bankdetailsdelete" data-url="">Delete </a>
                            </td>                        
                        </tr>
                    @endforeach
                    </tbody>
                    </table>
            </div>
        </div>
      </div>
    </section>
  </div>




  <div class="modal fade" id="bankmodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered " role="document">
        <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Supplier Bank Details Change</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <form class="form-horizontal" method="POST" action="/commisionupdate">
            {{csrf_field()}}
        <div class="modal-body">  
            <input type="hidden" name="id" id="id">    
            <input type="hidden" name="supid" id="supid">    
            <div class="form-group">
                <label>Reseller Company</label>
                <select class="form-control select2" name="reseller" id="reseller" style="width: 100%;" required>
                    <option value="" selected="selected" disabled>Select</option>
                    @foreach($resel as $data)
                        @if($data->id != $nowid)
                        <option value="{{$data->id}}">{{$data->companyname}}</option>
                        @endif
                    @endforeach
                </select>
            </div>
            <div class="form-group">
                <label for="">Commision </label><input type="number" class="form-control" id="Commision" name="Commision" placeholder="Commision" required>
            </div>
            <div class="form-group">
                <label for="">Paid Status</label>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="paidstatus" value="" id="flexCheckChecked" checked>
                    <label class="form-check-label" for="flexCheckChecked">Paid</label>
                </div>
            </div>

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary">Save changes</button>
        </div>
        </form>
        </div>
    </div>
</div>


  @include('dashboard.include.footer');

<script>
$(document).ready(function() {
    $('#example').DataTable();
    $('#example2').DataTable();
} );
</script>
<script>

$(document).on('click', '.bankdetailsdelete', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    var supid = $(this).data('supllierid');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove this Entry",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "{{url('/commisiondelete')}}/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                window.location.href = "/commision/"+supid;
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Removed", "error");
                }
            })
});


      
$('#bankmodel').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var id = button.data('id') 
var reseller = button.data('reseller') 
var charge = button.data('charge') 
var status = button.data('status') 
var res = button.data('res') 



var modal = $(this)
modal.find('.modal-body #id').val(id)
modal.find('.modal-body #supid').val(res)
modal.find('.modal-body #Commision').val(charge)
$("#reseller").val(reseller).change();

if(status==1){
    $( "#flexCheckChecked" ).prop( "checked", true );
}else{
    $( "#flexCheckChecked" ).prop( "checked", false  );
}
})


$('.select2').select2()

</script>