@extends('layout')
@section('title','Liste des paiements hôpital')
@section('content')
		<br/>
          <div class="section-body">
            <div class="row">
              <div class="col-lg-10 offset-1 col-md-12 ">
			  <p align="right">
				<a class="btn btn-icon btn-danger pull-right" href="{{route('paiementcli')}}"> Ajouter un paiement</a>
				<a class="btn btn-icon btn-primary pull-right" href="{{route('situation_hopital')}}"> Situation paiements de l'hôpital</a>
				</p>
				<br/>
				@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>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('liste-des-paiements-rech')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-5 col-md-5"> 
					  <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-5 col-md-5"> 
					  <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>
                  </div>
                </div>
          </div>
		   <div class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
				  @php
					$date_debut= explode('-', $date_debut);
					$date_debut= array_reverse($date_debut);
					$date_debut= implode('/', $date_debut);
					
					$date_fin= explode('-', $date_fin);
					$date_fin= array_reverse($date_fin);
					$date_fin= implode('/', $date_fin);
				  @endphp
                    <h4>Liste des paiements hôpital du {{$date_debut}} au {{$date_fin}}</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">Date</th>
                            <th class="text-center">Montant payé</th>
                            <th class="text-center">Actions</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($paie as $paies)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$paies->date}}</td>
							@php
								$lh = $paies->montant;
								$lh1 =  number_format($lh, 0, ' ', ' ');
							@endphp
							<td style="text-align:center;">{{$lh1}} F</td>
							<td style="text-align:center;">
							<a type="button" target="_blank" href="{{route('facture-paiement-hopital',['id'=>$paies->id])}}" class="btn btn-icon btn-info"><i class="fas fa-print"></i></a>
							</td>
                          </tr>
						  @endforeach
                        </tbody>
						<tfoot>
							<tr>
								<td style="text-align:right;"></td>
								<td style="text-align:right;"><b>Total paiements</b></td>
								@php
								$lhh = $total;
								$lhh1 =  number_format($lhh, 0, ' ', ' ');
								@endphp
								<td style="text-align:center;"><b>{{$lhh1}} FCFA</b></td>
							<tr>
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
				<p align="center">
					<a type="button" target="_blank" href="{{route('liste-des-paiements-pdf')}}" class="btn btn-icon btn-warning">
					<i class="fas fa-print"></i> Imprimer la liste</a>	
				</p>
              </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>
		$( "#addpaiec").on('click', function( e ) {
			e.preventDefault();
			var data = {};
			//data.client_id = $("input[name=client_id]").val();
            data.montant = $("input[name=montant]").val();
			data.mode = $("select[name=mode]").val();
			data.note = $("textarea[name=note]").val();
			//data.pc = $("input[name=pc]").val();
            //data.pa_carton = $("input[name=pa_carton]").val();
			//data.nb_carton = $("input[name=nb_carton]").val();
			//data.pu_carton = $("input[name=pu_carton]").val();
			//data.pu_kilo = $("input[name=pu_kilo]").val();
			//data.tva = $("input[name=tva]").val();
			//data.reference = $("input[name=reference]").val();

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

            if(!data.mode){
				toastr.error('Veuillez sélectionner le mode de règlement ', 'Erreur !', {timeOut: 5000})
				return false;
			}
			

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

			if(data.montant && data.mode){
				$.post("{{route('paiementcliPost')}}", 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 = '/es/paiementcli';
					}

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

@endsection