|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$mes = "";
|
|
|
|
|
$acao = isset($_GET['acao']) ? trim($_GET['acao']) : 'select';
|
|
|
|
|
$paramPesquisa = isset($_REQUEST['paramPesquisa']) ? $_REQUEST['paramPesquisa'] : '';
|
|
|
|
|
$filtro = isset($_REQUEST["paramPesquisa"]) ? trim($_REQUEST["paramPesquisa"]) : '';
|
|
|
|
|
$filtroNovo = !isset($_REQUEST["pgn"]) ? '' : sprintf("¶mPesquisa%s&pgn=%s&bloco=%s&pg=%s", $_REQUEST["paramPesquisa"], $_REQUEST["pgn"], $_REQUEST["bloco"], $_REQUEST["pg"]);
|
|
|
|
|
$recontaPag = ($acao == 'inseri') || ($acao == "deleta") || isset($_POST['pesquisa']);
|
|
|
|
|
$tpl = "vendas/grupoVendas.tpl";
|
|
|
|
|
|
|
|
|
|
if ($acao == "deleta") {
|
|
|
|
|
try {
|
|
|
|
|
/*
|
|
|
|
|
* VERIFICA SE EXISTE O RAMAL NA TABELA
|
|
|
|
|
*/
|
|
|
|
|
$id = $_GET['id'];
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, 'begin');
|
|
|
|
|
if (!$result) {
|
|
|
|
|
GeraExcept('N<EFBFBD>o foi poss<EFBFBD>vel iniciar a opera<EFBFBD><EFBFBD>o!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Apaga o grupo de vendas
|
|
|
|
|
*/
|
|
|
|
|
$deleta = "delete from vds_grupos where grp_id = '$id'";
|
|
|
|
|
$result = pg_query($dbcon, $deleta);
|
|
|
|
|
if (!$result) {
|
|
|
|
|
GeraExcept('Erro ao excluir a "Regional"!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = pg_query($dbcon, 'commit');
|
|
|
|
|
if (!$result) {
|
|
|
|
|
GeraExcept('N<EFBFBD>o foi poss<EFBFBD>vel finalizar a opera<EFBFBD><EFBFBD>o!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Alert('A "Regional" foi excluida com sucesso!');
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
Alert($ex->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$compl = '';
|
|
|
|
|
if (isset($_REQUEST['paramPesquisa']) && $_REQUEST['paramPesquisa']) {
|
|
|
|
|
$compl = PreparaLike($filtro, true);
|
|
|
|
|
$compl = sprintf("and (a.grp_nome ilike %s)", $compl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = "select a.grp_id, a.grp_nome, a.gpr_status, count(b.emp_id) as num_empresas
|
|
|
|
|
from vds_grupos a
|
|
|
|
|
left join vds_grupos_empresas b on b.grp_id = a.grp_id
|
|
|
|
|
where a.gpr_status = 0 $compl
|
|
|
|
|
group by a.grp_id, a.grp_nome, a.gpr_status
|
|
|
|
|
order by a.grp_nome ";
|
|
|
|
|
// select grp_id, grp_nome, gpr_status from vds_grupos where gpr_status = 0 $compl order by grp_nome
|
|
|
|
|
$resultados = '';
|
|
|
|
|
$params = "¶mPesquisa=$filtro";
|
|
|
|
|
$links = PaginaDados($idProg, $query, $params, $regPagina, $offSet, $pagMostra, true);
|
|
|
|
|
$query .= " limit $regPagina offset $offSet";
|
|
|
|
|
$result = pg_query($dbcon, $query);
|
|
|
|
|
|
|
|
|
|
while ($rowDepto = pg_fetch_array($result)) {
|
|
|
|
|
$regNome = $rowDepto['grp_nome'];
|
|
|
|
|
$regId = $rowDepto['grp_id'];
|
|
|
|
|
$relacionamento = $rowDepto['num_empresas'];
|
|
|
|
|
$regEdita = "<a style=\"color: #000;\" href=\"javaScript:NovaJanela('index.php?idProg=286&id=$regId&nome=$regNome', 'grupoRevendasCad', '500', '150', 'resizable=NO,scrollbars=1');\">$regNome</a>";
|
|
|
|
|
$resultados .= "<tr>
|
|
|
|
|
<td width=\"50\" align=\"center\">$regId</td>
|
|
|
|
|
<td>$regEdita</td>
|
|
|
|
|
<td width=\"20\" align=\"right\">$relacionamento</td>
|
|
|
|
|
<td width=\"20\" style=\"text-align: center; border-right:0;\"><a href=\"javaScript:NovaJanela('index.php?idProg=287®Id=$regId®Nome=$regNome', 'RelacionarRegionais', '930', '450', 'resizable=NO,scrollbars=1');\"><img src=\"imgSite/revendas.png\" width=\"15\" height=\"15\" border=\"0\"></a></td>
|
|
|
|
|
<td width=\"20\" style=\"text-align: center; border-right:0; border-left:0;\"><a href=\"javaScript:NovaJanela('index.php?idProg=286&id=$regId&nome=$regNome', 'grupoRevendasCad', '500', '150', 'resizable=NO,scrollbars=1');\"><img src=\"imgSite/editaUser.png\" border=\"0\"></a></td>
|
|
|
|
|
<td width=\"20\" style=\"text-align: center; border-left:0;\"><a href=\"javaScript:ApagaGrupoVendas('$regId', '$params');\"><img src=\"imgSite/deletaUser.png\" border=\"0\"></a></td>
|
|
|
|
|
</tr>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$imgNovo = "<a href=\"javaScript:NovaJanela('index.php?idProg=286$filtroNovo&id=0&nome=', 'Cadastro de Departamentos', '500', '150', 'resizable=NO,scrollbars=1');\"><img src=\"images/novo.gif\" border=\"0\" align=\"absmiddle\"> Novo Departamento</a>";
|
|
|
|
|
$smarty->assign('linhas', $resultados);
|
|
|
|
|
$smarty->assign('erro', $mes);
|
|
|
|
|
$smarty->assign("paramPesquisa", $paramPesquisa);
|
|
|
|
|
$smarty->assign("imgNovo", $imgNovo);
|
|
|
|
|
$smarty->assign("links", $links);
|
|
|
|
|
$smarty->assign("pagMostra", $pagMostra);
|
|
|
|
|
$smarty->assign("totalReg", $totalReg);
|
|
|
|
|
$smarty->assign("pgn", $_REQUEST["pgn"]);
|
|
|
|
|
$smarty->assign("bloco", $_REQUEST["bloco"]);
|
|
|
|
|
$smarty->assign("pg", $_REQUEST["pg"]);
|
|
|
|
|
|
|
|
|
|
GetTemplate($smarty, $tpl);
|
|
|
|
|
|
|
|
|
|
function RetornaMensagem($mes) {
|
|
|
|
|
if ($mes == "") {
|
|
|
|
|
$alert = "";
|
|
|
|
|
} else {
|
|
|
|
|
$alert = "<script type=\"text/javascript\">alert('$mes');</script>";
|
|
|
|
|
return $alert;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|