@extends('layout')
@section('title','Facture client ')
@section('description','Facture client')
@section('content')
			<br/>
          <div class="section-body">
		  <div class="row">
              <div class="col-8 offset-2">
			  <br/>
				@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
				<br/>
		<div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('recherche-facture-client2')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					<div class="col-lg-6 col-md-6"> 
					  <div class="form-group">
                      <label>Numéro de la facture <font color="red">*</font></label>
                      <input type="text" class="form-control" name="numero" required>
                    </div>
					</div>
					<div class="col-lg-4 col-md-6" style="margin-top:26px;"> 
                      <button class="btn btn-icon icon-left btn-success"><i class="fas fa-search"></i> Rechercher</button>
					</div>
                      </div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                    </div>
			  </div>
		  </div>
			<div class="section-body">
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4>Facture vente</h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th class="text-center"> ID </th>
                            <th class="text-center"> N° </th>
                            <th class="text-center">Client</th>
							<th class="text-center">Date</th>
                            <th class="text-center">Montant HT</th>
                            <th class="text-center">Montant Taxe</th>
                            <th class="text-center">Montant TTC</th>
                            <th class="text-center">Etat</th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($ventes as $vente)
                          <tr>
							<td style="text-align:center;">{{$loop->iteration}}</td>
							<td style="text-align:center;">BL{{$vente->numero}}</td>
							<td style="text-align:center;">{{DB::table('client_externe')->where('id', $vente->client_id)->first()->noms}}</td>
							@php
							$dd = implode('/', array_reverse(explode('-', $vente->date)));
							$mht =  number_format($vente->montant_ht, 0, ' ', ' ');
							$total_taxe2 =  number_format($vente->total_taux, 0, ' ', ' ');
							$lh3 =  number_format($vente->montant, 0, ' ', ' ');
							$tod = date('Y-m-d');
							$verif = DB::table('paiement_client')->where('vente_id', $vente->id)->get()->count();
							@endphp
							<td style="text-align:center;">{{$dd}} {{$vente->heure}}</td>
							<td style="text-align:center;">{{$mht}} FCFA</td>
							<td style="text-align:center;">{{$total_taxe2}} FCFA</td>
							<td style="text-align:center;">{{$lh3}} FCFA</td>
							<td style="text-align:center;">
							@if( $vente->etat ==  "Proforma")
							<div class="badge badge-warning badge-shadow">{{$vente->etat}}</div>
							@elseif( $vente->etat ==  "Validée")
							<div class="badge badge-success badge-shadow">{{$vente->etat}}</div>
							@else
							<div class="badge badge-danger badge-shadow">{{$vente->etat}}</div>
							@endif
							</td>
							<td class="align-middle">
							<a type="button" href="{{route('ligne-vente-client',['id'=>$vente->id])}}" data-toggle="tooltip" data-placement="bottom" title="Détails" class="btn btn-icon btn-info"><i class="fas fa-info"></i></a>
							 @if( $vente->etat ==  "Proforma")
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$vente->id}}" data-placement="bottom" title="Valider" class="btn btn-icon btn-success data-valider"><i class="fas fa-check"></i></a>
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$vente->id}}" data-placement="bottom" title="Supprimer" class="btn btn-icon btn-danger data-supprimer"><i class="fas fa-trash"></i></a>
							<!--<a type="button" href="{{route('modifier_vente_client',['id'=>$vente->id])}}" data-toggle="tooltip"
                                            data-placement="bottom" title="Modifier"
                                            class="btn btn-icon btn-primary"><i
                                                class="fas fa-edit"></i></a>-->
							@endif
							@if( $vente->etat ==  "Validée")
							<!--<a type="button" href="{{route('modifier_vente_client_',['id'=>$vente->id])}}" data-toggle="tooltip"
                                            data-placement="bottom" title="Modifier"
                                            class="btn btn-icon btn-primary"><i
                                                class="fas fa-edit"></i></a>-->
                            
							@endif
							<!--<a type="button" target="_blank" href="{{route('factureVenteclient',['id'=>$vente->id])}}" class="btn btn-icon btn-warning" data-toggle="tooltip" data-placement="bottom" title="BL AVEC PRIX"><i class="fas fa-print"></i></a>-->		
							<!--<a type="button" target="_blank" href="{{route('factureVenteclient2',['id'=>$vente->id])}}" class="btn btn-icon btn-danger" data-toggle="tooltip" data-placement="bottom" title="BL SANS PRIX"><i class="fas fa-print"></i></a>-->		
							<a type="button" target="_blank" href="{{route('factureclient',['id'=>$vente->id])}}" class="btn btn-icon btn-success" data-toggle="tooltip" data-placement="bottom" title="Facture"><i class="fas fa-print"></i></a>	
							@if( $vente->etat ==  "Validée")
							<!--<a type="button" href="{{route('livraison',['id'=>$vente->id])}}" class="btn btn-icon btn-primary" data-toggle="tooltip" data-placement="bottom" title="Editer bon de livraison"><i class="fas fa-file"></i></a>-->	
							@endif
							
							@if( $verif == 0)
							@if( $vente->etat ==  "Validée")
							<a type="button" href="#" data-toggle="tooltip" data-id="{{$vente->id}}" 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>
		  <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 ce BL  ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="annuler">
                
              </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</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 BL ?
            </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 ce BL ?
            </div>
            <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">

            </div>
        </div>
    </div>
</div>

@push('scripts')

<script>
        $(".data-valider").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/es/Validerventeclient/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('ValiderventeclientPot')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.vente.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+'/es/Venteclient/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimerventeclientPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.ven.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

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

            </form>`
            ;
            $('#annuler').html('').append(html);
          })
          $('#Annulermodal').modal();
        });
    </script>
@endpush
@endsection