@extends('layout')
@section('title','Liste des transferts entre dépôt  ')
@section('description','Transfert dépôt - dépôt ')
@section('content')
<div class="section-header">
            <h1>Transfert entre dépôts </h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="#">Transferts entre dépôt </a></div>
              <div class="breadcrumb-item"><a href="#">Liste</a></div>
            </div>
          </div>
          <div class="section-body">
		    @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 class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Liste des transferts entre dépôt</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 de départ </th>
                            <th class="text-center">Vers dépôt </th>
							 <th class="text-center">Produits </th>
							 <th class="text-center">Date </th>
							  <th class="text-center">Etat </th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($transfert as $transferts)
						@php
						$ligne = DB::table('ligne_transfertdepotdepot')->where('transfert_id', $transferts->id)->get();
						@endphp
                          <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->depotx_id)->first()->nom}}</td>
							<td style="text-align:center;">{{DB::table('depot')->where('id', $transferts->depoty_id)->first()->nom}}</td>
							<td style="text-align:center;">
							<table class="table table-striped" id="table-1">
							<tr>
                            <th class="text-center"> Produit </th>
                            <th class="text-center"> Qté </th>
							</tr>
							@foreach($ligne as $lignes)
							@php
    						$cc = DB::table('produit_vendable')->where('id', $lignes->produit_id)->get()->count();
    						if ($cc>0){
    						    $desi = DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->desi;
    						} else {
    						    $desi = "";
    						}
    						@endphp
								<tr>
									<td>{{$desi}}</td>
									<td>{{$lignes->qte}}</td>
								</tr>
							@endforeach
							</table>
							</td>
								
							@php
							$dd = implode('/', array_reverse(explode('-', $transferts->date)));
							@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>
							    @elseif( $transferts->etat ==  "Validé")
                                    <div class="badge badge-success badge-shadow">{{$transferts->etat}}</div>
								@else
									<div class="badge badge-danger badge-shadow">{{$transferts->etat}}</div>
                                @endif
                            </td>
                            <td>
							 @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
							 @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
							@if( session('user')->roles ==  "Admin")
							@if( $transferts->etat ==  "Validé")
							<a type="button" href="#" data-id="{{$transferts->id}}" data-toggle="tooltip" data-placement="bottom" title="Annuler" class="btn btn-icon btn-danger data-annuler"><i class="fas fa-times"></i></a>
							@endif
							@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">
                Voulez-vous valider ce transfert ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="valider">
                
              </div>
            </div>
          </div>
        </div>
		<div class="modal fade" id="Annulermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Annulation 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">
                Voulez-vous annuler ce transfert ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="annuler">
                
              </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>
        $(".data-annuler").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/voirtransfertdepot/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('annulertransfertdepotdepotPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.transfert.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

            </form>`
            ;
            $('#annuler').html('').append(html);
          })
          $('#Annulermodal').modal();
        });
    </script>
	     <script>
        $(".data-valider").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/voirtransfertdepot/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('validertransfertdepotdepotPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.transfert.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

            </form>`
            ;
            $('#valider').html('').append(html);
          })
          $('#Validermodal').modal();
        });
    </script>
	   
	   <script>
        $(".data-supprimer").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/voirtransfertdepot/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimertransfertdepotdepotPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.transfert.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

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

	function selectcat(iteration = 0) {
		$('.selectcat-'+iteration).change(function () {

			var typenivo11 = $('#produits').val();
			console.log(typenivo11)
			var typeselectionner11 = $(this).val();
			typenivo11 = JSON.parse(typenivo11);
			typenivo11 = typenivo11.filter(function (x) {
				return x.categorie_id == typeselectionner11;
			});
			var option = ' <option value="">Sélectionner le produit</option> ';
			for (var i = 0; i < typenivo11.length; i++) {
				option += `
			<option value="`+ typenivo11[i].id + `">` + typenivo11[i].desi + ` / ` + typenivo11[i].code + ` / ` + typenivo11[i].prix_detail + ` </option>
			`;

			}
			$('#selectproduit-'+iteration).html(option);

		})
	}

	selectcat(0);
    
</script>
	   
@endpush

@endsection