@extends('layouts.adminapp')

@section('content')

{{-- Order List --}}


<div class="card mb-4">
    <div class="card-header">
        <div class="d-flex">
            <div class="mr-auto p-2 align-self-center"><h4>All Orders</h4></div>
        </div>    

        <div class="border-top pt-3">
            <div class="row">
                <div class="col-lg-4 col-sm-4">
                    <form class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search">
                        <div class="input-group">
                            <input type="text"  id="searchgrp"   oninput="searOrder()" class="form-control bg-light border-0 small" placeholder="Search by Order Number" aria-label="Search" aria-describedby="basic-addon2">
                            <div class="input-group-append">
                            <button class="btn btn-info" type="button">
                                <i class="fas fa-search fa-sm"></i>
                            </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-lg-4 col-sm-4">
                    <form class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search">
                        <div class="input-group">
                            <input type="text"  id="searchmobile"   oninput="searchMobile()" class="form-control bg-light border-0 small" placeholder="Search by Name or Mobile " aria-label="Search" aria-describedby="basic-addon2">
                            <div class="input-group-append">
                            <button class="btn btn-info" type="button">
                                <i class="fas fa-search fa-sm"></i>
                            </button>
                            </div>
                        </div>
                    </form>
                    <div id="hint_tbl">
                    </div> 
                </div>
                <div class="col-lg-4 col-sm-4">
                    <div class="form-group w-30">
                        <select id="selectgrp" class="form-control @error('status_id')  @enderror" id="cbStatus" name="status_id" onchange="clicks()">
                            @php
                                echo App\Http\Controllers\StatusController::StatusListForCombo(0);
                            @endphp
                        </select>   
                        @error('status_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>

                <div class="col-lg-4 col-sm-4">             
                
                </div>           
            </div>
        </div>
    </div>
    <div class="card-body">
        <div class="table-responsive" >
            <table class="table table-hover" id="search_tbl">
                <thead>
                    <tr>
                        <!--th>SLNO.</th-->
                        <th>Order No.</th>
                        <th>Customer</th>
                        <th>Status</th>
                        <th>Rack</th>
                        <th>Godown</th>
                        <th>Narration</th>                     
                        <th colspan="">Actions</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($Results as $Result)
                    <tr>
                        <td>{{$Result->id}}</td>
                        <td>{{$Result->user->name}}</td>
                        <td>{{$Result->status->title}}</td>
                        @if($Result->rack)
                            <td>{{$Result->rack->title}}</td>
                        @else
                            <td>Not Selected</td>
                        @endif
                        @if($Result->rack)
                            <td>{{$Result->rack->godown->title}}</td>
                        @else
                            <td>Not Selected</td>
                        @endif
                       <td>{{$Result->narration}}</td>
                        <td style="width: 150px;"><a href="{{route('orderlistview',$Result->id)}}" class="btn btn-info"><i class="fa fa-edit"></i> View</a></td>   
                         <td>
                            @if($Result->status_id>='6')
                                <a href="{{route('InvoicePrint',$Result->id)}}"><button type="button" class="btn btn-secondary">Inovice</i></button></a>
                            @endif
                         </td>                    
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
    <div class="card-footer">
        <div class="d-flex justify-content-end font-weight-bold"><h5>Total:  {{$Results->Count()}}</h5></div>        
    </div>
</div>

@endsection

<script>
function searOrder(){
     
 var items = document.getElementById("searchgrp").value;
    $.ajax({
      url: '{{ route('searchGroups') }}',
      method: "get",
      data: {_token: '{{ csrf_token() }}',searchitems:items },
                              success: function (response){   
                                           
                                document.getElementById('search_tbl').innerHTML=response; 
                              
                                      }
                      });   
} 

function searchMobile(){
    hint_tbl.style.display ="block";
    var items = document.getElementById("searchmobile").value;
    
    $.ajax({
          url: '{{ route('searchMobile') }}',
          method: "get",
          data: {_token: '{{ csrf_token() }}',searchitems:items },
                                  success: function (response){   
                                               
                                    document.getElementById('hint_tbl').innerHTML=response; 
                                  
                                          }
                          });   
    }


function clicks() {
    var items = document.getElementById("selectgrp").value;    
    
    $.ajax({
      url: '{{ route('selectGroups') }}',
      method: "get",
      data: {_token: '{{ csrf_token() }}',searchitems:items },
                              success: function (response){   

                                document.getElementById('search_tbl').innerHTML=response; 
                              
                                      }
                      });  

}


function userclick(ID){
    hint_tbl.style.display ="none";
    $.ajax({
          url: '{{ route('searchByID') }}',
          method: "get",
          data: {_token: '{{ csrf_token() }}',user_id:ID },
                                  success: function (response){   
                                             
                                    document.getElementById('search_tbl').innerHTML=response; 
                                          }
                          });
                             
    }
</script>