<?php
require('conexion.php');
// cambio en los estatus
if(isset($_POST['clave_materia'])){
    $clave_materia_prima= $_POST['clave_materia'];
    $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_clave = '$clave_materia_prima'");
    $datos=mysqli_fetch_assoc($query);
}else{
    $datos="";
}

$salida = "";

if($datos != ""){
    if($query->num_rows > 0){
        $salida.="<div class='row'>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <input type='hidden' class='form-control' id='clave_materia_prima' value='".$datos['MAP_ID']."' id='map_id' name='map_id'>
                    <label class='form-label'><!--Clave de Materia prima--></label>
                    <input type='text' class='form-control' id='clave_materia_prima' value='".$datos['CLAVE']."' id='map_clave' name='map_clave' disabled>
                </div>
            </div>
            <div class='col-md-8'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Nombre de materia prima--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_NOMBRE']."' id='map_nombre' name='map_nombre'>
                </div>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label' ><!--Cantidad que ingresa--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_INGRESO']."' id='map_ingreso' name='map_ingreso'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <select class='form-control' id='map_clasificacion' name='map_clasificacion'>
                        <option value='".$datos['MAP_CLASIFICACION']."'selected>". $datos['MAP_CLASIFICACION']."</option>
                        <option value='1'>1</option>
                        <option value='2'>2</option>
                        <option value='3'>3</option>
                    </select>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Unidad de medida--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_UNIDAD']."' id='map_unidad' name='map_unidad'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--fecha de entrada--></label>
                    <input type='date' class='form-control' value='".$datos['MAP_ENTRADA']."' id='map_entrada' name='map_entrada'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Costo unico--></label>
                    <input type='text' class='form-control' value='". $datos['MAP_COSTO_U']."' id='map_costo_u' name='map_costo_u'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Existencia--></label>
                    <input type='text' class='form-control' value='". $datos['MAP_EXISTENCIA']."' id='map_existencia' name='map_existencia'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Costo final--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_COSTO_F']."' id='costo_final' name='costo_final'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--stock minimo--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_STOCK_MIN']."' id='map_stock_minimo' name='map_stock_minimo'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Es perecedero?--></label>
                    <input type='text' class='form-control' value='".$datos['MAP_PRED']."' id='map_predecedero' name='map_predecedero'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'><!--Fecha de perecer--></label>
                    <input type='date' class='form-control' value='".$datos['MAP_FECHA_PRED']."' id='map_fecha_predecer' name='map_fecha_predecer'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <select class='form-control' id='map_estatus' name='map_estatus'>
                        <option value='".$datos['MAP_STATUS']."'> ".$datos['MAP_STATUS']." </option>
                        <option value='ALta'>ALta</option>
                        <option value='Baja'>Baja</option>
                        <option value='Caducado'>Caducado</option>
                    </select>
                </div>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-4'>
                <div class='text-center'>
                    <button type='submit' class='btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0' >Actualizar</button>
                </div>
            </div>
        </div>";
    }
}else{
    $salida.="<div class='row'>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                <input type='hidden' class='form-control' id='clave_materia_prima' id='map_id' name='map_id' disabled>
                    <label class='form-label'><!--Clave de Materia prima--></label>
                    <input type='text' class='form-control' id='clave_materia_prima' name='clave_materia_prima' disabled>
                </div>
            </div>
            <div class='col-md-8'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Nombre de materia prima</label>
                    <input type='text' class='form-control' id='map_nombre' name='map_nombre'>
                </div>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Cantidad que ingresa</label>
                    <input type='text' class='form-control' id='map_ingreso' name='map_ingreso'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <select class='form-control' id='map_clasificacion' name='map_clasificacion'>
                        <option selected>Clasificacion</option>
                        <option value='1'>1</option>
                        <option value='2'>2</option>
                        <option value='3'>3</option>
                    </select>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Unidad de medida</label>
                    <input type='text' class='form-control' id='map_unidad' name='map_unidad'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>fecha de entrada</label>
                    <input type='date' class='form-control' id='map_entrada' name='map_entrada'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Costo unico</label>
                    <input type='text' class='form-control' id='map_costo_u' name='map_costo_u'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Existencia</label>
                    <input type='text' class='form-control' id='map_existencia' name='map_existencia'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Costo final</label>
                    <input type='text' class='form-control' id='costo_final' name='costo_final'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>stock minimo</label>
                    <input type='text' class='form-control' id='map_stock_minimo' name='map_stock_minimo'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Es perecedero?</label>
                    <input type='text' class='form-control' id='map_predecedero' name='map_predecedero'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <label class='form-label'>Fecha de perecer</label>
                    <input type='date' class='form-control' id='map_fecha_predecer' name='map_fecha_predecer'>
                </div>
            </div>
            <div class='col-md-4'>
                <div class='input-group input-group-outline mb-3'>
                    <select class='form-control' id='map_estatus' name='map_estatus'>
                        <option selected> Estatus </option>
                        <option value='Alta'>Alta</option>
                        <option value='Baja'>Baja</option>
                        <option value='Caducado'>Caducado</option>
                    </select>
                </div>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-4'>
                <div class='text-center'>
                    <button type='button' class='btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0'>Actualizar</button>
                </div>
            </div>
        </div>";
} 
echo $salida;
?>