@extends('layout')
@section('title','Liste des versements par magasin ')
@section('content')
		<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
		    <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/>
		<div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('versement-par-magasin')}}" 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 $magasin1)
						<option value="{{$magasin1->id}}">{{$magasin1->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>
			  </div>
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des versements; @php if ($magasin==0){echo "Tous les magasins";} else {
						$nom = DB::table('magasin')->where('id', $magasin)->first()->nom;
						echo $nom."&nbsp;&nbsp;Période:&nbsp;".$date_debut."&nbsp;au&nbsp;".$date_fin;
					}
					@endphp
					</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">Vente </th>
                            <th class="text-center">Montant vente à verser</th>
                            <th class="text-center">Montant versé</th>
                            <th class="text-center">Montant écart</th>
                            <th class="text-center">Notes</th>
                            <th class="text-center">Date</th>
                            <th class="text-center">Caissier</th>
                            <!--<th  style="text-align:center;">Action</th>-->
                          </tr>
                        </thead>
                        <tbody>
						@foreach($versement as $versements)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							@php
							
							   $lh1 =  number_format($versements->mont_a_verser, 0, ' ', ' ');
							   
							   $lh3 =  number_format($versements->mont_verse, 0, ' ', ' ');
							   
							   $lh4 =  number_format($versements->ecart, 0, ' ', ' ');
							
							@endphp
							<td style="text-align:center;">{{DB::table('cloture')->where('id', $versements->clo_id)->first()->libelle}}</td>
							<td style="text-align:center;">{{$lh1}} FCFA</td>
							<td style="text-align:center;">{{$lh3}} FCFA</td>
							<td style="text-align:center;">{{$lh4}} FCFA</td>
							<td style="text-align:center;">{{$versements->notes}}</td>
							<td style="text-align:center;">{{ implode('/', array_reverse(explode('-', $versements->date))) }}</td>
							<td style="text-align:center;">{{DB::table('users')->where('id',$versements->user_id)->first()->nom}}</td>
							<!--<td style="text-align:center;"> 
							    <a type="button" href="#" data-id="{{$versements->id}}" data-toggle="tooltip" data-placement="bottom" title="Supprimer" class="btn btn-icon btn-danger data-supprimer"><i class="fas fa-trash"></i></a> 
							</td>
							-->
                          </tr>
						  @endforeach
                        </tbody>
                        <tfoot>
						<tr>
							<td style="text-align:center" colspan="2"> <b>Totaux</b></td>
							<td style="text-align:center"> 
							@php
								
								$averser =  number_format($averser, 0, ' ', ' ');
							@endphp
							<b>{{$averser}} FCFA</b></td>
							<td style="text-align:center"> 
							@php
								
								$montverse =  number_format($montverse, 0, ' ', ' ');
							@endphp
							<b>{{$montverse}} FCFA</b></td>
							<td style="text-align:center">
							@php
								
								$ecart =  number_format($ecart, 0, ' ', ' ');
							@endphp
							<b>{{$ecart}} FCFA</b></td>
							<td style="text-align:center" colspan="2"></td>
						  </tr>
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
             
            </div>
          </div>
@endsection