@extends('layout')
@section('title','Situation de gain ')
@section('description','Situation de gain')
@section('content')
			<br/>
          <div class="section-body">
			<div class="section-body">
            <div class="row">
              <div class="col-12">
                                    <div class="card">
                  <div class="card-header">
                    <h4>Recherche</h4>
                  </div>
                  <div class="card-body">
				<form  action="{{route('historiquebenef2')}}" method="POST">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
                     <div class="col-lg-3 col-md-3"> 
					  <div class="form-group">
                      <label>Date début <font color="red">*</font></label>
                      <input type="text" class="form-control" name="date_debut" id="champ_date" required>
					  <div id="calendarMain"></div>
                    </div>
					</div>
					<div class="col-lg-3 col-md-3"> 
					  <div class="form-group">
                      <label>Date fin <font color="red">*</font></label>
                      <input type="text" class="form-control" name="date_fin" id="champ_date2" required>
					  <div id="calendarMain2"></div>
                    </div>
					</div>
					<div class="col-lg-2 col-md-2"> 
                      <button class="btn btn-icon icon-left btn-success"><i class="fas fa-search"></i> Rech</button>
					</div>
                      </div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                    </div>
                <div class="card">
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                            <tr>
                    			<th style="text-align:center">QTE</th>
                    			<th style="">ARTICLE</th>
                    			<th style="text-align:right">TOTAL</th>
                    			<th style="text-align:right">BENEF</th>
                    		  </tr>
                        </thead>
                        <tbody>
                			@foreach($produit as $produits)
                			@php
                			$qte = DB::table('ligne_vente_client')->where('produit_id', $produits->id)->sum('qte');
                			$mtl = $qte * $produits->prix_detail;
                			$mtl = number_format($mtl, 0, ' ', ' ');
                			$benef = DB::table('ligne_vente_client')->where('produit_id', $produits->id)->sum('benef');
                			$total= DB::table('ligne_vente_client')->sum('montligne');
                			$totalbenef= DB::table('ligne_vente_client')->sum('benef');
                			@endphp
                           <tr>
                			   <td align="center">&nbsp;&nbsp; {{$qte}} </td>
                			   <td align="center">{{$produits->designation}}</td>
                			   <td align="right">&nbsp;&nbsp; {{$mtl}} </td>
                			   <td align="right">&nbsp;&nbsp; {{number_format($benef, 0, ' ', ' ')}} </td>
                		   </tr>
                			@endforeach
		                </tbody>
                        <tfoot>
					        <tr>
                			   <td align="center">&nbsp;&nbsp; Total vente </td>
                			   <td  align="center">  {{number_format($total, 0, ' ', ' ')}}</td>
                			   <td align="right">&nbsp;&nbsp; Total bénéf</td>
                			   <td align="right">&nbsp;&nbsp; {{number_format($totalbenef, 0, ' ', ' ')}} </td>
                		   </tr>  
                        </tfoot>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          </div>
          </div>
          </div>
@endsection