BOa tarde pessoal eu tenho 1 controle de estoque, que segue o código abaixo e eu gostaria de fazer 1 modificação colocando assim Coca cola Preço de custo = 1,00 Preço de Venda = 1,00 Lucro = 0,50 E depois me mostrar o lucro total de todos os produtos veja a imagem abaixo <? session_start(); ?>
<html>
<head>
<title>SIG - Módulo Controle de Estoque</title>
<style type="text/css">
body {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.bd {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.tbl {
background-color: #FFFFFF;
}
a:link {
color: #FF0000;
font-family: Arial;
font-size: 12px;
}
a:active {
color: #0000FF;
font-family: Arial;
font-size: 12px;
}
a:visited {
color: #800080;
font-family: Arial;
font-size: 12px;
}
.hr {
background-color: #808080;
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:link {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:active {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:visited {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
.dr {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.sr {
background-color: #EEEEEE;
color: #000000;
font-family: Arial;
font-size: 12px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<style>
margin:0px;
</style>
<table class="bd" width="100%"><tr><td bgcolor="#000000" style="backgroundColor:#000000"><table width="601" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td><img src="../Imagens/Logo_r1_c1.jpg" width="58" height="94"></td>
<td><img src="../Imagens/Logo_r1_c2.jpg" width="88" height="94"></td>
<td><img src="../Imagens/Logo_r1_c3.jpg" width="86" height="94"></td>
<td><img src="../Imagens/Logo_r1_c4.jpg" width="82" height="94"></td>
<td><img src="../Imagens/Logo_r1_c5.jpg" width="85" height="94"></td>
<td><img src="../Imagens/Logo_r1_c6.jpg" width="100" height="94"></td>
<td><img src="../Imagens/Logo_r1_c7.jpg" width="102" height="94"></td>
</tr>
</table></td></tr></table>
<?
if (!login()) exit;
?>
<div style="float: right">[Usuário Logado: <font color="#003366"><b><? echo $_SESSION['usuarioLogado']; ?></b>]</font> <a href="produtos.php?a=logout">[ Sair do Sistema ]</a></div>
<br>
<?
$conn = connect();
$showrecs = 100;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
$wholeonly = false;
if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
$sql = @$_POST["sql"];
switch ($sql) {
case "insert":
sql_insert();
break;
case "update":
sql_update();
break;
case "delete":
sql_delete();
break;
}
switch ($a) {
case "add":
addrec();
break;
case "view":
viewrec($recid);
break;
case "edit":
editrec($recid);
break;
case "del":
deleterec($recid);
break;
default:
select();
break;
}
if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;
mysql_close($conn);
?>
<table class="bd" width="100%" style="backgroundColor:#000000"><tr>
<td bgcolor="#000000" style="backgroundColor:#000000;color:#FFFFFF;"><strong>SIG - Sistema Integrado de Gerenciamento - Por: Renato X. </strong></td>
</tr></table>
</body>
</html>
<? function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;
if ($a == "reset") {
$filter = "";
$filterfield = "";
$wholeonly = "";
$order = "";
$ordtype = "";
}
$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {mysql_data_seek($res, $startrec);}
$reccount = min($showrecs * $page, $count);
$fields = array(
"idPRODUTOS" => "ID Produto",
"PRODUTO" => "Produto",
"QUANTIDADECOMPRADA" => "Quantidade Comprada",
"QUANTIDADEEMESTOQUE" => "Quantidade em Estoque",
"QUANTIDADEVENDIDA" => "Quantidade Vendida",
"VALOR" => "Valor Unitário",
"VALORTOTALVENDIDO" => "Valor Total Vendas");
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Tabela: produtos</td></tr>
<tr><td>Exibindo Registros <? echo $startrec + 1 ?> - <? echo $reccount ?> de <? echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="produtos.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Busca Personalizada</b> </td>
<td><input type="text" name="filter" value="<? echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Todos Campos</option>
<?
reset($fields);
foreach($fields as $val => $caption) {
if ($val == $filterfield) {$selstr = " selected"; } else {$selstr = ""; }
?>
<option value="<? echo $val ?>"<? echo $selstr ?>><? echo htmlspecialchars($caption) ?></option>
<? } ?>
</select></td>
<td><input type="checkbox" name="wholeonly"<? echo $checkstr ?>>Sintaxe Completa Valor Total Vendas Mês: <b><font size="+3">R$
<?
$conn = mysql_connect("localhost", "sig", "teste");
mysql_select_db("sig");
$totalDias = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
$proximoDia = date("Y-m-d",mktime(0,0,0,date("m"),date("d")+1,date("Y")));
$sqlTotalVendido = "SELECT SUM(VALOR) as total FROM relatoriovendas WHERE DATAVENDA BETWEEN ('".date('Y-m')."-01') AND ('".$proximoDia."')";
mysql_query($sqlTotalVendido);
$sqlTotalVendido = mysql_query($sqlTotalVendido);
$totalVendidos = mysql_fetch_array($sqlTotalVendido);
?>
<? echo $totalVendidos['total']; ?></font></b></td>
</td></tr>
<tr>
<td></td>
<td><input type="submit" name="action" value="Buscar"></td>
<td><a href="produtos.php?a=reset">Limpar Busca</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<? showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<?
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="hr"><a class="hr" href="produtos.php?order=<? echo $val ?>&type=<? echo $ordtypestr ?>"><? echo htmlspecialchars($caption) ?></a></td>
<? } ?>
<td class="hr"> </td>
<td class="hr"> </td>
<td class="hr"> </td>
</tr>
<?
for ($i = $startrec; $i < $reccount; $i++)
{
$row = mysql_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr onClick="window.location.href='produtos.php?a=edit&recid=<? echo $i ?>';" onMouseOver="this.style.cursor='pointer';">
<?
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="<? echo $style ?>"><? echo htmlspecialchars($row[$val]) ?></td>
<? } ?>
<td class="<? echo $style ?>"><a href="produtos.php?a=view&recid=<? echo $i ?>">Visualizar</a></td>
<td class="<? echo $style ?>"><a href="produtos.php?a=edit&recid=<? echo $i ?>">Editar</a></td>
<td class="<? echo $style ?>"><a href="produtos.php?a=del&recid=<? echo $i ?>">Apagar</a></td>
</tr>
<?
}
mysql_free_result($res);
?>
</table>
<br>
<? showpagenav($page, $pagecount); ?>
<? } ?>
<? function login()
{
global $_POST;
global $_SESSION;
global $_GET;
if (isset($_GET["a"]) && ($_GET["a"] == 'logout')) $_SESSION["logged_in"] = false;
if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
if (!$_SESSION["logged_in"]) {
$login = "";
$password = "";
if (isset($_POST["login"])) $login = @$_POST["login"];
if (isset($_POST["password"])) $password = @$_POST["password"];
$_SESSION['usuarioLogado'] = $login;
if (($login != "") && ($password != "")) {
$conn = mysql_connect("localhost", "sig", "teste");
mysql_select_db("sig");
$sql = "select SENHA from `usuarios` where USERNAME = '" .$login ."'";
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res) or $row = array(0 => "");;
if (isset($row)) reset($row);
if (isset($password) && ($password == trim(current($row)))) {
$_SESSION["logged_in"] = true;
}
else {
?>
<p><b><font color="-1">Senha ou Usuário Invalido</font></b></p>
<? } } }if (isset($_SESSION["logged_in"]) && (!$_SESSION["logged_in"])) { ?>
<form action="produtos.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td>Usuário</td>
<td><input type="text" name="login" value="<? echo $login ?>"></td>
</tr>
<tr>
<td>Senha</td>
<td><input type="password" name="password" value="<? echo $password ?>"></td>
</tr>
<tr>
<td><input type="submit" name="action" value="Logar"></td>
</tr>
</table>
</form>
<?
}
if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
return $_SESSION["logged_in"];
} ?>
<? function showrow($row)
{
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><? echo htmlspecialchars("idPRODUTOS")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["idPRODUTOS"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("PRODUTO")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["PRODUTO"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADECOMPRADA")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["QUANTIDADECOMPRADA"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADEEMESTOQUE")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["QUANTIDADEEMESTOQUE"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADEVENDIDA")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["QUANTIDADEVENDIDA"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("VALOR")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["VALOR"]) ?></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("VALORTOTALVENDIDO")." " ?></td>
<td class="dr"><? echo htmlspecialchars($row["VALORTOTALVENDIDO"]) ?></td>
</tr>
</table>
<? } ?>
<? function showroweditor($row)
{
global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><? echo htmlspecialchars("idPRODUTOS")." " ?></td>
<td class="dr"><input type="text" name="idPRODUTOS" readonly="readonly" value="<? echo str_replace('"', '"', trim($row["idPRODUTOS"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("PRODUTO")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="PRODUTO" maxlength="255"><? echo str_replace('"', '"', trim($row["PRODUTO"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADECOMPRADA")." " ?></td>
<td class="dr"><input type="text" name="QUANTIDADECOMPRADA" onBlur="document.getElementById('QUANTIDADEEMESTOQUE').value= document.getElementById('QUANTIDADECOMPRADA').value - document.getElementById('QUANTIDADEVENDIDA').value;" value="<? echo str_replace('"', '"', trim($row["QUANTIDADECOMPRADA"])) ?>"></td>
</tr>
<script>
function vendaProduto(){
if(document.getElementById('QUANTIDADEVENDIDA').value != document.getElementById('QUANTIDADECOMPRADA').value){
var soma = document.getElementById('QUANTIDADEVENDIDA').value++;
document.getElementById('QUANTIDADEVENDIDA').value = soma+1;
document.getElementById('QUANTIDADEEMESTOQUE').value = document.getElementById('QUANTIDADECOMPRADA').value - document.getElementById('QUANTIDADEVENDIDA').value;
var somaQuantidadeVendida = document.getElementById('edtQuantidadeVendida').value++;
document.getElementById('edtQuantidadeVendida').value = somaQuantidadeVendida+1;
document.getElementById('edtValorVendido').value = document.getElementById('edtQuantidadeVendida').value * document.getElementById('VALOR').value;
valorTotalVendido();
}else{
alert('Erro: A quantidade de produtos em estoque se esgotou. Não é possivel efetuar a venda!');
}
}
function vendaProdutoB(){
var v1 = document.getElementById('QUANTIDADEVENDIDA').value;
var v2 = parseInt(document.getElementById('QUANTIDADECOMPRADA').value)+1;
if(parseInt(v1) < parseInt(v2)){
var soma = document.getElementById('QUANTIDADEVENDIDA').value++;
document.getElementById('QUANTIDADEVENDIDA').value = soma;
document.getElementById('QUANTIDADEEMESTOQUE').value = document.getElementById('QUANTIDADECOMPRADA').value - document.getElementById('QUANTIDADEVENDIDA').value;
var somaQuantidadeVendida = document.getElementById('edtQuantidadeVendida').value++;
document.getElementById('edtQuantidadeVendida').value = somaQuantidadeVendida+1;
document.getElementById('edtValorVendido').value = document.getElementById('edtQuantidadeVendida').value * document.getElementById('VALOR').value;
valorTotalVendido();
}else{
alert('Erro: A quantidade de produtos em estoque se esgotou. Não é possivel efetuar a venda!');
document.getElementById('QUANTIDADEVENDIDA').value = document.getElementById('QUANTIDADECOMPRADA').value;
}
}
function devolveProduto(){
if(document.getElementById('QUANTIDADEVENDIDA').value > 0){
document.getElementById('QUANTIDADEVENDIDA').value = (document.getElementById('QUANTIDADEVENDIDA').value)-1;
document.getElementById('QUANTIDADEEMESTOQUE').value= document.getElementById('QUANTIDADECOMPRADA').value - document.getElementById('QUANTIDADEVENDIDA').value;
document.getElementById('edtQuantidadeVendida').value = document.getElementById('edtQuantidadeVendida').value - 1;
document.getElementById('edtValorVendido').value = document.getElementById('edtQuantidadeVendida').value * document.getElementById('VALOR').value;
valorTotalVendido();
}else{
alert('Erro: A quantidade de produtos em estoque é igual à quantidade de produtos comprados.');
}
}
function valorTotalVendido(){
var soma = document.getElementById('VALOR').value * document.getElementById('QUANTIDADEVENDIDA').value;
soma = ''+soma;
document.getElementById('VALORTOTALVENDIDO').value = soma.substr(0,5);
}
</script>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADEEMESTOQUE")." " ?></td>
<td class="dr"><input type="text" name="QUANTIDADEEMESTOQUE" readonly="readonly" value="<? echo str_replace('"', '"', trim($row["QUANTIDADEEMESTOQUE"])) ?>"></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("QUANTIDADEVENDIDA")." " ?><input type="hidden" name="edtQuantidadeVendida"><input type="hidden" name="edtValorVendido"></td>
<td class="dr"><table cellpadding="0" cellspacing="0"><tr><td><input type="text" onBlur="vendaProdutoB();" name="QUANTIDADEVENDIDA" value="<? echo str_replace('"', '"', trim($row["QUANTIDADEVENDIDA"])) ?>"></td><td><img src="../Imagens/adiciona.jpg" align="right" onClick="vendaProduto();" style="cursor:pointer"></td><td><img src="../Imagens/remove.jpg" align="right" onClick="devolveProduto();" style="cursor:pointer"></td></tr></table></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("VALOR")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="VALOR" maxlength="255"><? echo str_replace('"', '"', trim($row["VALOR"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><? echo htmlspecialchars("VALORTOTALVENDIDO")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="VALORTOTALVENDIDO" maxlength="255"><? echo str_replace('"', '"', trim($row["VALORTOTALVENDIDO"])) ?></textarea></td>
</tr>
<?
$idProduto = trim($row["idPRODUTOS"]);
$estoque = trim($row["QUANTIDADEEMESTOQUE"]);
$sqlMes = "SELECT SUM(QUANTIDADE) AS TOTAL FROM relatoriovendas WHERE IDPRODUTO = '".$idProduto."'";
$sqlMes = mysql_query($sqlMes);
$total = mysql_fetch_array($sqlMes);
$total = $total['TOTAL'];
if(empty($total)){
$total = 0;
}
?>
<tr><td colspan="2">Estoque Início Mês:<b> <? echo $total+$estoque; ?></b> Quantidade Vendida Mês: <b> <? echo $total; ?></b></td></tr>
</table>
<? } ?>
<? function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="produtos.php?a=add">Cadastrar Produto</a> </td>
<? if ($page > 1) { ?>
<td><a href="produtos.php?page=<? echo $page - 1 ?>"><< Anterior</a> </td>
<? } ?>
<?
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><? echo $j ?></b></td>
<? } else { ?>
<td><a href="produtos.php?page=<? echo $j ?>"><? echo $j ?></a></td>
<? } } } else { ?>
<td><a href="produtos.php?page=<? echo $startpage ?>"><? echo $startpage ."..." .$count ?></a></td>
<? } } } ?>
<? if ($page < $pagecount) { ?>
<td> <a href="produtos.php?page=<? echo $page + 1 ?>">Proximo >></a> </td>
<? } ?>
</tr>
</table>
<? } ?>
<? function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="produtos.php">Home</a></td>
<? if ($recid > 0) { ?>
<td><a href="produtos.php?a=<? echo $a ?>&recid=<? echo $recid - 1 ?>">Registro Anterior</a></td>
<? } if ($recid < $count) { ?>
<td><a href="produtos.php?a=<? echo $a ?>&recid=<? echo $recid + 1 ?>">Próximo Registro</a></td>
<? } ?>
</tr>
</table>
<hr size="1" noshade>
<? } ?>
<? function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="produtos.php">Home</a></td>
</tr>
</table>
<hr size="1" noshade>
<form action="produtos.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?
$row = array(
"idPRODUTOS" => "",
"PRODUTO" => "",
"QUANTIDADECOMPRADA" => "",
"QUANTIDADEEMESTOQUE" => "",
"QUANTIDADEVENDIDA" => "",
"VALOR" => "",
"VALORTOTALVENDIDO" => "");
showroweditor($row)
?>
<p><input type="submit" name="action" value="Cadastrar"></p>
</form>
<? } ?>
<? function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<? showrow($row) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="produtos.php?a=add">Cadastrar Produto</a></td>
<td><a href="produtos.php?a=edit&recid=<? echo $recid ?>">Editar Produto</a></td>
<td><a href="produtos.php?a=del&recid=<? echo $recid ?>">Apagar Produto</a></td>
</tr>
</table>
<?
mysql_free_result($res);
} ?>
<? function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form action="produtos.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xidPRODUTOS" value="<? echo $row["idPRODUTOS"] ?>">
<? showroweditor($row) ?>
<p><input type="submit" name="action" value="Cadastrar"></p>
</form>
<?
mysql_free_result($res);
} ?>
<? function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form action="produtos.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xidPRODUTOS" value="<? echo $row["idPRODUTOS"] ?>">
<? showrow($row) ?>
<p><input type="submit" name="action" value="Confirmar"></p>
</form>
<?
mysql_free_result($res);
} ?>
<? function connect()
{
$conn = mysql_connect("localhost", "sig", "teste");
mysql_select_db("sig");
return $conn;
}
function sqlvalue($val, $quote)
{
if ($quote)
$tmp = sqlstr($val);
else
$tmp = $val;
if ($tmp == "")
$tmp = "NULL";
elseif ($quote)
$tmp = "'".$tmp."'";
return $tmp;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "select `idPRODUTOS`, PRODUTO, QUANTIDADECOMPRADA, QUANTIDADEEMESTOQUE, QUANTIDADEVENDIDA, VALOR, VALORTOTALVENDIDO from `produtos`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`idPRODUTOS` like '" .$filterstr ."') or (PRODUTO like '" .$filterstr ."') or (QUANTIDADECOMPRADA like '" .$filterstr ."') or (QUANTIDADEEMESTOQUE like '" .$filterstr ."') or (QUANTIDADEVENDIDA like '" .$filterstr ."') or (VALOR like '" .$filterstr ."') or (VALORTOTALVENDIDO like '" .$filterstr ."')";
}
if (isset($order) && $order!='') $sql .= " order by \"" .sqlstr($order) ."\"";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "select count(*) from `produtos`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`idPRODUTOS` like '" .$filterstr ."') or (PRODUTO like '" .$filterstr ."') or (QUANTIDADECOMPRADA like '" .$filterstr ."') or (QUANTIDADEEMESTOQUE like '" .$filterstr ."') or (QUANTIDADEVENDIDA like '" .$filterstr ."') or (VALOR like '" .$filterstr ."') or (VALORTOTALVENDIDO like '" .$filterstr ."')";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}
function sql_insert()
{
global $conn;
global $_POST;
$sql = "insert into `produtos` (`idPRODUTOS`, PRODUTO, QUANTIDADECOMPRADA, QUANTIDADEEMESTOQUE, QUANTIDADEVENDIDA, VALOR, VALORTOTALVENDIDO) values (" .sqlvalue(@$_POST["idPRODUTOS"], false) .", " .sqlvalue(@$_POST["PRODUTO"], true) .", " .sqlvalue(@$_POST["QUANTIDADECOMPRADA"], false) .", " .sqlvalue(@$_POST["QUANTIDADEEMESTOQUE"], false) .", " .sqlvalue(@$_POST["QUANTIDADEVENDIDA"], false) .", " .sqlvalue(@$_POST["VALOR"], true) .", " .sqlvalue(@$_POST["VALORTOTALVENDIDO"], true) .")";
mysql_query($sql, $conn) or die(mysql_error());
}
function sql_update()
{
global $conn;
global $_POST;
$sql = "update `produtos` set `idPRODUTOS`=" .sqlvalue(@$_POST["idPRODUTOS"], false) .", PRODUTO=" .sqlvalue(@$_POST["PRODUTO"], true) .", QUANTIDADECOMPRADA=" .sqlvalue(@$_POST["QUANTIDADECOMPRADA"], false) .", QUANTIDADEEMESTOQUE=" .sqlvalue(@$_POST["QUANTIDADEEMESTOQUE"], false) .", QUANTIDADEVENDIDA=" .sqlvalue(@$_POST["QUANTIDADEVENDIDA"], false) .", VALOR=" .sqlvalue(@$_POST["VALOR"], true) .", VALORTOTALVENDIDO=" .sqlvalue(@$_POST["VALORTOTALVENDIDO"], true) ." where " ."(`idPRODUTOS`=" .sqlvalue(@$_POST["xidPRODUTOS"], false) .")";
mysql_query($sql, $conn) or die(mysql_error());
$sqlRelatorios = "insert into relatorioVendas(ID,DATAVENDA,VENDEDOR,IDPRODUTO,PRODUTO,QUANTIDADE,VALOR) VALUES ('','".date('Y-m-d H:i:s')."','".$_SESSION['usuarioLogado']."','".$_POST['idPRODUTOS']."','".$_POST["PRODUTO"]."','".$_POST["edtQuantidadeVendida"]."','".$_POST["edtValorVendido"]."')";
$sqlRelatorios = mysql_query($sqlRelatorios);
}
function sql_delete()
{
global $conn;
global $_POST;
$sql = "delete from `produtos` where " ."(`idPRODUTOS`=" .sqlvalue(@$_POST["xidPRODUTOS"], false) .")";
mysql_query($sql, $conn) or die(mysql_error());
} ?>