@extends('layout')
@section('title','Nouvelle catégorie de dépense ')
@section('content')
		<br/>
          <div class="section-body">
            <div class="row">
              <div class="col-lg-8 offset-2 col-md-12 ">
				@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
		<br/>
                <div class="card">
                  <div class="card-header">
                    <h4>Enregistrer une nouvelle catégorie de dépense (<h7><strong>Les champs en * sont obligatoires</strong></h7>)</h4>
                  </div>
                  <div class="card-body">
				<form  action="" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-8 col-md-8"> 
					  <div class="form-group">
                      <label>Libellé <font color="red">*</font></label>
                      <input type="text" class="form-control" name="lib">
                    </div>
					</div>
					
                      </div>
					 <hr>  	
                   <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="addcat"><i class="fas fa-check"></i> Enregistrer</button>
                  </div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                    </div>
                  </div>
                </div>

			
           
          </div>
		  
		  
		   <div class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des types de dépense</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr style="text-align:center;">
                            <th class="text-center"> N° </th>
                            <th class="text-center">libellé</th>
							
                            <th>Action</th>
						  
                          </tr>
                        </thead>
                        <tbody>
						@foreach($typedepense as $typedepenses)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$typedepenses->libelle}}</td>
							
							
							<td style="text-align:center;">
							
							<a class="btn btn-icon btn-primary" href="{{route('modifier-typededepense',['id'=>$typedepenses->id])}}"><i class="fas fa-edit"></i> Modifier </a>
		                 	
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  

		  
	   @push('scripts') 
	   
	   
	   
		<script>
		$( "#addcat").on('click', function( e ) {
			e.preventDefault();
			var data = {};
			
			data.lib = $("input[name=lib]").val();
			

			if(!data.lib){
				toastr.error('Veuillez saisir le libellé ', 'Erreur !', {timeOut: 5000})
				return false;
			}


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

			if( data.lib ){
				$.post("{{route('typedepensePost')}}", data, function (result) {
					if(result.type == 'error'){
						toastr.error(result.response, result.title, {timeOut: 5000})
					}else{

					     toastr.success(result.response, result.title, {timeOut: 15000})
                         location.reload();
					}

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

@endsection