@extends('layout')
@section('title','Stock ')
@section('description','Stock')
@section('content')
    <!-- content ends -->
	<div class="row">
	
    <div class="box col-md-12">
	@if (session('status'))
				<div class="alert alert-success" role="alert">
					<i class="ti-check"></i> {{ session('status') }}
				</div>
			@endif

			@if (session('error'))
				<div class="alert alert-danger" role="alert">
					<i class="ti-na"></i> {{ session('error') }}
				</div>
			@endif
	@if(session('user')->roles == "Admin")
	<br/><br/><br/><br/><br/>
		<div class="card">
                  <div class="card-header">
                    <h4>Par période</h4>
                  </div>
				  
                  <div class="card-body">
				  
				  <h7><strong>Veuillez d'abord sélectionner la date début et la date fin</strong></h7>
				  
				<form method="POST" action="{{ route('etat.transfert.resultat') }}">
                         {{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_id" required>
                        <option value="">Sélectionner le magasin</option>
						 @foreach($magasin as $magasins)
						<option value="{{$magasins->id}}" {{ (old('magasin_id', $request->magasin_id ?? '') == $magasins->id) ? 'selected' : '' }}>{{$magasins->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" name="date_debut" value="{{ old('date_debut', $request->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" name="date_fin" value="{{ old('date_fin', $request->date_fin ?? '') }}" required>
                    </div>
					</div>
					 <div class="col-lg-1 col-md-12" style="margin-top: 30px"> 
					 <button class="btn btn-icon  btn-primary " ><i  class="fa fa-search"></i></button>
					</div>
					</div>	  
				</form>
					    </div>
                    </div>
					@endif
		<br/>
</div>
</div>

<div class="section-body">
    <div class="row">
        <div class="col-12">
            <div class="card">
                  <div class="card-header">
                    <h4>Liste des transferts</h4>
                    @isset($resultats)
                    <form method="POST" action="{{ route('etat.transfert.pdf') }}">
                        @csrf
                        <input type="hidden" name="magasin_id" value="{{ $request->magasin_id }}">
                        <input type="hidden" name="date_debut" value="{{ $request->date_debut }}">
                        <input type="hidden" name="date_fin" value="{{ $request->date_fin }}">
                        <button type="submit" class="btn btn-danger mb-3">📄 Exporter en PDF</button>
                    </form>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                            <tr>
                                <th>Désignation</th>
                                <th>Qté Transférée</th>
                                <th>Qté Vendue</th>
                                <th>Stock Actuel</th>
                            </tr>
                        </thead>
                        <tbody>
					        @forelse($resultats as $ligne)
                                <tr>
                                    <td>{{ $ligne['designation'] }}</td>
                                    <td>{{ $ligne['qte_transfert'] }}</td>
                                    <td>{{ $ligne['qte_vendue'] }}</td>
                                    <td>{{ $ligne['stock_actuel'] }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="4" class="text-center">Aucun résultat</td>
                                </tr>
                            @endforelse
                        </tbody>
                      </table>
                      @endisset
                    </div>
                  </div>
                </div>
        </div>
    </div>
</div>
	@push('scripts')
	@endpush
@endsection