@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">Create Delivery Service</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">Create Delivery Service</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
            <div class="card-body">
            <form class="form-horizontal" method="POST" action="/adddelivery">
                {{csrf_field()}}
            <div class="row">
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label for="">Delivery Service Name</label><input type="text" class="form-control" name="Name" placeholder="Name" required>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="">Phone Number</label><input type="number" class="form-control" name="Phone_Number" placeholder="Phone Number" required>
                    </div>
                </div>
                <div class="col-md-4"> 
                    <div class="form-group">
                        <label for="">E-mail</label><input type="email" class="form-control" name="email" placeholder="E-mail" required>
                    </div>
                </div>
                <div class="col-md-5"> 
                    <div class="form-group">
                        <label for="">Address</label><input type="text" class="form-control" name="Address" placeholder="Address" required>
                    </div>
                </div>
                <div class="col-md-2" style="padding-top:32px;"><button type="submit" class="btn btn-block btn-primary">Create Delivery</button> </div>
           
            </div> 
            </form>
            </div>
            </div>
            <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                    <table id="example" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Delivery Service Name</th>
                                <th>Phone Number</th>
                                <th>Address</th>
                                <th>Email</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                    @foreach($item as $data)
                        <tr>
                            <td>{{ $data->id}}</td>
                            <td>{{ $data->deliveryname}}</td>
                            <td>{{ $data->deliveryphone}}</td>
                            <td>{{ $data->deliveryaddress}}</td>
                            <td>{{ $data->email}}</td>
                            <td class="text-center">
                                <button type="button" class="btn btn-primary btn-xs supmodel" data-email="{{$data->email}}" data-id="{{$data->id}}" data-name="{{$data->deliveryname}}" data-address="{{$data->deliveryaddress}}"  data-number="{{$data->deliveryphone}}" data-toggle="modal" data-target="#supmodel">Edit</button>
                                <a href="" data-id="{{$data->id}}" class="btn btn-danger btn-xs button deletesupplier" data-url="">Delete </a>
                                <a type="button" class="btn btn-success btn-xs" data-id="{{$data->id}}" href="trackingrange/{{$data->id}}">Tracking Range</a>
                            </td>                        
                        </tr>
                    @endforeach
                    </tbody>
                    </table>
                    
                    </div>
                </div>


            </div>
        </div>
        <div class="card">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                    <table id="example11" class="table table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Delivery Service Name</th>
                                <th>Phone Number</th>
                                <th>Address</th>
                                <th>Available No of Barcodes</th>
                            </tr>
                        </thead>
                        <tbody>
                    @foreach($countdata as $data)
                        <tr>
                            <td>{{ $data->deliveryname}}</td>
                            <td>{{ $data->deliveryphone}}</td>
                            <td>{{ $data->deliveryaddress}}</td>
                            <td>{{$data->ctrack}}</td>                
                        </tr>
                    @endforeach
                    </tbody>
                    </table>
                    
                    </div>
                </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">Delivery Service 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="/deliveryupdate">
            {{csrf_field()}}
        <div class="modal-body"> 
            <input type="hidden" name="id" id="id">    
            <div class="form-group">
                <label for="">Name</label><input type="text" class="form-control" id="Name" name="Name"  required>
            </div>
            <div class="form-group">
                <label for="">Phone Number</label><input type="number" class="form-control" id="Phone_Number" name="Phone_Number"  required>
            </div>
            <div class="form-group">
                <label for="">E-mail</label><input type="email" class="form-control" id="email" name="email" required>
            </div> 
            <div class="form-group">
                <label for="">Address</label><input type="text" class="form-control" id="Address" name="Address" 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>


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

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

$(document).ready(function() {
    $('#example11').DataTable();
} );
</script>
<script>
$(document).on('click', '.deletesupplier', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

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

                        $.ajax({
                            url: "{{url('/deletedelivery')}}/"+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 = "/deliveryserice";
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

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


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

var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('id') 
var name = button.data('name') 
var address = button.data('address') 
var number = button.data('number') 
var email = button.data('email') 

var modal = $(this)
modal.find('.modal-body #id').val(recipient)
modal.find('.modal-body #Name').val(name)
modal.find('.modal-body #Phone_Number').val(number)
modal.find('.modal-body #Address').val(address)
modal.find('.modal-body #email').val(email)
})
</script>



