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; private $___tipoRelatorio; 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 = 'Clique aqui para imprimir!'; $prtHtml = "\"Clique"; $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 = ''; /* * Rotulos. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= ""; $filtro .= sprintf('', $this->___origem); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Ura Telefone  
%s$ura%s
'; /* * 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['src'] = ocultarTelefone($row["src"]); $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['src'] = ocultarTelefone($row["src"]); $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[] = ''; /* * Monta a linha de cabecalio. */ $dataRel[] = ""; $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Relatório URA
%s
%s
", 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("%s", 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 = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Registro(s): %s'; $dataRel[] = sprintf($linha, $somaReg); /* * Fecha relatorio. */ $dataRel[] = ''; $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]['src'] = ocultarTelefone($row["src"]); $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 a INNER JOIN pbx_ura b ON a.umv_ura_id = b.id WHERE umv_data >= '%s' AND umv_data <= '%s' AND umv_tipo = 'ini' AND b.org_id = {$this->GetOrgId()} ORDER BY umv_ura_nome ", FormatDtMssql($this->___dataIni), FormatDtMssql($this->___dataFim)); $resp = pg_query($dbcon, $query); $result = pg_fetch_all($resp); $row = ""; 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();