@extends('layout')
@section('title','Liste des transferts')
@section('content')
	@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">
            <div class="card">
                  <div class="card-header">
                    <h4>Liste des transferts</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">Référence</th>
                            <th class="text-center">Dépôt </th>
                            <th class="text-center">Vers </th>
							 <th class="text-center">Date </th>
							 <th class="text-center">Articles </th>
							  <th class="text-center">Etat </th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($transfert as $transferts)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							
							<td style="text-align:center;">{{ $transferts->numero}} </td>
							<td style="text-align:center;">{{DB::table('depot')->where('id', $transferts->depot_id)->first()->nom}}</td>
							<td style="text-align:center;">{{DB::table('magasin')->where('id', $transferts->magasiny_id)->first()->nom}}</td>
							
							@php
							
							$dd = implode('/', array_reverse(explode('-', $transferts->date)));
							$ligne = DB::table('ligne_transfert')->where('transfert_id', $transferts->id)->get();
							@endphp
							<td style="text-align:center;">{{$dd}} </td>
						
							 <td class="text-center">
							    @if( $transferts->etat ==  "En cours")
									
                                  <div class="badge badge-warning badge-shadow">{{$transferts->etat}}</div>
							    @else
                                      <div class="badge badge-success badge-shadow">{{$transferts->etat}}</div>
                                @endif
								  
                            </td>
							
							<td>
								<table class="table table-striped">
									@foreach($ligne as $lignes)
									<tr>
										<td>{{  DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->barcode }} {{  DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->designation }}</td>
										<td>{{  $lignes->qte }}</td>
									</tr>
									@endforeach
								</table>
							</td>
							
							
                            <td style="text-align:center;">
							 @if( $transferts->etat ==  "En cours")
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$transferts->id}}" data-placement="bottom" title="Valider" class="btn btn-icon btn-success data-valider"><i class="fas fa-check"></i></a>
							@endif
							
							<a type="button" href="{{route('consultation_transfert',['id'=>$transferts->id])}}" data-toggle="tooltip" data-placement="bottom" title="Détails" class="btn btn-icon btn-info"><i class="fas fa-info"></i></a>
							 @if( $transferts->etat ==  "En cours")
							<a type="button" href="#" data-id="{{$transferts->id}}" data-toggle="tooltip" data-placement="bottom" title="Supprimer" class="btn btn-icon btn-danger data-supprimer"><i class="fas fa-trash"></i></a>
							@endif
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
        </div>
    </div>
</div>
</div>
</div>
<div class="modal fade" id="Validermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Validation du transfert</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                <div class="progress progress-lg" id="pg" style="display:none">
					<div class="progress-bar progress-bar-warning progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%;height:50px">
						<br>Traitement en cours, veuillez patienter...
					</div>
				</div>
                <p id="nn" style="text-align:center">Voulez-vous valider ce transfert ?</p>
            </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="valider">
                
              </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 définitivement ce transfert ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">
                
              </div>
            </div>
          </div>
        </div>
	@push('scripts')
	<script>
	function myFunction() {
		$('#bregister').hide();
		$('#bregister2').hide();
		$('#bregister3').hide();
		$('#pg').show();
		$('#mm').hide();
		$('#nn').hide();
		//$("#nn").attr("value", "Traitement en cours, veuillez patienter...");
		//document.getElementById("nn").value = "Traitement en cours, veuillez patienter...";
		//document.getElementById("nn").innerHTML = "Traitement en cours, veuillez patienter...";
	}
	</script>
	     <script>
        $(".data-valider").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/es/validertransfert/'+id, function (data) {
                  var html = `
                      <form action="{{route('validertransferteffecuePost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.tran.id+`" name="id" >
                      <button type="submit" class="btn btn-success" onclick="myFunction()" id="bregister">Oui</button>
					  <button type="button" class=" btn btn-danger" data-dismiss="modal" id="bregister2">Non</button>
            </form>`
            ;
            $('#valider').html('').append(html);
          })
          $('#Validermodal').modal();
        });
    </script>
	   
	   <script>
        $(".data-supprimer").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/es/validertransfert/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimertransfertPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.tran.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

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

	@endpush
@endsection