<?php
// ini_set('display_errors',1);

require_once ("../../config/Cado.php");
require_once ("../producto/cProducto.php");
$oProducto = new cProducto();
require_once ("../stock/cStock.php");
$oStock = new cStock();
require_once("../producto/cProductomarca.php");
$oProductomarca = new cProductomarca();
require_once ("../formatos/formato.php"); 
require_once("../producto/cProductotag.php");
$oProductotag = new cProductotag();

require_once("../stockvalorizadocompra/cStockvalorizadocompra.php");
$oStockvalorizadocompra = new cStockvalorizadocompra();

require_once("../producto/cProductomarcacodigo.php");
$oProductomarcacodigo = new cProductomarcacodigo();

$emp_id = $_POST['cmb_fil_empresa_id'];

if($emp_id>0)
{

	$dts1=$oStockvalorizadocompra->mostrar_filtro(fecha_mysql($_POST['txt_fil_valcom_fec1']),fecha_mysql($_POST['txt_fil_valcom_fec2']),
	$_POST['txt_fil_pro_dat1'],$_POST['txt_fil_pro_dat2'],
	$_POST['cmb_fil_cat_id'],$_POST['txt_fil_pro_mar'],$emp_id);
	$num_rows= mysqli_num_rows($dts1);
  
}
else
{
	$num_rows=0;
}

?>

<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:5px;">
	
					<div class="table-responsive">
	
					<table id="tabla_producto" class="table table-bordered table-striped">
						<thead>
			                <tr>
			                    <th nowrap >NOMBRE</th>
			                    <th nowrap >MARCA</th>
			                    <th nowrap >CATEGORIA</th>
			                    <th nowrap >PRESENTACION</th>
			                    <th align="right" nowrap>CANTIDAD</th>
			                    <th align="right" nowrap>P. COSTO UNITARIO</th>
			                    <th align="right" nowrap>P. COSTO TOTAL</th>
			                </tr>
			            </thead>
						 <tbody>
			                <?php
			                if($num_rows>0){
							
							while($dt1 = mysqli_fetch_array($dts1)){
									
								$emp_fac = $dt1['tb_empaque_fac'];
								$igv = $dt1['tb_compra_igvsub'];
								$preuni = $dt1['tb_compradetalle_preuni']*$igv;
								
								$can = $dt1['tb_compradetalle_can'];
								
								
															
								if($can>=$emp_fac){
									
									$preuni = $preuni / $emp_fac;
									
								}else{
									$preuni = $preuni;
								}
			
								
								$totprecos = $dt1['tb_compradetalle_can'] * $preuni;
								
							?>
			                        <tr>
			                           
			                            <td nowrap ><span style=""><?php echo $dt1['tb_producto_nom']?></span></td>
			                            <td nowrap ><?php echo $dt1['tb_marca_nom']?></td>
			                            <td nowrap ><?php echo $dt1['tb_categoria_nom']?></td>
			                            <td nowrap ><?php echo $dt1['tb_presentacion_nom']?></td>
			                            <td nowrap align="right"><?php echo $dt1['tb_compradetalle_can'] ?></td>
			                            <td nowrap align="right"><?php echo formato_money($preuni) ?></td>
			                            <td nowrap align="right"><?php echo formato_money($totprecos)?></td>
			                       </tr>
			                <?php
								$total_can += $dt1['tb_compradetalle_can'];
								$total_preuni += $preuni;
								$total_precos += $totprecos;
								}			               
								mysqli_free_result($dts1);
			                }
			                ?>
			                </tbody>   
			                <tr class="even">
			                  <td colspan="4">TOTAL</td>
			                  <td nowrap align="right"><?php echo $total_can?></td>
			                  <td nowrap align="right"><?php echo formato_money($total_preuni)?></td>
			                  <td nowrap align="right"><?php echo formato_money($total_precos)?></td>	
			                </tr>
					</table>
					</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>



<script type="text/javascript">

	$(function() {  
		$("#tabla_producto").DataTable( {
			"columnDefs": [
			{ "orderable": false, "targets": [] }
			],
			"searching": false,
			"order":[[0,"asc"]]

		});

	}); 

</script>  