@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">Reseller Received COD</h1>
          </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 Received COD</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">

    <form method="post" action="/receivedcodfilter">
        {{csrf_field()}}
        <div class="row">
    
                <div class="col-md-4">
                    <div class="form-group">
                        <label>Reseller name</label>
                        <select class="form-control select2" name="resller" id="resller" style="width: 100%;" required>
                            <option value="" selected="selected" disabled>Select</option>
                                @foreach($delise as $data)
                                <option value="{{ $data->id }}">{{ $data->companyname }}</option>
                                @endforeach
                        </select>
                    </div>
                </div>

            <div class="col-md-2" style="padding-top:30px;"><button type="submit" class="btn btn-primary btn-block">Search</button></div>
        </form>   
        <div class="col-md-3"></div>
    <div class="col-md-3">
    <form method="post" action="/resellerpaymentexcel">
        {{csrf_field()}}
    <button type="submit" name="payment" value="payment" class="btn btn-dark btn-block">Generate Payment Excel</button>
    <button type="submit" name="commission" value="commission" class="btn btn-success btn-block">Generate Commission</button>
    </form>  
    </div>


        
  </div>

  
<br><br>
            <div class="col-md-12">
                <table id="example2" class="table table-bordered" style="width:100%;font-size: 10px;">
                    <thead>
                        <tr>
                            <th>Payment ID</th>
                            <th>Company</th>
                            <th>Collected COD</th>
                            <th>Delivery Charge</th>
                            <th>Service Charge</th>
                            <th>Products Charge</th>
                            <th>Commision</th>
                            <th>Advance</th>
                            <th>Paid Amount</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                        <tbody>
                            @foreach($repay as $data)
                            <tr>
                                <td>{{$data->id}}</td>
                                <td>{{$data->getresellerd2->companyname}}</td>
                                <td>{{$data->collectedcod}}</td>
                                <td>{{$data->deliverycharge}}</td>
                                <td>{{$data->servicecharge}}</td>
                                <td>{{$data->productscharge}}</td>
                                <td>{{$data->commision}}</td>
                                <td>{{$data->advance}}</td>
                                <td>{{$data->paidamount}}</td>
                                <td>
                                @if($data->status == 0)
                                <span class="badge badge-warning">Not Paid</span>
                                @else
                                <span class="badge badge-success">Paid</span>
                                @endif
                                </td>
                                <td>
                                @if($data->status == 0)
                                <button type="button" class="btn btn-primary btn-xs" data-id="{{$data->id}}" data-status="{{$data->status}}"   data-toggle="modal" data-target="#supmodel">Edit</button>
                                <a data-id="{{$data->id}}" target="_blank" class="btn btn-primary btn-xs" href="resellerpaymentorders/{{$data->id}}">View</a></td>
                                @else
                                <a data-id="{{$data->id}}" target="_blank" class="btn btn-primary btn-xs" href="resellerpaymentorders/{{$data->id}}">View</a></td>
                                @endif
                            </tr>
                            @endforeach
                        </tbody>
                    </thead>
                </table>
            </div>
        </div>
        </div>
      

     

      </div>
    </section>
  </div>


<div class="modal fade" id="supmodel" 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">Payment 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 resellerpaymentform" method="POST">
          {{csrf_field()}}
      <div class="modal-body"> 
          <input type="hidden" name="id" id="id">    
                <div class="form-group">
                    <label for="">Paid Date :</label>
                        <div class="input-group date" id="reservationdate" data-target-input="nearest">
                            <input type="text" class="form-control datetimepicker-input" value="" id="paid_date" name="paid_date" data-target="#reservationdate"/  required>
                            <div class="input-group-append" data-target="#reservationdate" data-toggle="datetimepicker">
                                <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                            </div>
                        </div>
                </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>
$('#reservationdate').datetimepicker({
    format: 'YYYY/MM/DD'
    });


  $(document).ready(function() {
    $('#example2').DataTable();
} );

$(function () {
$('.select2').select2()
})


$('#supmodel').on('show.bs.modal', function (event) {

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var status = button.data('status') 


var modal = $(this)
modal.find('.modal-body #id').val(recipient)

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



    $('.resellerpaymentform').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/resellerpayupdate",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (data, code, ex) {
                toastr.success('Payment Details Update successfully!')
                $("#supmodel").modal('hide');  
                location.reload();
                jQuery.each(data, function(key,value){
        });

            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });
</script>