@extends('layout')
@section('title','Transfert  ')
@section('description','Transfert vers magasin ')
@section('content')
<div class="section-header">
            <h1>Transferts </h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="#">Transfert  </a></div>
              <div class="breadcrumb-item"><a href="#">Recherche </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 class="row">
              <div class="col-lg-12 col-md-12 ">
                <div class="card">
                  <div class="card-header">
                    <h4>Nouveau transfert</h4>
                  </div>
				  
                  <div class="card-body">
				  
				  <h7><strong>Veuillez d'abord sélectionner le depôt, la date début et la date fin</strong></h7>
				  
				<form  action="{{route('transfertdepotdepotPost')}}" method="POST">
                         {{csrf_field()}}
				
				  <div class="row" style="padding-top: 30px">
					<div class="col-lg-4 col-md-12"> 
					  <div class="form-group">
                      <label>Dépôt<font color="red">*</font></label>
                      <select  class="form-control select2" name="depot_id" required>
                        <option value="">Sélectionner un dépôt</option>
						@foreach($depot as $depots)
						<option value="{{$depots->id}}">{{$depots->nom}}</option>
                        @endforeach
                      </select>
                    </div>
					</div>
					 <div class="col-lg-3 col-md-12"> 
					 <div class="form-group">
                      <label>Date début</label>
                      <input type="date" class="form-control datepicker" name="date_debut" required>
                    </div>
					
					</div>
					
					 <div class="col-lg-3 col-md-12"> 
					 <div class="form-group">
                      <label>Date fin</label>
                      <input type="date" class="form-control datepicker" name="date_fin" required>
                    </div>
					
					</div>
					
					 <div class="col-lg-2 col-md-12" style="margin-top: 30px"> 
					
					 <button class="btn btn-icon  btn-primary " ><i  class="fa fa-search"></i> Rechercher</button>
					</div>
					</div>
		
                  
            
			<br><br>
					  
				</form>
					  
					    </div>
						 
                    </div>
                  </div>
                </div>

          </div>
		  
		  
		   <div class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4> Transfert(s) du dépôt : {{DB::table('depot')->where('id', $depot_id)->first()->nom}} du {{ implode('/', array_reverse(explode('-', $datedeb))) }} au {{ implode('/', array_reverse(explode('-', $datefin))) }}</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped table table-hover" 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">Etat </th>
							   <th class="text-center">Pièces </th>
							   <th class="text-center">Actions </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->depotx_id)->first()->nom}}</td>
							<td style="text-align:center;">{{DB::table('depot')->where('id', $transferts->depoty_id)->first()->nom}}</td>
							
							@php
							
							$dd = implode('/', array_reverse(explode('-', $transferts->date)));
							@endphp
							<td style="text-align:center;">{{$dd}} </td>
						
							<td class="text-center">
                            <div class="badge badge-success badge-shadow">{{$transferts->etat}}</div>
                            </td>
							
							 @php

                                 $ligne = DB::table('ligne_transfertdepotdepot')->where('transfert_id', $transferts->id)->get();

						  @endphp
						  
							
							 <td>
							 
							 <table class="table table-striped" >
                        <thead>
                          <tr>
                            <th class="text-center"> N° </th>
                           
							<th class="text-center">Produits transférés</th>
                            <th class="text-center">Quantité </th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($ligne as $lignes)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							
						    
							
							<td style="text-align:center;">
							{{DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->code}}
							/ {{DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->desi}}/
							{{DB::table('produit_vendable')->where('id', $lignes->produit_id)->first()->marque}}
							</td>
							
							<td style="text-align:center;">{{$lignes->qte}}</td>
							
                          </tr>
						  @endforeach
                        </tbody>
                      </table> 
							 
					    </td>
                        <td>
							<!--<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 ==  "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
							</td>
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </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</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 définitivement ce transfert ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="annuler">
                
              </div>
            </div>
          </div>
        </div>
		@push('scripts') 
		<script>
        $(".data-annuler").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/validertransfert/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('AnnulertransfertPost')}}" 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>`
            ;
            $('#annuler').html('').append(html);
          })
          $('#Annulermodal').modal();
        });
    </script>
		@endpush

@endsection