@extends('layout')
@section('title','Liste des fournisseurs ')
@section('description','Liste des fournisseurs')
@section('content')
			<br/>
          <div class="section-body">
		  <br/>
			<div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des fournisseurs</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">Téléphone</th>
							<th style="text-align:center;">Total à payer</th>
							<th style="text-align:center;">Payé</th>
							<th style="text-align:center;">Reste à payer</th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($fournisseur as $fournisseurs)
							@php
								$apayer = DB::table('appro_vendable')->where('fournisseur_id',$fournisseurs->id)->where('etat', 'Validée')->get()->sum('montant');
								 $sommePaiement =  DB::table('paiement_fou')->where('fournisseur_id', $fournisseurs->id)->where('etat','Validée')->get()->sum('montant');
								 $sommePaiementE =  DB::table('paiement_fou')->where('etat','Validée')->get()->sum('montant');
								 $restantF = $apayer - $sommePaiement;

							@endphp
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$fournisseurs->nom}}</td>
							<td style="text-align:center;">{{$fournisseurs->telephone}}</td>
							<td style="text-align:center;">
							@php
							$lh = $apayer;
							$lh1 =  number_format($lh, 0, ' ', ' ');
							echo $lh1;
							@endphp
							</td>
							<td style="text-align:center;">
							@php
							$lhhh = $sommePaiement;
							$lhhh1 =  number_format($lhhh, 0, ' ', ' ');
							echo $lhhh1."&nbsp;F";
							@endphp
							</td>
							<td style="text-align:center;">
							@php
							$lhh = $restantF;
							$lhh1 =  number_format($lhh, 0, ' ', ' ');
							echo $lhh1."&nbsp;F";
							@endphp
							</td>
							<td style="text-align:center;">
								<a type="button" href="{{route('fournisseur_appro',['id'=>$fournisseurs->id])}}" class="btn btn-icon btn-primary"><i class="fas fa-money" aria-hidden="true"></i> Factures appro</a>
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
		<div class="modal fade bd-example-modal-sm" id="Validermodal">
			<div class="modal-dialog modal-sm">
				<div class="modal-content">
					<div class="modal-body">
						<p>Voulez-vous valider la facture ?</p>
					</div>
					<div class="modal-footer" style="background-color:#ffffff" id="valider">

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

        <div class="modal fade bd-example-modal-sm" id="Annulermodal">
			<div class="modal-dialog modal-sm">
				<div class="modal-content">
					<div class="modal-body">
						<p>Etes-vous sûr d'annuler cette facture ?</p>
					</div>
					<div class="modal-footer" style="background-color:#ffffff" id="annuler">

					</div>
				</div>
			</div>
		</div>
		<div class="modal fade bd-example-modal-sm" id="Supprimermodal">
			<div class="modal-dialog modal-sm">
				<div class="modal-content">
					<div class="modal-body">
						<p>Etes-vous sûr de supprimer cette facture ?</p>
					</div>
					<div class="modal-footer" style="background-color:#ffffff" id="supprimer">

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

@endsection