@extends('layout')
@section('title','Liste des ventes cloturées ')
@section('description','Liste des ventes cloturées')
@section('content')
			<br/>
          <div class="section-body">
		  @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="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>
		  </div>
			<div class="row">
              <div class="col-12">
				<div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('rechcloturees')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-5 col-md-5"> 
					  <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-5 col-md-5"> 
					  <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>
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des ventes journalières du {{$date_debut}} au {{$date_fin}}</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th>N°</th>
                            <th>Caissier</th>
                            <th>Date</th>
                            <th>Recette</th>
                            <th>Dépense</th>
                            <th>Caisseoff</th>
                            <th>Versé</th>
                            <th>Reste</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($cloture as $clotures)
						@php
						$verse = DB::table('versement_caisier')->where('cloture_id', $clotures->id)->sum('montant');
						$rr = $clotures->caisseoff - $verse;
						@endphp
                          <tr>
						<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">{{DB::table('users')->where('id',$clotures->user_id)->first()->login}}</td>
							@php
							$clotures->date= explode('-', $clotures->date);
							$clotures->date= array_reverse($clotures->date);
							$clotures->date= implode('/', $clotures->date);
							@endphp
							<td style="text-align:center;">{{$clotures->date}}</td>
							@php
							$lh = $clotures->montant;
							$lh1 =  number_format($lh, 0, ' ', ' ');
							@endphp
							<td style="text-align:center;">{{$lh1}} FCFA</td>
							<td style="text-align:center;">{{number_format($clotures->totaldep, 0, ' ', ' ')}} FCFA</td>
							<td style="text-align:center;">{{number_format($clotures->caisseoff, 0, ' ', ' ')}} FCFA</td>
							<td style="text-align:center;">{{number_format($verse, 0, ' ', ' ')}} FCFA</td>
							<td style="text-align:center;">{{number_format($rr, 0, ' ', ' ')}} FCFA</td>
                          </tr>
						  @endforeach
                        </tbody>
                        <tfoot>
                        @php
						$tverse = DB::table('versement_caisier')->whereBetween('date', [$date_debut,$date_fin])->sum('montant');
						$rrr = $caisseoff - $tvers;
						@endphp
							<tr>
								<td style="text-align:center;"><b></b></b></td>
								<td style="text-align:center;"><b></b></td>
								<td style="text-align:center;"><b></b></td>
								<td style="text-align:center;"><b>{{number_format($total, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>{{number_format($totaldep, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>{{number_format($caisseoff, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>{{number_format($tvers, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"><b>{{number_format($rrr, 0, ' ', ' ')}}</b></td>
								<td style="text-align:center;"> </td>
							</tr>
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
				<p align="center">
					<a type="button" target="_blank" href="{{route('ventejourpdf')}}" class="btn btn-icon btn-warning"><i class="fas fa-print"></i> Imprimer</a>	
				</p>
              </div>
            </div>
          </div>
          </div>
@endsection