@extends('layout')
@section('title','Nouvel employé ')
@section('content')
		<br/>
          <div class="section-body">
            <div class="row">
              <div class="col-lg-10 offset-1 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 un nouvel employé (<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-4 col-md-4"> 
					  <div class="form-group">
                      <label>Type d'employé <font color="red">*</font></label>
                      <select class="form-control select2" name="typeemploye">
                        <option value="">Sélectionner </option>
                        <option value="Journalier">Journalier</option>
                        <option value="Salarié">Salarié</option>
                      </select>
                    </div>
					</div>
                     <div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Nom <font color="red">*</font></label>
                      <input type="text" class="form-control" name="nom">
                    </div>
					</div>
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Prénoms <font color="red">*</font></label>
                      <input type="text" class="form-control" name="prenoms">
                    </div>
					</div>
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Fonction <font color="red">*</font></label>
                      <input type="text" class="form-control" name="fonction">
                    </div>
					</div>
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Téléphone <font color="red">*</font></label>
                      <input type="text" class="form-control" name="telephone">
                    </div>
					</div>
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Rémunération (Journ./Mensuel) <font color="red">*</font></label>
                      <input type="text" class="form-control" name="salaire_base">
                    </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="addemp"><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 employés</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th class="text-center"> N° </th>
                            <th class="text-center">Nom</th>
                            <th class="text-center">Prénoms</th>
							<th class="text-center">Téléphone</th>
                            <th class="text-center">Type d'employé</th>
                            <th class="text-center">Rémunération</th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($employe as $employes)
                          <tr>
							<td style="text-align:center;">{{$employes->matricule}}</td>
							<td style="text-align:center;">{{$employes->nom}}</td>
							<td style="text-align:center;">{{$employes->prenoms}}</td>
							<td style="text-align:center;">{{$employes->telephone}}</td>
							<td style="text-align:center;">{{$employes->typeemploye}}</td>
							<td style="text-align:center;">{{number_format($employes->salaire_base, 0, ' ', ' ')}}</td>
							<td style="text-align:center;">
							<a type="button" href="{{route('modifier_employe',['id'=>$employes->id])}}" data-toggle="tooltip" data-placement="bottom" title="Modifier" class="btn btn-icon btn-info"><i class="fas fa-edit"></i></a>
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  
  <div class="modal fade" id="Validermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Validation</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Voulez-vous valider cet approvisionnement ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="valider">
                
              </div>
            </div>
          </div>
        </div>
		  
	   @push('scripts') 
		<script>
		$( "#addemp").on('click', function( e ) {
			e.preventDefault();
			var data = {};
			
			data.nom = $("input[name=nom]").val();
			data.prenoms = $("input[name=prenoms]").val();
			data.fonction = $("input[name=fonction]").val();
			data.telephone = $("input[name=telephone]").val();
			data.salaire_base = $("input[name=salaire_base]").val();
			data.typeemploye = $("select[name=typeemploye]").val();
			
			if(!data.typeemploye){
				toastr.error('Veuillez sélectionner le type d\'employé ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			if(!data.nom){
				toastr.error('Veuillez saiisir le nom ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			if(!data.prenoms){
				toastr.error('Veuillez saisir le(s) prénom(s) ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			if(!data.telephone){
				toastr.error('Veuillez saisir le téléphone ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			if(!data.salaire_base){
				toastr.error('Veuillez saisir la rémunération ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			


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

			if( data.nom && data.prenoms ){
				$.post("{{route('nouveau_employePost')}}", 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