<!DOCTYPE html>
<html lang="en">


<!-- Mirrored from www.radixtouch.in/templates/logicswave/ality/source/light/ by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 02 Sep 2020 20:02:10 GMT -->
<head>
  <meta charset="UTF-8">
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" name="viewport">
  <title>Mouvements stock : @php if ($magasin==0) { echo 'Stock en général';} else {$mg=DB::table('magasin')->where('id',$magasin)->first()->nom; echo $mg;}@endphp</title>  
		</head>
			<body style="font-family:'Montserrat';font-size:12px;">
			<h3> Mouvements stock : @php if ($magasin==0) { echo 'Stock en général';} else {$mg=DB::table('magasin')->where('id',$magasin)->first()->nom; echo $mg;}@endphp </h3>
			  <table border="1" class="table table-striped" id="table-1" style="border-collapse: collapse;font-family:'Montserrat';font-size:12px;width:720px;">
                        <thead>
                          <tr>
							<th style="text-align:center;">N°</th>
							<th style="text-align:center;">Désignation</th>
							<th style="text-align:center;">Prix détail</th>
							<th style="text-align:center;">Prix semi</th>
							<th style="text-align:center;">Prix gros</th>
							<th style="text-align:center;">Entrées(Qté approv.)</th>
							<th style="text-align:center;">Sorties(Vendues)</th>
							<th style="text-align:center;">En stock</th>
						</tr>
                        </thead>
                       <tbody>
	@foreach($produits as $produit)
	@php
		if ($magasin==0){
		$totap0 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Inventaire')->sum('qte');
		$totap1 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Appro')->sum('qte');
		$totap2 =  DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'TransfertRecu')->sum('qte');
		$totap = $totap0 + $totap1 + $totap2;
		$totvente0 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Transfert')->sum('qte');
		$totvente1 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Vente')->sum('qte');
		$totvente2 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Vente')->sum('qte');
		$totvente = $totvente0 + $totvente1;
		$totstk = $totap - ($totvente + $totvente2);
		} else {
		$totap0 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('magasin_id', $magasin)->where('type_operation', 'Inventaire')->sum('qte');
		$totap1 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('magasin_id', $magasin)->where('type_operation', 'Appro')->sum('qte');
		$totap2 =  DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'TransfertRecu')->where('magasin_id', $magasin)->sum('qte');
		$totap = $totap0 + $totap1 + $totap2;
		$totvente0 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('magasin_id', $magasin)->where('type_operation', 'Transfert')->sum('qte');
		$totvente1 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('magasin_id', $magasin)->where('type_operation', 'Vente')->sum('qte');
		$totvente = $totvente0 + $totvente1;
		$totvente2 = DB::table('stock_magasin')->where('produit_id', $produit->id)->where('type_operation', 'Vente')->where('magasin_id', $magasin)->sum('qte');
		$totstk = $totap - $totvente;
		}
		
	@endphp
	<tr>
        <td style="text-align:center;font-size:14px;">{{$loop->iteration}}</td>
        <td style="font-size:14px;">{{$produit->designation}}</td>
        <td style="text-align:center;font-size:14px;">{{number_format($produit->prix_detail, 0, ' ', ' ')}}</td>
        <td style="text-align:center;font-size:14px;">{{number_format($produit->prix_semigros, 0, ' ', ' ')}}</td>
        <td style="text-align:center;font-size:14px;">{{number_format($produit->prix_gros, 0, ' ', ' ')}}</td>
        <td style="text-align:center;font-size:14px;"> {{$totap}} {{$produit->unite_mesure}}</td>
        <td style="text-align:center;font-size:14px;">{{$totvente}} {{$produit->unite_mesure}}</td>
        <td style="text-align:center;font-size:14px;">{{$totstk}} {{$produit->unite_mesure}}</td>
    </tr>
	@endforeach
                        </tbody>
                      </table>
                    </body>
</html>