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

// cambio en los estatus
$clave_materia_prima="";
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.id = '$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'>
                <label class='form-label'>Clave de Materia prima</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='hidden' class='form-control' value='".$datos['MAP_ID']."' id='map_id_edt' name='map_id_edt'>
                    
                    <input type='text' class='form-control' value='".$datos['CLAVE']."' id='map_clave_edt' name='map_clave_edt' disabled>
                </div>
            </div>
            <div class='col-md-8'>
                <label class='form-label'>Nombre de materia prima</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='".$datos['MAP_NOMBRE']."' id='map_nombre_edt' name='map_nombre_edt' required>
                </div>
            </div>
        </div>
        <div class='row'>
            <div class='col-md-4'>
                <label class='form-label'> Cantidad que ingresa</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='".$datos['MAP_INGRESO']."' id='map_ingreso_edt' name='map_ingreso_edt' pattern='\d+(\.\d{1,2})?' required>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>Clasificacion</label>
                <div class='input-group input-group-outline mb-2'>
                    
                    <select class='form-control' id='map_clasificacion_edt' name='map_clasificacion_edt'>";
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL CARNE'){
                        $salida.="
                        <option value='CENTRAL CARNE' selected>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'CERVEZA CORONA'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA' selected>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL FRUTA'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA' selected>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL HIERBAS'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS' selected>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL SEMILLAS'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS' selected>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL VERDURAS'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS' selected>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    
                    if ($datos['MAP_CLASIFICACION'] == 'CENTRAL POLLERIA'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA' selected>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'TIENDA'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA' selected>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'TORTILLERIA'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA' selected>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</option>";
                    }
                    if ($datos['MAP_CLASIFICACION'] == 'GARRAFON'){
                        $salida.="
                        <option value='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON' selected>GARRAFON</option>";
                    }
                    $salida.=  "
                    </select>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>Unidad de medida</label>
                <div class='input-group input-group-outline mb-2'>
                    
                    <input type='text' class='form-control' value='".$datos['MAP_UNIDAD']."' id='map_unidad_edt' name='map_unidad_edt' pattern='[\w\s.,!?\-]+' required>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>fecha de entrada</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='date' class='form-control' value='".$datos['MAP_ENTRADA']."' id='map_entrada_edt' name='map_entrada_edt'>
                </div>
            </div>
        
            <div class='col-md-4'>
                <label class='form-label'>Costo unico</label>
                <div class='input-group input-group-outline mb-2'>
                    
                    <input type='text' class='form-control' value='". $datos['MAP_COSTO_U']."' id='map_costo_u_edt' name='map_costo_u_edt' pattern='\d+(\.\d{1,2})?' required>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>Existencia</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='". $datos['MAP_EXISTENCIA']."' id='map_existencia_edt' name='map_existencia_edt' disabled >
                </div>
            </div>
        
            <div class='col-md-4'>
                <label class='form-label'>Costo final</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='".$datos['MAP_COSTO_F']."' id='map_costo_final_edt' name='map_costo_final_edt' disabled>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>stock minimo</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='".$datos['MAP_STOCK_MIN']."' id='map_stock_minimo_edt' name='map_stock_minimo_edt' pattern='\d+(\.\d{1,4})?' required>
                </div>
            </div>
        
            <div class='col-md-4'>
                <label class='form-label'>Es perecedero?</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='text' class='form-control' value='".$datos['MAP_PRED']."' id='map_predecedero_edt' name='map_predecedero_edt'>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>Fecha de perecer</label>
                <div class='input-group input-group-outline mb-2'>
                    <input type='date' class='form-control' value='".$datos['MAP_FECHA_PRED']."' id='map_fecha_predecer_edt' name='map_fecha_predecer_edt'>
                </div>
            </div>
            <div class='col-md-4'>
                <label class='form-label'>Estatus</label>
                <div class='input-group input-group-outline mb-2'>
                    <select class='form-control' id='map_estatus_edt' name='map_estatus_edt'>";
                    if($datos['MAP_STATUS'] == "ALTA" || $datos['MAP_STATUS'] == "Alta"|| $datos['MAP_STATUS'] == "alta"){
                        $salida.="
                        <option value='Alta' selected>Alta</option>
                        <option value='Baja'>Baja</option>
                        <option value='Caducado'>Caducado</option>";
                    }
                    if($datos['MAP_STATUS'] == "BAJA" || $datos['MAP_STATUS'] == "Baja" || $datos['MAP_STATUS'] == "baja"){
                        $salida.="
                        <option value='Alta'>Alta</option>
                        <option value='Baja'  selected>Baja</option>
                        <option value='Caducado'>Caducado</option>";
                    }
                    if($datos['MAP_STATUS'] == "CADUCADO" || $datos['MAP_STATUS'] == "Caducado" || $datos['MAP_STATUS'] == "caducado"){
                        $salida.="
                        <option value='Alta'>Alta</option>
                        <option value='Baja'>Baja</option>
                        <option value='Caducado' selected>Caducado</option>";
                    }
                    $salida.="
                    </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_edt' 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_edt' 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='CENTRAL CARNE'>CENTRAL CARNE</option>
                        <option value='CERVEZA CORONA'>CERVEZA CORONA</option>
                        <option value='CENTRAL FRUTA'>CENTRAL FRUTA</option>
                        <option value='CENTRAL HIERBAS'>CENTRAL HIERBAS</option>
                        <option value='CENTRAL SEMILLAS'>CENTRAL SEMILLAS</option>
                        <option value='CENTRAL VERDURAS'>CENTRAL VERDURAS</option>
                        <option value='CENTRAL POLLERIA'>CENTRAL POLLERIA</option>
                        <option value='TIENDA'>TIENDA</option>
                        <option value='TORTILLERIA'>TORTILLERIA</option>
                        <option value='GARRAFON'>GARRAFON</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_edt' 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_edt' 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='map_costo_final_edt' 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' id=''>Actualizar</button>
                </div>
            </div>
        </div>";
} 
echo $salida;
?>