@extends('layout')
@section('title','Historique de vente par caissier ')
@section('description','Historique de vente par caissier')
@section('content')
			<br/>
          <div class="section-body">
		  <div class="row">
              <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/>
				@if( session('user')->roles == "Admin")
		<div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('historique-par-caissier-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>Magasin <font color="red">*</font></label>
                      <select class="form-control select2" name="caissier">
                        <option value="0">Sélectionner un caissier</option>
						@foreach($caissier1 as $caissier1s)
						<option value="{{$caissier1s->id}}">{{$caissier1s->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-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>
					@endif
			  </div>
		  </div>
			<div class="section-body">
            <div class="row">
			@php
				$d1 = implode('/', array_reverse(explode('-', request('date_debut'))));
				$d2 = implode('/', array_reverse(explode('-', request('date_fin'))));
			@endphp
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Historique ventes du caissier
					@php
					$f= DB::table('users')->where('id', $caissier)->first()->nom;
					echo '<font color="red">'.$f.'</font>';	
					@endphp
					du <font color="red">{{$d1}} </font> au <font color="red">{{$d2}}</font>
					</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th class="text-center"> ID </th>
                            <th class="text-center"> N° Facture</th>
                            <th class="text-center"> Nom du client </th>
                            <th class="text-center">Produit</th>
                            <th class="text-center">Prix de vente</th>
							<th class="text-center">Qté</th>
                            <th class="text-center">Total</th>
                            <th class="text-center">Etat</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($ligne as $lignes)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{DB::table('vente')->where('id', $lignes->vente_id)->first()->numero}}</td>
							<td style="text-align:center;">{{DB::table('vente')->where('id', $lignes->vente_id)->first()->nomcli}}</td>
							<td style="text-align:center;">{{DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->desi}}</td>
							<td style="text-align:center;">{{$lignes->pv}}</td>
							<td style="text-align:center;">{{$lignes->qte}}</td>
							<td style="text-align:center;">{{$lignes->montligne}}</td>
							<td style="text-align:center;">
								@if ($lignes->etat == "Annulée")
								 <font color="red"> {{$lignes->etat}} </font>
								@else
								{{$lignes->etat}} 
								@endif
							</td>
                          </tr>
						@endforeach
                        </tbody>
                        <tfoot>
						@php
						$tot =  number_format($total, 0, ' ', ' ');
						@endphp
							<tr>
								<td><b>Total dépense</b></td>
								<td>  <b>{{number_format($totaldep, 0, ' ', ' ')}}</b> </td>
								<td style="text-align:center;"><b>Total vente</b></td>
								<td style="text-align:center;"><b>{{number_format($montant, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>Total Remise : {{number_format($remise, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>Paiement client : {{number_format($paiement_client, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>Total net</b></td>
								<td style="text-align:center;color:red"><b>{{number_format(($total + $paiement_client) , 0, ' ', ' ')}}</b></td>
							</tr>
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          </div>
          </div>
          </div>
@endsection