@extends('layout')
@section('title','Liste des clients ')
@section('content')
		<br/>
       
		   <div class="section-body">
            <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('liste-rech')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Client <font color="red">*</font></label>
                      <select class="form-control select2" name="client">
                        <option value="{{$client}}">@php if($client==0){
							$cli="Tous les clients";}
							else 
							{$cli=DB::table('client_externe')->where('id', $client)->first()->noms;}
						@endphp 
						{{$cli}}</option>
						@foreach($client2 as $clients)
						<option value="{{$clients->id}}">{{DB::table('client_externe')->where('id', $clients->id)->first()->noms}}</option>
						@endforeach
                      </select>
                    </div>
					</div>
					@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
                     <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" value="{{$date_debut}}" 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" value="{{$date_fin}}" 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 class="card">
                  <div class="card-header">
                    <h4>Liste des ventes par clients : @php if($client==0){$cli="Tous les clients";} else {$cli=DB::table('client_externe')->where('id', $client)->first()->noms;}@endphp {{$cli}}</h4>
                  <a target="_blank" class="btn btn-info" href="{{route('listerechpdf')}}">Imprimer la facture client<a/>
			&nbsp;&nbsp;<a target="_blank" class="btn btn-primary" href="{{route('listerechpdf2')}}">Historique client<a/>
				  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                          <thead>
                      <tr>
                        <th style="width:30px;">N°</th>
                        <th style="width:105px;">Référence</th>
						<th style="width:105px;">Montant</th>
						<th style="width:105px;">Date</th>
                      </tr>
                    </thead>
                        <tbody>
			@foreach($vente as $ventes)
           <tr>
		   <td width="30px" height="30px" align="center">{{$loop->iteration}}</td>
		   <td width="30px" height="30px" align="center">{{$ventes->numero}}</td>
		   <td width="200px" height="30px" align="center">{{$ventes->montant}}</td>
		   <td width="200px" height="30px" align="center">{{$ventes->date}}</td>
		   </tr>
			@endforeach
		</tbody>
		<tr>
			<td style="text-align:center"> <b>Total à payer</b></td>
			<td style="text-align:center"> <b>Payé</b></td>
			<td style="text-align:center" colspan="2"> <b>Reste à payer</b></td>
		</tr>
		<tr>
			@php
			$reste = $total - $sommePaiement;
			$reste =  number_format($reste, 0, ' ', ' ');
			$total1 = $total;
			$total1 =  number_format($total1, 0, ' ', ' ');
			$sommePaiement1 = $sommePaiement;
			$sommePaiement1 =  number_format($sommePaiement1, 0, ' ', ' ');
			@endphp
			<td style="text-align:center">{{$total1}}</td>
			<td style="text-align:center"> {{$sommePaiement1}}</td>
			
			<td style="text-align:center" colspan="2"> <b>{{$reste}}</b></td>
		</tr>
                      </table>
                    </div>
                  </div>
                </div>
				
			<p> 
			</p>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
@endsection