Viewing File: /home/cienp/public_html/portal/sql_almx_entr.php
<?
$dt_atua = date("Y-m-d");
echo ".";
switch ($_POST[opc]){
case "ins":
require "$this->include_dir/conecta.php";
$s_id_prdt = protecao($_POST[id_prdt],'inteiro');
$s_id_setr = protecao($_POST[id_setr],'inteiro');
$s_id_resp = protecao($_POST[id_resp],'inteiro');
$s_id_marc = protecao($_POST[id_marc],'inteiro');
$s_id_cond = protecao($_POST[id_cond],'inteiro');
$s_id_locl = protecao($_POST[id_nivl_4],'inteiro');
$s_dt_entr = protecao($_POST[dt_entr],'data');
$s_de_obsr = protecao($_POST[de_obsr]);
$s_nu_nota = protecao($_POST[nu_nota]);
$s_nu_qtde = protecao($_POST[nu_qtde],'decimal');
$s_vl_unit = protecao($_POST[vl_unit],'decimal');
$s_nu_qtde = str_replace('.','',$s_nu_qtde);
$s_nu_qtde = str_replace(',','.',$s_nu_qtde);
$s_vl_unit = str_replace('.','',$s_vl_unit);
$s_vl_unit = str_replace(',','.',$s_vl_unit);
if ($s_dt_entr != '') {
$d1 = explode('/', $s_dt_entr);
$dt_entr = $d1[2]."-".$d1[1]."-".$d1[0];
}
$sqlj = "SELECT nu_estq ";
$sqlj .= "FROM ".$pref_tabl."almx_prdt ";
$sqlj .= "WHERE id_prdt = $s_id_prdt ";
$sqlj .= "LIMIT 1";
#echo $sqlj."<br>";
$resj = mysqli_query($conn, $sqlj);
if (mysqli_num_rows($resj) > 0) {
$linhaj = mysqli_fetch_array($resj);
$sql = "INSERT INTO ".$pref_tabl."almx_entr ";
$sql .= "(id_prdt, id_setr, id_resp, id_marc, id_cond, id_locl, dt_entr, ";
$sql .= "de_obsr, nu_nota, nu_qtde, vl_unit, dt_cads, id_cads) ";
$sql .= "VALUES ('$s_id_prdt', '$s_id_setr', '$s_id_resp', '$s_id_marc', '$s_id_cond', '$s_id_locl', '$dt_entr', ";
$sql .= "'$s_de_obsr', '$s_nu_nota', '$s_nu_qtde', '$s_vl_unit', '$dt_atua', $linhau[id_user]) ";
#echo $sql;
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=ins_almx_entr&certo=S";
$nu_estq = $linhaj[nu_estq] + $s_nu_qtde;
// faz o update no estoque
$sqlee = "UPDATE ".$pref_tabl."almx_prdt ";
$sqlee .= "SET nu_estq = '$nu_estq', ";
$sqlee .= "vl_prdt = '$s_vl_unit' ";
$sqlee .= "WHERE id_prdt = '$s_id_prdt' ";
$sqlee .= "LIMIT 1";
$resee = mysqli_query($conn, $sqlee);
if (!$resee) {
$onde = "index1.php?pg=ins_almx_entr&certo=A";
}
} else {
$onde = "index1.php?pg=ins_almx_entr&certo=N";
}
} else {
$onde = "index1.php?pg=ins_almx_entr&certo=N";
}
break;
case "alt":
require "$this->include_dir/conecta.php";
$s_id_entr = protecao($_POST[id_entr],'inteiro');
$s_id_setr = protecao($_POST[id_setr],'inteiro');
$s_id_resp = protecao($_POST[id_resp],'inteiro');
$s_id_marc = protecao($_POST[id_marc],'inteiro');
$s_id_cond = protecao($_POST[id_cond],'inteiro');
$s_id_locl = protecao($_POST[id_nivl_4],'inteiro');
$s_dt_entr = protecao($_POST[dt_entr],'data');
$s_de_obsr = protecao($_POST[de_obsr]);
$s_nu_nota = protecao($_POST[nu_nota]);
if ($s_dt_entr != '') {
$d1 = explode('/', $s_dt_entr);
$dt_entr = $d1[2]."-".$d1[1]."-".$d1[0];
}
$sql = "UPDATE ".$pref_tabl."almx_entr ";
$sql .= "SET id_setr = '$s_id_setr', ";
$sql .= "id_resp = '$s_id_resp', ";
$sql .= "id_marc = '$s_id_marc', ";
$sql .= "id_cond = '$s_id_cond', ";
$sql .= "id_locl = '$s_id_locl', ";
$sql .= "dt_entr = '$dt_entr', ";
$sql .= "de_obsr = '$s_de_obsr', ";
$sql .= "nu_nota = '$s_nu_nota', ";
$sql .= "id_altr = '$linhau[id_user]', ";
$sql .= "dt_altr = '$dt_atua' ";
$sql .= "WHERE id_entr = '$s_id_entr' ";
$sql .= "LIMIT 1";
//echo $sql.'<br>';
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=alt_almx_entr&certo=S";
} else
$onde = "index1.php?pg=alt_almx_entr&certo=N";
break;
case "exc":
require "$this->include_dir/conecta.php";
$s_id_entr = protecao($_POST[id_entr],'inteiro');
if ($s_id_entr > 0) {
$sqlfo = "SELECT nu_qtde, id_prdt ";
$sqlfo .= "FROM ".$pref_tabl."almx_entr ";
$sqlfo .= "WHERE id_entr = '$s_id_entr' ";
$sqlfo .= "LIMIT 1 ";
$resfo = mysqli_query($conn, $sqlfo);
if (mysqli_num_rows($resfo) > 0) {
$linhafo = mysqli_fetch_array($resfo);
$sqlj = "SELECT nu_estq ";
$sqlj .= "FROM ".$pref_tabl."almx_prdt ";
$sqlj .= "WHERE id_prdt = '$linhafo[id_prdt]' ";
$sqlj .= "LIMIT 1";
#echo $sqlj."<br>";
$resj = mysqli_query($conn, $sqlj);
if (mysqli_num_rows($resj) > 0) {
$linhaj = mysqli_fetch_array($resj);
if ($linhafo[nu_qtde] <= $linhaj[nu_estq]) {
$sql = "DELETE FROM ".$pref_tabl."almx_entr ";
$sql .= "WHERE id_entr = '$s_id_entr' ";
$sql .= "LIMIT 1";
$res = mysqli_query($conn, $sql);
if ($res) {
$onde = "index1.php?pg=res_almx_entr&certo=X";
} else {
$onde = "index1.php?pg=res_almx_entr&certo=N";
}
} else {
$onde = "index1.php?pg=res_almx_entr&certo=Q";
}
}
} else {
$onde = "index1.php?pg=res_almx_entr&certo=N";
}
} else {
$onde = "index1.php?pg=res_almx_entr&certo=N";
}
break;
}
?>
<form name="retorna" method="post" action="">
<input type="hidden" name="id_entr" id="id_entr" value="<?=$_POST[id_entr]?>">
<input name="passa" type="hidden" id="passa" value="yes">
<input type="hidden" name="v_id_prdt" id="v_id_prdt" value="<?=$_POST[v_id_prdt]?>">
<input type="hidden" name="v_id_setr" id="v_id_setr" value="<?=$_POST[v_id_setr]?>">
<input type="hidden" name="v_id_entr" id="v_id_entr" value="<?=$_POST[v_id_entr]?>">
<input type="hidden" name="v_dt_inic" id="v_dt_inic" value="<?=$_POST[v_dt_inic]?>">
<input type="hidden" name="v_dt_finl" id="v_dt_finl" value="<?=$_POST[v_dt_finl]?>">
</form>
<?
echo "<SCRIPT LANGUAGE=javascript> \n";
echo "document.retorna.action = '$onde'; \n";
echo "document.retorna.submit(); \n";
echo "</script>";
?>
Back to Directory
File Manager