You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

370 lines
16 KiB

<?php
$tpLayout = 1;
include_once 'util/relatoriosBase.php';
class AgenteAnota extends Relatorios {
private $___consultar;
private $___validar;
private $___agenteAnota;
private $___agenteFone;
private $___listaAgente;
private $___matricula;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___consultar = isset($_POST["btPesquisa"]);
$this->___validar = isset($_POST["btAnota"]) && (trim($_POST["AnotaTexto"]) != "");
$this->___agenteAnota = isset($_POST["AnotaTexto"]) ? $_POST["AnotaTexto"] : "";
$this->___agenteFone = isset($_POST["AnotaFone"]) ? soNumero($_POST["AnotaFone"]) : (isset($_SESSION[RAMAL_DESTINO]) ? soNumero($_SESSION[RAMAL_DESTINO]) : '');
$this->___listaAgente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : GetMatricula();
$this->___dataIni = IsPostBack() ? $_POST['dataIni'] : date('d/m/Y');
$this->___dataFim = IsPostBack() ? $_POST['dataFim'] : date('d/m/Y');
$this->___matricula = GetMatricula();
}
function ___ValidaForm() {
if (!is_date($this->___dataIni) && empty($this->___agenteFone)) {
GeraExcept('A "Data Inicial" informada é inválida!');
}
if (!is_date($this->___dataFim) && empty($this->___agenteFone)) {
GeraExcept('A "Data Final" informada é inválida!');
}
if (!$this->___consultar && $this->___validar && empty($this->___agenteFone)) {
$msg = GetAnotacoesKey() ? "Informe o número do telefone!" : "Informe o número do protocolo!";
GeraExcept($msg);
}
if($this->___validar && !$this->___consultar){
$this->___InserirAnotacao();
}
}
function ___FiltrosRelatorio() {
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess�o do usu�rio.
*/
list($this->___dataIni, $this->___dataFim, $this->___agenteFone) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
return sprintf("Data Inicial: %s Data Final: %s ", $this->___dataIni, $this->___dataFim);
}
$fltCsv = array();
$fltCsv[] = "Data Inicial: " . $this->___dataIni;
$fltCsv[] = "Data Final: " . $this->___dataFim;
$fltCsv[] = "Data Hora Emissao: " . date('d/m/Y H i s)');
$fltCsv[] = "Emitido Por: " . GetLogin();
return $fltCsv;
}
$lkPrint = "";
if ($this->___dataCount) {
$prt = '<a href="index.php?idProg=%s&media=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>';
$prtHtml = "<a href=\"javaScript:NovaJanela('index.php?idProg=%s&media=%s', '%s', '720', '700', 'scrollbars=YES');\"><img src=\"imgSite/%s\" alt=\"Clique aqui para imprimir!\" width=\"24\" height=\"24\" border=\"0\"></a>";
//$lkPrint .= sprintf($prtHtml, $this->GetidProg(), MEDIA_PRINT_HTML, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png');
//$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, 'prt-pdf.png');
//$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, 'prt-csv.png');
}
$filtro .= '<table border="0" align="center" cellpadding="8" cellspacing="0" style="border-top:0;font-size:12px;" >
<tr>
<td align="center">
<span style="font-face:Arial, Helvetica, sans-serif; font-size:16px; font-weight:bold;">
<img src="imgSite/anotacoes.png" alt="Bloco de Anota&ccedil;&otilde;es" align="absmiddle" width="32" height="32" border="0" title="Bloco de Anota&ccedil;&otilde;es">
Bloco de Anotações
</span>
</td>
</tr>
</table>';
/*
* Personalise esta função se necessitar de outras opções de filtro.
*/
$filtro .= '<table class="filtro" align="center" border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
$filtro .= IsSuper() ? '<td>Agentes</td>' : '';
$filtro .= '<td>Agentes</td>';
$filtro .= '<td>Data Inicial </td>';
$filtro .= '<td>Data Final </td>';
$filtro .= sprintf('<td>%s</td>', GetAnotacoesKey() ? 'Fone' : $_SESSION['prm_label_protoco_pesquisa']);
/*
* Valores.
*/
$filtro .= '<tr>';
$filtro .= IsSuper() ? sprintf("<td><select name='listaAgente'>%s</select></td>", $this->GetAgentesAnotacoes($this->___listaAgente)) : '';
$filtro .= sprintf("<td><select name='listaAgente'>%s</select></td>", $this->GetAgentesAnotacoes($this->___listaAgente));
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="16" value="%s" onkeyup="formataDataHora(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><div> ';
$filtro .= sprintf('<input name="AnotaFone" size="20" type="text" id="AnotaFone" value="%s">'
. '<input name="btPesquisa" type="submit" id="btPesquisa" value="Pesquisar">'
. '<input name="btAnota" type="submit" id="btAnota" value="Salvar">', $this->___agenteFone);
$filtro .= '</div></td>';
$filtro .= '<td>%s</td>';
$filtro .= '</tr>';
$filtro .= '</table>';
$filtro .= "<br>";
$filtro .= '<table class="grid" align="center" border="0" cellspacing="1" cellpadding="1">';
$filtro .= "<tr><td class='destaque'>{$_SESSION['prm_label_protoco_texto']}</td></tr>";
$filtro .= "<tr>";
$filtro .= "<td><textarea name='AnotaTexto' cols='114' rows='8' id='AnotaTexto'></textarea></td>";
$filtro .= "</tr>";
$filtro .= "</table>";
/*
* Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o.
*/
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim, $this->___agenteFone);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$query = sprintf("SELECT a.id_text, a.conteudo, a.matricula_agente, a.fone_cliente, a.data, b.apelido
FROM pbx_anotacoes a
INNER JOIN pbx_usuarios b ON b.matricula = a.matricula_agente::text
WHERE data::DATE >= '$dataIni' AND data::DATE <= '$dataFim'");
if(empty($this->___agenteFone)){
$query .= $this->___listaAgente ? " AND a.matricula_agente::text = '$this->___listaAgente' " : "";
}
$query .= " AND fone_cliente LIKE '%$this->___agenteFone%'";
$query .= " ORDER BY b.apelido, a.data DESC";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
}
protected function ___PreparaExcel() {
$dataRel = array();
$dataAgrup = array();
$filtro = $this->___FiltrosRelatorio();
/*
* Inicia o relatório.
*/
/*
* Cria os filtros
*/
$linha = array('LABEL');
foreach ($filtro as $values) {
list($label, $value) = explode(":", $values);
$linha[] = $label;
}
$dataRel[] = $linha;
$linha = array('DADOS');
foreach ($filtro as $values) {
list($label, $value) = explode(":", $values);
$linha[] = $value;
}
$dataRel[] = $linha;
$dadosCabecalio = array('ID','Data', RemoveAcentos($_SESSION['prm_label_protoco_pesquisa']), 'Mensagem','Autor');
$dadosField = array('id_text', 'data', 'fone_cliente', 'conteudo', 'apelido');
/*
* Monta a linha de cabecalio.
*/
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaTempo = 0;
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row["data"] = date('d/m/Y', strtotime($row["data"]));
$row["conteudo"] = RemoveAcentos($row['conteudo']);
// Formata linha de dados.
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = $linha;
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dadosCabecalio = array(
'ID' => 'align="center"',
'Data' => 'align="center"',
$_SESSION['prm_label_protoco_pesquisa'] => 'align="center"',
'Mensagem' => 'align="left"',
'Autor' => 'align="center"',
);
$dadosField = array(
'id_text' => 'align="center"',
'data' => 'align="center"',
'fone_cliente' => 'align="center"',
'conteudo' => 'align="left"',
'apelido' => 'align="center"',
);
/*
* Inicia o relat�rio.
*/
$dataRel[] = '<table width="99%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$linha = '<tr>';
foreach ($dadosCabecalio as $key => $value) {
$linha .= sprintf("<th %s>%s</th>", $value, $key);
}
$linha .= "</tr>";
$dataRel[] = $linha;
/*
* Verifica se retornou dados
*/
if (!IsPostBack() || !count($this->GetData()[0])) {
$dataRel[] = sprintf("<tr><td align=\"center\" colspan=\"%s\">%s</td></tr></table>", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!'));
$this->___dataRel[] = $dataRel;
return;
}
$somaQuantidade = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$row["data"] = date('d/m/Y', strtotime($row["data"]));
// Formata linha de dados.
$linha = "<tr>";
foreach ($dadosField as $key => $value) {
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
}
$linha .= "</tr>";
$dataRel[] = $linha;
}
/*
* Linha de totalizacao.
*/
//$linha = '<tr><th colspan="2" align="left">Total</th><th align="left" colspan="2">Registros: %s</th><th align="left" colspan="6">Duração: %s</th></tr>';
//$dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo));
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
}
private function ___InserirAnotacao(){
if ($this->___validar && empty($this->___agenteAnota)) {
GeraExcept("Insira uma anotação!");
}
$query = "SELECT * FROM pbx_anotacoes WHERE conteudo = '{$this->___agenteAnota}' AND fone_cliente = '{$this->___agenteFone}';";
$res = $this->___GetQuery($query);
if(pg_fetch_assoc($res)){
GeraExcept('Essas informações já foram registradas!');
}
$query = "INSERT INTO pbx_anotacoes (conteudo,matricula_agente,fone_cliente) VALUES('$this->___agenteAnota', '$this->___matricula', '$this->___agenteFone');";
$result = $this->___GetQuery($query);
if(!$result){
GeraExcept('Não foi possível inserir o registro');
}
}
private function GetAgentesAnotacoes($matricula) {
$query = "SELECT id, apelido, nome, matricula FROM pbx_usuarios WHERE delete_ = 0 AND apelido NOT IN('sinccontasenha') ORDER BY apelido"; //'admin',
$result = $this->___GetQuery($query);
$sel = $matricula == "0" ? ' Selected="selected" ' : '';
$item = "<option value=\"0\"$sel>Todos</option>\n";
while ($dados = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$mat = $dados['matricula'];
$apelido = $dados['apelido'];
$sel = $mat == $matricula ? ' Selected="selected" ' : '';
$item .= "<option value=\"$mat\"$sel>$apelido-[$mat]</option>\n";
}
return $item;
}
public function ExecutaRelatorio() {
global $jsStartup, $jsJQuery, $smarty;
try {
/*
* Use esta fun��o para validar dados do formul�rio.
*/
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
$this->___ConteudoRelatorio();
/*
* Imprime relat�rio de acordo com a media passada.
*/
$conteudoRelatorio = $this->___ImprimeRelatorio();
} catch (Exception $exc) {
$this->SetMsg($exc->getMessage());
$jsStartup[] = sprintf("alert('%s');", $this->GetMsg());
$this->___GravaLog();
}
/*
* Inclua os scripts necessários aqui.
*/
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
$smarty->assign('filtros', $this->___FiltrosRelatorio());
$smarty->assign('conteudo', $conteudoRelatorio);
$smarty->assign('msg', $this->GetMsg());
GetTemplate($smarty, 'relatoriosGrid.tpl');
}
}
$agenteAnota = new AgenteAnota($idProg, $dbcon, 0);
$agenteAnota->ExecutaRelatorio();
?>