<?php 
require('../conexion.php');

$datos=array();
if(isset($_POST['op'])){
    $op= $_POST['op'];
    $query=query("SELECT A.id 'MAP_ID', A.map_clave 'CLAVE', A.map_nombre 'MAP_NOMBRE', A.map_entrada 'MAP_INGRESO', A.map_clasificacion 'MAP_CLASIFICACION', A.map_unidad_medida 'MAP_UNIDAD', A.map_fecha_entrada 'MAP_ENTRADA', A.map_costo_unico 'MAP_COSTO_U', A.map_existencia 'MAP_EXISTENCIA', A.map_costo_final 'MAP_COSTO_F', A.map_stock_minimo 'MAP_STOCK_MIN', A.map_perecedero 'MAP_PRED', A.map_fecha_perecer 'MAP_FECHA_PRED', A.map_estatus 'MAP_STATUS' FROM materia_prima A WHERE A.map_clasificacion = '$op'");
    
    $reg=0;
    while($resultado=mysqli_fetch_assoc($query))
    {
    $datos[$reg]["MAP_ID"]=$resultado["MAP_ID"];
    $datos[$reg]["CLAVE"]=$resultado["CLAVE"];
    $datos[$reg]["MAP_NOMBRE"]=$resultado["MAP_NOMBRE"];
    $datos[$reg]["MAP_INGRESO"]=$resultado["MAP_INGRESO"];
    $datos[$reg]["MAP_CLASIFICACION"]=$resultado["MAP_CLASIFICACION"];
    $datos[$reg]["MAP_UNIDAD"]=$resultado["MAP_UNIDAD"];
    $datos[$reg]["MAP_ENTRADA"]=$resultado["MAP_ENTRADA"];
    $datos[$reg]["MAP_COSTO_U"]=$resultado["MAP_COSTO_U"];
    $datos[$reg]["MAP_EXISTENCIA"]=$resultado["MAP_EXISTENCIA"];
    $datos[$reg]["MAP_COSTO_F"]=$resultado["MAP_COSTO_F"];
    $datos[$reg]["MAP_STOCK_MIN"]=$resultado["MAP_STOCK_MIN"];
    $datos[$reg]["MAP_PRED"]=$resultado["MAP_PRED"];
    $datos[$reg]["MAP_FECHA_PRED"]=$resultado["MAP_FECHA_PRED"];
    $datos[$reg]["MAP_STATUS"]=$resultado["MAP_STATUS"];
    $reg++;
    }
}else{
    $datos="";
}

$salida = "";
if($datos != ""){ 
    if($query->num_rows > 0){
        $salida.="<table class='table' id='mat_tabla'>
            <thead style='background: #052659;'>
                <tr>
                    <th class='align-middle text-center' scope='col'>Clave</th>
                    <th class='align-middle text-center' scope='col'>Nombre</th>
                    <th class='align-middle text-center' scope='col'>Entrada</th>
                    <th class='align-middle text-center' scope='col'>Clasificacion</th>
                    <th class='align-middle text-center' scope='col'>Unidad M.</th>
                    <th class='align-middle text-center' scope='col'>Fecha Ent.</th>
                    <th class='align-middle text-center' scope='col'>Costo U.</th>
                    <th class='align-middle text-center' scope='col'>Existencia</th>
                    <th class='align-middle text-center' scope='col'>Costo F.</th>
                    <th class='align-middle text-center' scope='col'>Stock Min.</th>
                    <th class='align-middle text-center' scope='col'>Perecedero</th>
                    <th class='align-middle text-center' scope='col'>Fecha Per.</th>
                    <th class='align-middle text-center' scope='col'>Estatus</th>
                </tr>
            </thead>
            <tbody>";
        for($rr=0;$rr<count($datos);$rr++){
        $salida.="<tr>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Comensal--></label>
                            <input type='text' class='form-control input-clave' value='".$datos[$rr]['CLAVE']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Cantidad--></label>
                            <input type='text' class='form-control input-nombre' value='".$datos[$rr]['MAP_NOMBRE']."'>
                        </div>
                    </th>
                    
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Descuento--></label>
                            <input type='text' class='form-control input-entrada' value='".$datos[$rr]['MAP_INGRESO']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-clasificacion' value='".$datos[$rr]['MAP_CLASIFICACION']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-unidad-medida' value='".$datos[$rr]['MAP_UNIDAD']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-fecha-ent' value='".$datos[$rr]['MAP_ENTRADA']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-costo-unico' value='".$datos[$rr]['MAP_COSTO_U']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-existencia' value='".$datos[$rr]['MAP_EXISTENCIA']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-costo-final' value='".$datos[$rr]['MAP_COSTO_F']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-stock-minimo' value='".$datos[$rr]['MAP_STOCK_MIN']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-perecedero' value='".$datos[$rr]['MAP_PRED']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-fecha-predecedero' value='".$datos[$rr]['MAP_FECHA_PRED']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='text' class='form-control input-estatus' value='".$datos[$rr]['MAP_STATUS']."'>
                        </div>
                    </th>
                    <th>
                        <div class='input-group '>
                            <label class='form-label'><!--Precio--></label>
                            <input type='hidden' class='form-control input-id' value='".$datos[$rr]['MAP_ID']."'>
                        </div>
                    </th>
                </tr>";
            
        }
        $salida.="
            </tbody>
            </table>";
    }
}
    else{
        $salida.="<table class='table'>
            <thead style='background: linear-gradient(135deg, #05265926, #052659); color: #052659; border: 1px solid rgba(5, 38, 89, .3);'>
                <tr>
                    
                    <th class='align-middle text-center' scope='col'>Clave</th>
                    <th class='align-middle text-center' scope='col'>Nombre</th>
                    <th class='align-middle text-center' scope='col'>Entrada</th>
                    <th class='align-middle text-center' scope='col'>Clasificacion</th>
                    <th class='align-middle text-center' scope='col'>Unidad M.</th>
                    <th class='align-middle text-center' scope='col'>Fecha Ent.</th>
                    <th class='align-middle text-center' scope='col'>Costo U.</th>
                    <th class='align-middle text-center' scope='col'>Existencia</th>
                    <th class='align-middle text-center' scope='col'>Costo F.</th>
                    <th class='align-middle text-center' scope='col'>Stock Min.</th>
                    <th class='align-middle text-center' scope='col'>Perecedero</th>
                    <th class='align-middle text-center' scope='col'>Fecha Per.</th>
                    <th class='align-middle text-center' scope='col'>Estatus</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    
                </tr>
            </tbody>
            </table>";
    }

echo $salida;

?>