<html>
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link id="bs-css" href="css/bootstrap-cerulean.min.css" rel="stylesheet">
	<link href="css/charisma-app.css" rel="stylesheet">
    <link href='bower_components/fullcalendar/dist/fullcalendar.css' rel='stylesheet'>
    <link href='bower_components/fullcalendar/dist/fullcalendar.print.css' rel='stylesheet' media='print'>
    <link href='bower_components/chosen/chosen.min.css' rel='stylesheet'>
    <link href='bower_components/colorbox/example3/colorbox.css' rel='stylesheet'>
    <link href='bower_components/responsive-tables/responsive-tables.css' rel='stylesheet'>
    <link href='bower_components/bootstrap-tour/build/css/bootstrap-tour.min.css' rel='stylesheet'>
    <link href='css/jquery.noty.css' rel='stylesheet'>
    <link href='css/noty_theme_default.css' rel='stylesheet'>
    <link href='css/elfinder.min.css' rel='stylesheet'>
    <link href='css/elfinder.theme.css' rel='stylesheet'>
    <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
    <link href='css/uploadify.css' rel='stylesheet'>
    <link href='css/animate.min.css' rel='stylesheet'>
        <title>Etat des boisson en fin de journée</title>
    </head>
      <body style="font-family:'Montserrat';font-size:18px;" onload="window.print();">
            <div class="container">
		   <div class="row">
		    <div class="col-md-12">  
                <center>
				<br/>				
				<img src="{{public_path('assets/img/logohopital.jpg')}}"/><br/><br/>
				<p><b>Ordre Hospitalier de St Jean de Dieu TANGUIETA</b></p>
				<hr style="width:150px;" />
				<p><b></b></p>
				</center>
		    </div>
		</div></div>
		<!--BLOC DU GERANT-->
		<div class="container">
		<div class="row"> 
                <div class="col-md-4" style="margin-left:20px;">
					@php
					$date_debut1= explode('-', $date_debut);
					$date_debut1= array_reverse($date_debut1);
					$date_debut1= implode('/', $date_debut1);
					
					$date_fin1= explode('-', $date_fin);
					$date_fin1= array_reverse($date_fin1);
					$date_fin1= implode('/', $date_fin1);
					@endphp
					<p><b>Stock boissons du :</b> 
					@php
					if ($date_debut1 == $date_fin1){
						$date ="Stock boisson du ".$date_debut1;
					} else {
						$date ="Stock boisson du ".$date_debut1." au ".$date_fin1;
					}
					@endphp
					{{$date}}</p>
			        </div>
				<div class="col-md-4">  
                    &nbsp;
		        </div>
		</div>
		</div>
     <center>
        <table class="rpp" border='1' style="border-collapse: collapse;margin-left:25px;width:600px" cellspacing="3">
		<thead>
                          <tr>
							<th style="text-align:center;">N°</th>
							<th style="text-align:center;">Désignation</th>
							<th style="text-align:center;">Quantité entrée</th>
							<th style="text-align:center;">Après</th>
							<th style="text-align:center;">Vendus</th>
							<th style="text-align:center;">En stock</th>
						</tr>
                        </thead>
        <tbody>
					@foreach($produits as $produit)
					@php
					
					   $idcat = $produit->cat_id;
					 
					   $idprod = $produit->pv_id;
					   $date = date('Y-m-d');
				
					   
					   if( $idcat == "4" ){ 
					   
					   $totap = DB::table('stock_resto')->where('produit_id', $produit->id)->where('type_operation', 'Appro')->whereBetween('date', [$date_debut,$date_fin])->get()->sum('nbre');
						$totstock = DB::table('stock_resto')->where('produit_id', $produit->id)->where('type_operation', 'Appro')->get()->sum('nbre');
						$aprescount = DB::table('stock_resto')->where('produit_id', $produit->id)->get()->count();
						if ($aprescount>0){
						   $apres = DB::table('stock_resto')->where('produit_id', $produit->id)->orderBydesc('id')->take(1)->first()->apres;
					   } else {
							$apres = 0;
					   }
					   }else{ 
					   $aprescount = DB::table('stock_resto')->where('produit_id', $produit->id)->get()->count();
					   if ($aprescount>0){
						   $apres = DB::table('stock_resto')->where('produit_id', $produit->id)->orderBydesc('id')->take(1)->first()->apres;
					   } else {
							$apres = 0;
					   }
					   $totap = DB::table('stock_resto')->where('produit_id', $produit->id)->where('type_operation', 'Appro')->whereBetween('date', [$date_debut,$date_fin])->get()->sum('nbre');
					   $totstock = DB::table('stock_resto')->where('produit_id', $produit->id)->where('type_operation', 'Appro')->get()->sum('nbre');
					   }
						
						$totvente0 = DB::table('ligne_vente')->where('produit_id', $produit->id)->where('etat', 'Validée')->whereBetween('date', [$date_debut,$date_fin])->get()->sum('qte');
						$totvente2 = DB::table('ligne_vente_client')->where('produit_id', $produit->id)->where('etat', 'Validée')->whereBetween('date', [$date_debut,$date_fin])->get()->sum('qte');
						$totvente = $totvente0 + $totvente2;
					@endphp
	<tr>
        <td style="text-align:center;font-size:14px;">{{$loop->iteration}}</td>
        <td style="text-align:center;font-size:14px;">{{$produit->designation}}</td>
        <td style="text-align:center;font-size:14px;">{{$totap}} {{$produit->unite_mesure}}</td>
        <td style="text-align:center;font-size:14px;">{{$totstock}} {{$produit->unite_mesure}}</td>
        <td style="text-align:center;font-size:14px;">{{$totvente}} {{$produit->unite_mesure}}</td>
        
		<td style="text-align:center;font-size:18px;">
			{{$apres}} {{$produit->unite_mesure}}
        </td>
    </tr>
	@endforeach
        </tbody>
        </table>
		<p style="margin-left:430px;margin-top:90px;"><strong>Caissier(e),</strong><br/>
        Ce <?php echo date('d-m-Y');?>
        </p>
      </div>
        <footer style="position:fixed;bottom:0;text-align:center;">
        <p align="center"><strong><font color="#dc2a26">&copy; Ordre Hospitalier de St Jean de Dieu TANGUIETA 2019-2020</font> </strong>  </p>
        </footer>
      </body>
     </html> 