<?php 
// ini_set("display_errors",1);
session_start();
require_once ("../../config/Cado.php"); 
require_once ("../kardex/cKardex.php");
require_once ("../formatos/formato.php");
$oKardex = new cKardex();
$dts = $oKardex->mostrar_datos_kardex($_POST['idcat_oculto'],$_POST['cmb_fil_mar_id']);
$num_rows = mysqli_num_rows($dts);
?>
<br>
<input type="hidden" name="hdd_cat_sel_id" id="hdd_cat_sel_id" value="<?php echo $_POST['cat_id']?>" />
<div class="table-responsive">
<table id="tabla_producto_detalle" cellspacing="1" class="table table-bordered table-striped" >
    <thead>
        <tr>
            <th>CÓDIGO</th>
            <th>ARTÍCULO</th>
            <th>CATEGORIA</th>
            <th>MARCA</th>
            <th align="right">EMPAQUE</th>
            <th align="right">FACTOR</th>
            <th style="width: 12%" align="right">STOCK REFERENCIAL</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $contadorunits = 0;
       while ($dt = mysqli_fetch_array($dts)){
        $contadorunits++;
?>
            <tr class="even">
            <td align="center"><?php echo $dt['tb_presentacion_codbar']; ?></td>
            <td><?php echo $dt['tb_producto_nom'].' '.$dt['tb_presentacion_nom']; ?></td>           
            <td><?php echo $dt['tb_categoria_nom']; ?></td>
            <td><?php echo $dt['tb_marca_nom']; ?></td>
            <td align="right"> <?php echo $dt['tb_empaque_nom']; ?></td> 
            <td align="right"> <?php echo $dt['tb_catalogo_fac']; ?></td>
            <td id="tdstockref_<?php echo $contadorunits;?>" style="width: 200px" align="right"> 
			<input type="hidden" id="facfila_<?php echo $contadorunits;?>" value="<?php echo $dt['tb_catalogo_fac'];?>"> calculando...</td>         
            </tr>
<?php     
}
mysqli_free_result($dts);
?>
        </tbody>
        <input type="hidden" id="contadorxunits" value="<?php echo $contadorunits;?>">
    </table>
    
</div>	
	<br>
    <script>
        function calcularstockreferencial()
        {
            var totalstock = $("#xtotalx").text();
            var totalunis = parseInt($("#contadorxunits").val());
            for (i = 1; i <= totalunis; i++) { 
                var fac = $("#facfila_"+i).val();
                $("#tdstockref_"+i).text(totalstock/fac)
            }
        }
    </script>