@extends('layout')
@section('title','Liste des salaires ')
@section('description','Liste des salaires')
@section('content')
			<br/>
          <div class="section-body">
		  <br/>
			<div class="row">
              <div class="col-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
				
				<div class="card">
                  <div class="card-header">
                    <h4>Rechercher facture client pour une période</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('historique-paiement-journalier')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-3 col-md-3"> 
					  <div class="form-group">
                      <label>Date début <font color="red">*</font></label>
                      <input type="text" class="form-control" name="date_debut" id="champ_date" required>
					  <div id="calendarMain"></div>
                    </div>
					</div>
					<div class="col-lg-3 col-md-3"> 
					  <div class="form-group">
                      <label>Date fin <font color="red">*</font></label>
                      <input type="text" class="form-control" name="date_fin" id="champ_date2" required>
					  <div id="calendarMain2"></div>
                    </div>
					</div>
					<div class="col-lg-2 col-md-2"> 
                      <button class="btn btn-icon icon-left btn-success"><i class="fas fa-search"></i> Rech</button>
					</div>
                      </div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                </div>
            <br />
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des salaires du {{$dd}} au {{$df}}</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th>N°</th>
							<th>Employé</th>
							<th>Date début</th>
							<th>Date fin</th>
							<th>Absen.</th> 
							<th>Nbre de jour</th> 
							<th>A payer</th> 
							<th>ACTIONS</th>
                          </tr>
                        </thead>
                        <tbody>
                @foreach($salaire as $salaires)
                <tr>
                        @php
                        $dated = $salaires->date_debut;
                        $dated= explode('-', $dated);
                        $dated= array_reverse($dated);
                        $dated= implode('-', $dated);

                        $datef = $salaires->date_fin;
                        $datef= explode('-', $datef);
                        $datef= array_reverse($datef);
                        $datef= implode('-', $datef);
						$today = date('Y-m-d');

                    @endphp
					<td>{{$loop->iteration}}</td>
                    <td>
                        {{DB::table('employe')->where('id', $salaires->employe_id)->first()->nom}}
                        {{DB::table('employe')->where('id', $salaires->employe_id)->first()->prenoms}}
                    </td>
					<td style="text-align:center">{{$dated}}</td>
					<td style="text-align:center">{{$datef}}</td>
					<td style="text-align:center">{{$salaires->nbabsence}}</td>
					<td style="text-align:center">{{$salaires->nbjour}}</td>
                    <td style="text-align:center">{{number_format($salaires->apayer, 0, ' ', ' ')}}</td>
                    <td>
						@if ($today == $salaires->dateenreg)
						<a type="button" href="#" data-toggle="tooltip" data-id="{{$salaires->id}}"
                                            data-placement="bottom" title="Supprimer"
                                            class="btn btn-icon btn-danger data-supprimer"><i
                        class="fas fa-trash"></i>
						</a>
						@endif
						@if ($salaires->typeemploye == "Salarié")
						<a type="button" target="_blank" href="{{route('bulletin-paie-journalier', ['id'=> $salaires->id])}}" class="btn btn-icon btn-warning"><i class="fa fa-print"></i></a>
						@endif
					</td>
				</tr>
                @endforeach
                </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
		  </div>
</div>
		  <div class="modal fade" id="Supprimermodal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Suppression</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 supprimer cet enregistrement ?
            </div>
            <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">

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

@push('scripts')
<script>
    $(".data-supprimer").on('click', function () {
        var id = $(this).data('id');
        $.get(location.origin + '/es/Salaire/' + id, function (data) {
            var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimerSalairePost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+ data.salaire.id + `" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

            </form>`
                ;
            $('#delete').html('').append(html);
        })
        $('#Supprimermodal').modal();
    });
</script>
@endpush
@endsection