@extends('layout')
@section('title','Detail vente ticket ')
@section('content')
		<br/>
		           
		   <div class="section-body">
            <div class="row">
			
            <div class="col-md-12">
			  
                <div class="card">
                  <div class="card-header">
                    <h4>Details de la vente de tickets</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">N° ticket</th>
							 <th class="text-center">Montant ticket</th>
							  <th class="text-center">Etat ticket</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($detail as $details)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							@php
							   
							   $monttic = DB::table('ticket')->where('id', $details->type_ticket_id)->first()->montant ;
							   $lh1 =  number_format($monttic, 0, ' ', ' ');
							
							@endphp
							<td style="text-align:center;">{{$details->ref}}</td>
							<td style="text-align:center;">{{$lh1}} FCFA</td>
							
							@php
							
							 $numtic = DB::table('vente')->where('num_ticket', $details->ref)->where('etat', 'Validée')->first() ; 
							 
							 if( $numtic){
								 
								 \Illuminate\Support\Facades\DB::table('ligne_vente_ticket')->where('id', $details->id)->update(
							        [
							          'etat' => "Utilisé",
							        ]);
								 $details = \Illuminate\Support\Facades\DB::table('ligne_vente_ticket')->where('id', $details->id)->first();
							 }else{
								 
								  \Illuminate\Support\Facades\DB::table('ligne_vente_ticket')->where('id', $details->id)->update(
							        [
							          'etat' => "Non utilisé",
							        ]);
                               $details = \Illuminate\Support\Facades\DB::table('ligne_vente_ticket')->where('id', $details->id)->first();
								 }
							 
							 @endphp
							
							 @if($details->etat == "Non utilisé")
								<td style="text-align:center;">
									<span class="badge badge-success badge-shadow">
									 {{$details->etat}}  
									</span>
								</td>
						    @else
								
							<td style="text-align:center;">
								<span class="badge badge-danger badge-shadow">
								 {{$details->etat}}  
								</span>
							</td>
								
							@endif
                          </tr>
						  @endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
             
            </div>
          </div>
		  
 @push('scripts') 

@endpush

@endsection