@extends('layout')
@section('title','Créances clients ')
@section('content')
		<br/>
       
		   <div class="section-body">
            <div class="row">
              <div class="col-10 offset-1">
				<div class="card">
                  <div class="card-header">
                    <h4>Rechercher facture client pour une période</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('creance-rech')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-4 col-md-12"> 
					  <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-4 col-md-12"> 
					  <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-12"> 
                      <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 class="card">
                  <div class="card-header">
                    <h4>Créances clients</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 du client</th>
							<th style="text-align:center;">A payer</th>
							<th style="text-align:center;">Payé</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($client as $clients)
						
						    @php
							$apayer = DB::table('vente_client')->where('client_id',$clients->id)->get()->sum('montant');
							$paye = DB::table('paiement_client')->where('client_id',$clients->id)->get()->sum('montant');
							@endphp
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$clients->noms}} </td>
							<td style="text-align:center;">
							@php
							$lh = $apayer;
							$lh1 =  number_format($lh, 0, ' ', ' ');
							echo $lh1."&nbsp;F";
							@endphp
							</td>
							@php
							$paye = $paye;
							$paye =  number_format($paye, 0, ' ', ' ');
							@endphp
							<td style="text-align:center;">{{$paye}} F</td>
                          </tr>
						  @endforeach
                        </tbody>
						<tr>
						@php
							$totvente =  number_format($totvente, 0, ' ', ' ');
							$totpaie =  number_format($totpaie, 0, ' ', ' ');
						@endphp
							<td style="text-align:center;"></td>
							<td style="text-align:center;"><b>Total</b></td>
							<td style="text-align:center;height:30px;"><b>{{$totvente}} F</b></td>
							<td style="text-align:center;height:30px;"><b>{{$totpaie}} F</b></td>
						</tr>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  
 
		  
 @push('scripts') 
	   
@endpush

@endsection