@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 par client sur une période</h4>
                  </div>
                  <div class="card-body">
				<form>
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					<div class="col-lg-4 col-md-12"> 
					  <div class="form-group">
                      <label>Client <font color="red">*</font></label>
                      <select class="form-control select2" name="client">
                        <option value="0">Tous les clients</option>
						@foreach($cli as $clients)
						<option value="{{$clients->id}}">{{DB::table('client_externe')->where('id', $clients->id)->first()->noms}}</option>
						@endforeach
                      </select>
                    </div>
					</div>
                     <div class="col-lg-3 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-3 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>Liste consignation par client</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">Noms</th>
							<th style="text-align:center;">Tot. Consigné</th>
							<th style="text-align:center;">Transfert reçu</th>
							<th style="text-align:center;">Retour d'emb.</th>
							<th style="text-align:center;">Reste</th>
                            <th  style="text-align:center;">Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($client as $clients)
						   @php
							$totconsigne = DB::table('ligne_consignation')->where('client_id',$clients->id)->where('etat', 'Validée')->get()->sum('qte');
							$transf = DB::table('ligne_transfert_emballage')->where('client_id',$clients->id)->where('etat', 'Validé')->get()->sum('qte');
							$retour = DB::table('ligne_retour_emballage')->where('client_id',$clients->id)->where('etat', 'Validé')->get()->sum('qte');
							$restant = $transf - $retour;

							@endphp
							
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{$clients->noms}} </td>
							<td style="text-align:center;">{{ $totconsigne }} </td>
							<td style="text-align:center;">{{ $transf }} </td>
							<td style="text-align:center;">{{ $retour }} </td>
							<td style="text-align:center;">{{ $restant }} </td>
							<td style="text-align:center;"> </td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  
 
		  
 @push('scripts') 
	   
@endpush

@endsection