@extends('layout')
@section('title','Inventaire restaurant ')
@section('description','Inventaire restaurant ')
@section('content')
<div class="section-header">
            <h1>Inventaire restaurant</h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="#">Inventaire restaurant</a></div>
              <div class="breadcrumb-item"><a href="#">Modification</a></div>
            </div>
          </div>
          <div class="section-body">
		    @if (session('status'))
            <div class="alert alert-warning" style="font-size: 15px; background-color: #328039; color: white">
                <i class="fa fa-check"></i> &nbsp; {{ session('status') }}
            </div>
        @endif

        @if (session('error'))
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white">
                <i class="ti-na"></i> {{ session('error') }}
            </div>
        @endif
        @if ($errors->any())
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white" >
                <ul>
                    @foreach ($errors->all() as $error)
                        <li> <i class="ti-na"></i> {{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
            <div class="row">
            <div class="col-lg-10 offset-1 col-md-12 ">
                <div class="card">
                  <div class="card-header">
                    <h4>Modifier un inventaire</h4>
                  </div>
				  
                  <div class="card-body">
				  
				  <h7><strong>Les champs en * sont obligatoires</strong></h7>
				  
				<form  action="" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					  
                    <div class="col-lg-6 col-md-12">
					  <div class="form-group">
                      <label>Produit <font color="red">*</font></label>
                      <select  class="form-control select2" name="produit">
                        <option value="{{$ligne->produit_id}}">
                        {{DB::table('produit_vendable_fini')->where('id', $ligne->produit_id)->first()->designation}}
                        </option>
						 @foreach($produit as $produits) 
						<option value="{{$produits->id}}">{{$produits->designation}} </option>
						@endforeach
                      </select>
                    </div>
					</div>
					 <div class="col-lg-3 col-md-12">
					<div class="form-group">
                      <label>Boules/Morceaux <font color="red">*</font></label>
                      <input  type="text" value="{{$ligne->nbre}}" class="form-control" name="qte">
                    </div>
					</div>
					
				
                      </div>
					    	

                   <div class="pull-left">
                 
                    <button type="reset" class="btn btn-icon icon-left btn-danger"><i class="fas fa-times"></i> Annuler</button>
                    <button class="btn btn-icon icon-left btn-primary" id="editinvres"><i class="fas fa-check"></i> Enregistrer</button>
                  </div>
            
			<br><br>
					  
				</form>
					  
					    </div>
						 
                    </div>
                  </div>
                </div>

			
           
          </div>
	
		  
             
            </div>
          </div>
		  
         
		  
	   @push('scripts') 
	   
    
	
		<script>
		$( "#editinvres").on('click', function( e ) {
			e.preventDefault();
			var data = {};
			
			data.produit = $("select[name=produit]").val();
			data.qte = $("input[name=qte]").val();

			if(!data.produit){
				toastr.error('Veuillez sélectionner le produit ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			if(!data.qte){
				toastr.error('Veuillez saisir le nombre de boules ou morceaux', 'Erreur !', {timeOut: 5000})
				return false;
			}


			data._token = "{{csrf_token()}}";

      @php
         $idinv = $ligne->id;
      @endphp

			if(data.produit && data.qte ){
        $.post("{{route('modifier_inventaire_restoPost',['id'=>$idinv])}}", data, function (result) {
					if(result.type == 'error'){
						toastr.error(result.response, result.title, {timeOut: 5000})
					}else{

					     toastr.success(result.response, result.title, {timeOut: 15000})
                         window.location.href = '/detail_resto/'+result.idresto;
					}

				})
			}
		});
     
  </script>
	   
	   
@endpush

@endsection