Пример #1
0
function upd_inventario()
{
    $fun = new funciones();
    $msg = new messages();
    $response = new StdClass();
    $res = false;
    /*recibimos variables*/
    $inv = $_POST["inv"];
    $oin = $_POST["oin"];
    $id = $_POST["id"];
    //traemos inventario restante y lo recalculamos
    $i_r = $fun->get_custom("SELECT in_mt_restante FROM tbl_inventario WHERE in_id=" . $id . ";");
    $inv_res = $oin - $inv - $i_r;
    if ($inv_res < 0) {
        $inv_res = $inv_res * -1;
    }
    $tbl = "inventario";
    $cambios = 'in_mt_cubico = ' . $inv . ', in_mt_restante = ' . $inv_res . ' ';
    $where = 'in_id = ' . $id;
    $res = $fun->actualizar($tbl, $cambios, $where);
    #tenemos que actualizar en control_inventarios
    #traemos inventario total del lote
    $inv_array = $fun->get_array("SELECT CI.ci_id, CI.ci_vol_act FROM tbl_control_inventarios CI \n\t\t\t\t\t\t\t\t  INNER JOIN tbl_inventario I ON I.in_lote = CI.ci_in_lote\n\t\t\t\t\t\t\t\t  WHERE I.in_id =" . $id . ";");
    $ni_r = $oin + $inv_array[0]['ci_vol_act'] - $inv;
    #actualizamos
    $tbl = "control_inventarios";
    $cambios = 'ci_vol_act = ' . $ni_r;
    $where = 'ci_id = ' . $inv_array[0]['ci_id'];
    $res2 = $fun->actualizar($tbl, $cambios, $where);
    if ($res && $res2) {
        $res = true;
        $mes = $msg->get_msg("e004");
    } else {
        $res = false;
        $mes = $msg->get_msg("e019");
    }
    $response->res = $res;
    $response->mes = $mes;
    echo json_encode($response);
}
Пример #2
0
function add_finca()
{
    $fun = new funciones();
    $msg = new messages();
    $response = new StdClass();
    /*recibimos variables*/
    $cod = $_POST["cod"];
    $nombre = "";
    if ($cod == "") {
        $res = false;
        $mes = $msg->get_msg("e005");
    } else {
        $con = new con();
        $con->connect();
        /* verificamos que exista la finca en la matriz importada desde excel*/
        $res_finca = $fun->existe("matriz_ica", "codfinca", $cod);
        /* verificamos que no esté registrada en la tabla de fincas*/
        $res_existe = $fun->existe("fincas", "fi_codigo", $cod);
        if ($res_finca) {
            if (!$res_existe) {
                /* subnucleos */
                $qry_sn = 'SELECT DISTINCT sn_id, municipio FROM `tbl_matriz_ica` 
							INNER JOIN tbl_subnucleos ON sn_subnucleo = municipio 
							WHERE codfinca = "' . $cod . '"';
                //echo $qry_sn;
                $sn_id = $fun->get_custom($qry_sn);
                /* ingresamos datos de la finca */
                $qry = "INSERT INTO tbl_fincas (fi_codigo, fi_sn_id, fi_created, fi_estado)\n\t\t\t\t\t\t\tVALUES ('" . $cod . "'," . $sn_id . "," . $_SESSION["ses_id"] . ",1);";
                $resp = mysql_query($qry);
                if (!$resp) {
                    $res = false;
                    $mes = $msg->get_msg("e003");
                } else {
                    //Si la insercción fué correcta, traemos el id de la finca y lo asociaremos a cada lote que se autorizó
                    $qry_fi = "SELECT fi_id, fi_codigo FROM tbl_fincas WHERE fi_codigo='" . $cod . "' ORDER BY fi_id DESC LIMIT 1;";
                    $res_fi = mysql_query($qry_fi);
                    if ($row_fi = mysql_fetch_assoc($res_fi)) {
                        //echo "<br> ultima finca: ".$row_fi['fi_id']."<br>";
                        //echo "<br> query finca: ".$qry_fi."<br>";
                        //validamos integridad de los lotes
                        if (isset($_POST['arr_lotes'])) {
                            //hacemos insercción por cada lote con el codfinca
                            foreach ($_POST['arr_lotes'] as $key => $value) {
                                $qry_lotes = 'INSERT INTO tbl_lotes_autorizados (la_fi_id, la_idlote, la_created, la_estado)
													VALUES(' . $row_fi['fi_id'] . ', "' . $value . '", ' . $_SESSION["ses_id"] . ',1);';
                                $resp_lotes = mysql_query($qry_lotes);
                            }
                            if (!$resp_lotes) {
                                $res = false;
                                $mes = $msg->get_msg("e003");
                            } else {
                                $res = true;
                                $mes = $msg->get_msg("e004");
                            }
                        } else {
                            $res = true;
                            $mes = $msg->get_msg("e004");
                        }
                    } else {
                        $res = false;
                        $mes = $msg->get_msg("e003");
                    }
                }
            } else {
                $res = false;
                $mes = $msg->get_msg("e007");
            }
        } else {
            $res = false;
            $mes = $msg->get_msg("e006");
        }
    }
    $response->res = $res;
    $response->mes = $mes;
    echo json_encode($response);
    $con->disconnect();
}