@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">Exchange/Refund Return Recive</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">Exchange/Refund Return Recive</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">

      <div class="card">
        <div class="card-body">

          <div class="row">
            <div class="col-md-12">
            <form method="post" class="itemstatusform2" enctype="multipart/form-data">
          {{csrf_field()}}
                <div class="form-group">
                    <input type="text" class="form-control barcodetxt" name="id" id="id" placeholder="Invoice ID + Press Enter Key" required aurofocus>
                </div>
                </form>
                <hr>
                <table id="example12" class="table table-bordered" style="width:100%; font-size:13px;">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Phone</th>
                            <th>Tracking</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
            </div>
          </div>
          </div>
        </div>

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



  @include('dashboard.include.footer')


  <script>
$('.barcodetxt').bind("enterKey",function(e){
    $(".itemstatusform2").submit();
});
</script>


<script>

$('.itemstatusform2').on('submit', function(event){
   let ele = this;
       event.preventDefault();
       var form_data = $(this).serialize();
       $.ajax({
           url:"/postexchangereturn",
           method:"POST",
           data:form_data,
           dataType:"json",      
           success: function (data) {

                jQuery.each(data, function(key,value){
                    if(value=="2"){

                        swal({
                            title: "Error!",
                            text: "This order already returned",
                            icon: "error",
                            button: "OK",
                        });
                        $('input[name=id').val('');
                      $('input[name=id').focus();
                    }
                    else if(value=="4"){
                        swal({
                            title: "Error!",
                            text: "Not a Exchange or Refund Order",
                            icon: "error",
                            button: "OK",
                        });
                        $('input[name=id').val('');
                        $('input[name=id').focus();
                        }
                    else{
                      toastr.success('It was successfully!')
                      $('#example12').DataTable().ajax.reload();
                      $('input[name=id').val('');
                      $('input[name=id').focus();

                    }

                
        });






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

$(document).ready(function() {
    $('#example12').DataTable({
        processing: false,
        serverSide: true,
        responsive: true,
        ajax: '/getallorders',
        columns: [
            { data: 'id', name: 'id' },
            {  data: 'name', name: 'name' },
            { data: 'phone', name: 'phone'},
            { data: 'tracking', name: 'tracking'},
            { data: 'action', name: 'action', orderable: false, searchable: false}
        ]
    });


} );
</script>
