@extends('layout')
@section('title','Liste de toutes les ventes clients externes')
@section('description','Liste de toutes les ventes clients externes')
@section('content')
			<br/>
          <div class="section-body">
		  <div class="row">
		  <div class="col-md-12">
			<a type="button" target="_blank" href="{{route('toutes-les-ventes-client-pdf')}}" class="btn btn-icon btn-info pull-right"><i class="fas fa-print"></i> Imprimer la liste
			</a>	
			<br/>
			<br/>
			</div>
              <div class="col-12">
			  <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
				<br/>
		<div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('toutes-les-ventes-rech-client')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					<div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Magasin <font color="red">*</font></label>
                      <select class="form-control select2" name="magasin">
                        <option value="0">Tous les magasins</option>
						@foreach($magasin1 as $magasin11)
						<option value="{{$magasin11->id}}">{{$magasin11->nom}}</option>
						@endforeach
                      </select>
                    </div>
					</div>
                     <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" 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" required>
					  <div id="calendarMain2"></div>
                    </div>
					</div>
					<div class="col-lg-2 col-md-3"> 
                      <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 class="row">
              <div class="col-12">
                <div class="card">
				@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="card-header">
                    <h4>Liste des bons de livraison du magasin 
					@php
					if ($magasin==0)
						{
							echo 'Tous les magasins';
					}
							else
								{
									$f= DB::table('magasin')->where('id', $magasin)->first()->nom;
									echo $f;
							}
							@endphp
							du {{$date_debut}} au {{$date_fin}}
							&nbsp;&nbsp;&nbsp;/ Nombre de ventes : {{$totalcount}}
							</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th>N°</th>
                            <th>Date</th>
                            <th>Magasin</th>
                            <th>Client</th>
                            <th>Montant</th>
                            <th>Actions</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($ventes as $vente)
						@php
						if ($vente->magasin_id > 0){
						    $nomb = DB::table('magasin')->where('id', $vente->magasin_id)->first()->nom;
						}else{
						    $nomb = DB::table('depot')->where('id', $vente->depot_id)->first()->nom;
						}
						@endphp
                          <tr>
							<td style="text-align:center;">BL{{$vente->numero}}</td>
							<td style="text-align:center;">{{$vente->date}}</td>
							<td style="text-align:center;">
							{{$nomb}}
							</td>
							<td style="text-align:center;">
							{{DB::table('client_externe')->where('id', $vente->client_id)->first()->noms}}
							</td>
							@php
							$dd = implode('/', array_reverse(explode('-', $vente->date)));
							$lh1 =  number_format($vente->montant, 0, ' ', ' ');
							$tod = date('Y-m-d');
							@endphp
							<td style="text-align:center;">{{$lh1}} FCFA</td>
							<td class="align-middle">
							<a type="button" href="{{route('ligne-vente-client',['id'=>$vente->id])}}" data-toggle="tooltip" data-placement="bottom" title="Détails" class="btn btn-icon btn-info"><i class="fas fa-info"></i></a>
							 @if( $vente->etat ==  "Proforma")
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$vente->id}}" data-placement="bottom" title="Valider" class="btn btn-icon btn-success data-valider"><i class="fas fa-check"></i></a>
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$vente->id}}" data-placement="bottom" title="Supprimer" class="btn btn-icon btn-danger data-supprimer"><i class="fas fa-trash"></i></a>
							<a type="button" href="{{route('modifier_vente_client',['id'=>$vente->id])}}" data-toggle="tooltip"
                                            data-placement="bottom" title="Modifier"
                                            class="btn btn-icon btn-primary"><i
                                                class="fas fa-edit"></i></a>
							@endif
							@if( $vente->etat ==  "Validée")
							<a type="button" href="{{route('modifier_vente_client_',['id'=>$vente->id])}}" data-toggle="tooltip"
                                            data-placement="bottom" title="Modifier"
                                            class="btn btn-icon btn-primary"><i
                                                class="fas fa-edit"></i></a>
                            
							@endif
							<!--<a type="button" target="_blank" href="{{route('factureVenteclient',['id'=>$vente->id])}}" class="btn btn-icon btn-warning" data-toggle="tooltip" data-placement="bottom" title="BL AVEC PRIX"><i class="fas fa-print"></i></a>	
							<a type="button" target="_blank" href="{{route('factureVenteclient2',['id'=>$vente->id])}}" class="btn btn-icon btn-danger" data-toggle="tooltip" data-placement="bottom" title="BL SANS PRIX"><i class="fas fa-print"></i></a>-->
							<a type="button" target="_blank" href="{{route('factureclient',['id'=>$vente->id])}}" class="btn btn-icon btn-success" data-toggle="tooltip" data-placement="bottom" title="Facture"><i class="fas fa-print"></i></a>	
							<a type="button" target="_blank" href="{{route('factureclient21',['id'=>$vente->id])}}" class="btn btn-icon btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Invoice"><i class="fas fa-print"></i></a>
							@if( $vente->etat ==  "Validée")
							<!--<a type="button" href="{{route('livraison',['id'=>$vente->id])}}" class="btn btn-icon btn-primary" data-toggle="tooltip" data-placement="bottom" title="Editer bon de livraison"><i class="fas fa-file"></i></a>-->	
							@endif
							</td>
                          </tr>
						  @endforeach
                        </tbody>
						<tr>
							<td colspan="2"></td>
							<td style="text-align:center;font-size:14px;"> Total</td>
							<td style="text-align:center;font-size:14px;">
							@php
								$total = $total;
								$ph =  number_format($total, 0, ' ', ' ');
							@endphp
							{{$ph}} FCFA
							</td>
                          </tr>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
		
@endsection