@extends('layout')
@section('title','Liste des versements caisiers ')
@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($magasin as $magasin)
						<option value="{{$magasin->id}}">{{$magasin->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 caissiers</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  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;"> 
							    <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>
		  
   <div class="modal fade" id="Supprimermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Suppression</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Voulez-vous supprimer ce versement ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">
                
              </div>
            </div>
          </div>
        </div>
		  
	   @push('scripts') 
	   
  <script>
        $(".data-supprimer").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/es/Versement/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-light" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimerversementPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.vers.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

            </form>`
            ;
            $('#delete').html('').append(html);
          })
          $('#Supprimermodal').modal();
        });
    </script>
@endpush

@endsection