PABX da Simples IP
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.
 
 
 
 
 
 

419 lines
16 KiB

<?php
/* * *************************************************************************
*
* URA Geral
* Autor
* Lucas Awade
*
* *************************************************************************
Definições do Projeto
Nome: RelUraGeral
Data início: 13/09/2018
Equipe: Amarildo Pereira
Descrição:
Este relatório tem a finalidade de apresenta um fluxo de URA para que tenha
o acompanhamento de cada seção e seleção da URA. Para isso foi composto uma
tela auxiliar para examinar cada chamada de URA realizada durante um periodo
entre datas.
Tabela(s):
-> pbx_ura_movimento
Tabela(s) Auxiliar(es):
-> pbx_ura_movimento
-> pbx_ura
-> pbx_opcao_acao
-> pbx_opcoes
Retornos:
-> ini - Inicialização da URA;
-> opc - Selecionou uma opção na URA;
-> seq - Sequenciou um destino; -- |Fila|URA|Ramal|Voicemail|etc.
Script composto:
-> uraGeralDetalhes.php - Gera o fluxo de uma URA especifica;
Script Auxiliar:
-> pbx_complemento.php - Criação do registro no banco de dados;
* *************************************************************************
* Copyright (c) 2018, Simples IP
* ************************************************************************ */
include_once 'util/relatoriosBase.php';
class RelUraGeral extends Relatorios {
private $___ura;
private $___origem;
public function __construct($idProg, $dbcon, $incDac) {
parent::__construct($idProg, $dbcon, $incDac);
$this->___ura = isset($_POST["listaUra"]) ? $_POST["listaUra"] : '';
$this->___origem = isset($_POST["origem"]) ? $_POST["origem"] : '';
}
function ___FiltrosRelatorio() {
$ura = $this->___GetURA();
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sess�o do usu�rio.
*/
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
$fila = $this->GetIncDac() ? 'Fila: ' . GetDacDesc($this->GetDbCon(), $this->GetIdProg() . ' ') : '';
return sprintf("%sData Inicial: %s Data Final: %s Tipo: %s", $fila, $this->___dataIni, $this->___dataFim, ($this->___tipoRelatorio ? 'Analítico' : 'Sintético'));
}
$fltCsv = array();
if ($this->GetIncDac()) {
$fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac);
}
$fltCsv[] = "Data Inicial:" . $this->___dataIni;
$fltCsv[] = "Data Final:" . $this->___dataFim;
$fltCsv[] = "Data Emissao:" . date('d/m/Y H:i:s');
$fltCsv[] = "Emitido Por:" . GetLogin();
return $fltCsv;
}
if ($this->GetIncDac()) {
$dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1);
}
$lkPrint = "";
if ($_POST['btConsulta']) {
$prt = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%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&tipoRelatorio=%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, $this->___tipoRelatorio, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, $this->___tipoRelatorio, 'prt-xls.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, $this->___tipoRelatorio, 'prt-pdf.png');
$lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, $this->___tipoRelatorio, 'prt-csv.png');
}
$tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"';
/*
* Personalise esta fun��o se necessitar de outras op��es de filtro.
*/
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
*/
$filtro .= '<tr>';
if ($this->GetIncDac())
$filtro .= '<td>Fila</td>';
$filtro .= '<td>Data Inicial</td>';
$filtro .= '<td>Data Final </td>';
$filtro .= '<td>Ura </td>';
$filtro .= '<td>Telefone </td>';
$filtro .= '<td align="center" valign="middle">&nbsp;</td>';
$filtro .= '</tr>';
/*
* Valores.
*/
$filtro .= '<tr>';
if ($this->GetIncDac())
$filtro .= sprintf('<td>%s</td>', $dacs);
$filtro .= '<td><input name="dataIni" id="dataIni" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= '<td><input name="dataFim" id="dataFim" type="text" size="15" maxlength="10" value="%s" onkeyup="formataData(this)" title="dd/mm/aaaa"></td>';
$filtro .= "<td>$ura</td>";
$filtro .= sprintf('<td><input name="origem" id="origem" type="text" size="15" maxlength="15" value="%s" title="Número de telefone"></td></span></td>', $this->___origem);
$filtro .= '<td><input type="submit" name="btConsulta" id="btConsulta" value="Consultar"></td>';
$filtro .= '<td>%s</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);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb() {
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$query = "SELECT umv_id,data_reg,src,a.uniqueid,umv_tipo,umv_ura_id,umv_ura_nome,umv_ura_opcao,umv_opcao,
CASE WHEN (umv_opcao = 'filas')THEN (SELECT nome FROM pbx_dacs WHERE numero = umv_acao) ELSE umv_acao END AS umv_acao
FROM pbx_bilhetes a
INNER JOIN pbx_ura_movimento b ON a.uniqueid = b.uniqueid
WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim'";
$this->___ura ? $query .= " AND umv_ura_id = $this->___ura" : '';
$this->___origem ? $query .= " AND src = '$this->___origem'" : '';
$query .= " AND umv_tipo = 'ini'
ORDER BY uniqueid,data_reg";
$result = $this->___GetQuery($query);
$row = pg_fetch_all($result);
$this->SetData($row ? $row : array());
}
protected function ___PreparaCsv() {
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
$dataRel[] = GenerateCsvFromArray($filtro);
$dadosCabecalio = array('Data/Hora', 'Origem','Nome', 'Tipo');
$dadosField = array('data_reg', 'src','umv_ura_nome', 'umv_tipo');
$dataRel[] = GenerateCsvFromArray($dadosCabecalio);
$somaReg = 0;
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$row['umv_ura_nome'] = $row['umv_ura_nome'] ? $row['umv_ura_nome'] : '--';
$row['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$row['umv_tipo'] = $row['umv_tipo'] == 'ini' ? 'Entrada' : '';
// Formata linha de dados.
$linha = array();
foreach ($dadosField as $value) {
$linha[] = $row["$value"];
}
$dataRel[] = GenerateCsvFromArray($linha);
}
$dataRel[] = GenerateCsvFromArray(array('Registro(s): ' . $somaReg));
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaExcel() {
$dataRel = 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('Data/Hora','Origem', 'Nome', 'Tipo');
$dadosField = array('data_reg', 'src','umv_ura_nome', 'umv_tipo');
$linha = array('LABEL');
foreach ($dadosCabecalio as $value) {
$linha[] = $value;
}
$dataRel[] = $linha;
$somaReg = 0;
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$row['umv_ura_nome'] = $row['umv_ura_nome'] ? $row['umv_ura_nome'] : '--';
$row['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$row['umv_tipo'] = $row['umv_tipo'] == 'ini' ? 'Entrada' : '';
$linha = array('DADOS');
foreach ($dadosField as $key) {
$linha[] = $row["$key"];
}
$dataRel[] = $linha;
}
$dataRel[] = array('LABEL', 'Registro(s): ' . $somaReg);
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
$dataRel = array();
$dadosCabecalio = array(
'Data/Hora' => 'align="center"',
'Origem' => 'align="center"',
'Nome' => 'align="center"',
'Tipo' => 'align="center"'
);
$dadosField = array(
'data_reg' => 'align="center"',
'src' => 'align="center"',
'umv_ura_nome' => 'align="center"',
'umv_tipo' => 'align="center"'
);
/*
* Inicia o relatório.
*/
$dataRel[] = '<table width="50%" cellpadding="2" class="grid">';
/*
* Monta a linha de cabecalio.
*/
$dataRel[] = "<tr><th colspan='4'>Relatório URA</th></tr>";
$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;
}
$somaReg = 0;
/*
* Linhas de dados.
*/
foreach ($this->GetData()[0] as $row) {
$somaReg++;
$row['umv_ura_nome'] = $row['umv_ura_nome'] ? sprintf("<a style=\"color: #000;\" href=\"javaScript:NovaJanela('index.php?idProg=306&idUni=%s&dataIni=%s&dataFim=%s', 'uraGeral', '750', '450', 'resizable=NO,scrollbars=1');\">%s</a>", base64_encode($row['uniqueid']), $this->___dataIni, $this->___dataFim, $row['umv_ura_nome']) : '--';
$row['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$row['umv_tipo'] = $row['umv_tipo'] == 'ini' ? 'Entrada' : '';
$row['src'] = ocultarTelefone($row["src"]);
$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 align="left" colspan="4">Registro(s): %s</th></tr>';
$dataRel[] = sprintf($linha, $somaReg);
/*
* Fecha relatorio.
*/
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
}
protected function ___PreparaPdf() {
list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
$dadosCabecalio = array(
'Data/Hora' => 'C',
'Origem' => 'C',
'Nome' => 'C',
'Tipo' => 'C'
);
$dadosField = array(
'data_reg' => 'C',
'src' => 'C',
'umv_ura_nome' => 'C',
'umv_tipo' => 'C'
);
$dados = $this->GetData()[0];
$x = 0;
foreach ($dados as $row) {
$dados[$x]['data_reg'] = date('d/m/Y H:i:s', strtotime($row['data_reg']));
$dados[$x]['umv_ura_nome'] = $row['umv_ura_nome'] ? $row['umv_ura_nome'] : '--';
$row['umv_tipo'] == 'ini' ? $row['umv_tipo'] = $dados[$x]['umv_tipo'] = 'Entrada' : '';
$x++;
}
$widthHeader = array(35, 55 ,55, 35);
$totaliza = array('Registro(s): ' , $x, '', '');
$table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 0);
$this->___dataRel = array($table);
}
protected function ___GetURA() {
global $dbcon;
$query = sprintf("SELECT DISTINCT umv_ura_nome, umv_ura_id
FROM pbx_ura_movimento
WHERE umv_data >= '%s' AND umv_data <= '%s'
AND umv_tipo = 'ini' ", FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim));
$resp = pg_query($dbcon, $query);
$result = pg_fetch_all($resp);
$row = "<select name=\"listaUra\">";
!$result ? $row .= "<option value=\"0\"> ----- </option>" : $row .= "<option value=\"0\">Todas</option>";
foreach ($result as $uraMov) {
$sel = $this->___ura == $uraMov['umv_ura_id'] ? "selected" : '';
if($uraMov['umv_ura_nome']) {
$row .= sprintf("<option value=\"%s\" $sel>%s</option>", $uraMov['umv_ura_id'], $uraMov['umv_ura_nome']);
}
}
$row .= "</select>";
return $row;
}
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');
}
}
$relUraGeral = new RelUraGeral($idProg, $dbcon, 0);
$relUraGeral->ExecutaRelatorio();
?>