<?php echo $__env->make('dashboard.include.header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

  
  <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="/deliveryserice">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">Add Tracking Range</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 Tracking Range</h3>
        </div>
            <div class="card-body">
            <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dadetail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="row">
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label for="">Delivery Service Name &nbsp;&nbsp;: &nbsp;&nbsp;</label><?php echo e($dadetail->deliveryname); ?>

                    </div>
                </div>
                <div class="col-md-5"> 
                    <label for="">Address&nbsp;&nbsp; : &nbsp;&nbsp;</label><?php echo e($dadetail->deliveryaddress); ?>

                </div>
                <div class="col-md-3"> 
                    <label for="">Phone Number&nbsp;&nbsp; : &nbsp;&nbsp;</label><?php echo e($dadetail->deliveryphone); ?>

                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <hr> <br>

            <form class="form-horizontal" method="POST" action="/adddeliveryrang">
                <?php echo e(csrf_field()); ?>

            <div class="row">
                <div class="col-md-2">
                <label for="">Count</label><br>
                    <span id="net_amo">000</span>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><input type="hidden" class="form-control" value="<?php echo e($datad->id); ?>" name="sid" required> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <label for="">Min Number</label><input type="number" class="form-control" id="min_no" name="min_no" placeholder="Min Number" required>
                    </div>
                </div>
                <div class="col-md-1" style="padding-top:25px;" align="center"><h1><</h1> </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="">Max Number</label><input type="number" class="form-control" id="max_no" name="max_no" placeholder="Max Number" required>
                    </div>
                </div>
                <div class="col-md-3" style="padding-top:32px;"><button type="submit" class="btn btn-block btn-primary">Add Tracking Range</button> </div>
           
            </div> 
            </form>
<hr> <br>
            <table id="example2" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Id</th>
                                <th>Invoice ID</th>
                                <th>Tracking Number</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                    <?php $__currentLoopData = $range; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supdatad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($supdatad->id); ?></td>
                            <td><?php echo e($supdatad->customerid); ?></td>
                            <td><?php echo e($supdatad->trackingno); ?></td>
                            <td class="text-center">
                            <?php if($supdatad->status=='0'): ?>
                            <span class="badge badge-warning">Not Shipping</span>
                            <?php elseif($supdatad->status=='1'): ?>
                            <span class="badge badge-success">Shipped</span>
                            <?php endif; ?>
                            </td>
                            <td class="text-center">
                            <button type="button" class="btn btn-primary btn-xs" data-id="<?php echo e($supdatad->id); ?>" data-tracking="<?php echo e($supdatad->trackingno); ?>" data-toggle="modal" data-target="#bankmodel">Edit</button>
                                <a href="" data-supllierid="<?php echo e($supdatad->Sid); ?>" data-id="<?php echo e($supdatad->id); ?>" class="btn btn-danger btn-xs button bankdetailsdelete" data-url="">Delete </a>
                            </td>                        
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </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">Trcking Update</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" id="trckingupdate">
            <?php echo e(csrf_field()); ?>

        <div class="modal-body">  
            <input type="hidden" name="id" id="id">    
            <div class="form-group">
                <label for="">Tracking Number</label><input type="number" class="form-control" id="tracking" name="tracking" placeholder="" required>
            </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>


  <?php echo $__env->make('dashboard.include.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;

<script>
$('#min_no').on('input', function() { 
    var min = $(this).val();
    var max = parseInt($('#max_no').val());
    $("#net_amo").html(max-min);

 });
 $('#max_no').on('input', function() { 
    var max = $(this).val();
    var min = parseInt($('#min_no').val());
    $("#net_amo").html(max-min);

 });



$(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 Tracking Number",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletedeliveryrange')); ?>/"+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) {
                                swal("Done!", "It was successfully!", "success");
                            },
                            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 supid = button.data('tracking') 
var id = button.data('id') 



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

})


$('#trckingupdate').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/rangetrackinupdate",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (result, code, ex) {
                swal("Done!", "It was successfully!", "success");
                $("#bankmodel").modal('hide');  
                location.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });

$('input[name=min_no]').change(function() { 
    var min = $(this).val();
    var max = parseInt($('#max_no').val());

    if(max<=min){
        $(document).Toasts('create', {
        class: 'bg-danger',
        title: 'Warning',
        subtitle: 'Close',
        body: 'Min Value cannot be greater than Max Value.'
      })

      $(':input[type="submit"]').prop('disabled', true);
    }
    else{
        $(':input[type="submit"]').prop('disabled', false);
       
    }

 });
 $('input[name=max_no]').change(function() { 
    var max = $(this).val();
    var min = parseInt($('#min_no').val());

    if(max<=min){
        $(document).Toasts('create', {
        class: 'bg-danger',
        title: 'Warning',
        subtitle: 'Close',
        body: 'Min Value cannot be greater than Max Value.'
      })
      $(':input[type="submit"]').prop('disabled', true);
    }
    else{
        $(':input[type="submit"]').prop('disabled', false);
        
    }

 });











// $('#min_no').on('input',function(e){
//     var min = $(this).val();
//     var max = parseInt($('#max_no').val());
//     if(max<=min){
//         $(document).Toasts('create', {
//         class: 'bg-danger',
//         title: 'Warning',
//         subtitle: 'Close',
//         body: 'Min Value cannot be greater than Max Value.'
//       })

//     }
//     else{
//     }

// });

// $('#max_no').on('input',function(e){
//     var max = $(this).val();
//     var min = parseInt($('#min_no').val());

//     if(max<=min){
//         $(document).Toasts('create', {
//         class: 'bg-danger',
//         title: 'Warning',
//         subtitle: 'Close',
//         body: 'Min Value cannot be greater than Max Value.'
//       })

//     }
//     else{
//     }

// });
</script>