___ura = isset($_POST["listaUra"]) ? $_POST["listaUra"] : ''; } function ___FiltrosRelatorio() { $ura = $this->___GetURA(); if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessao do usuario. */ 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(); $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 .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= ""; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Ura  
%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_ura_nome, count(umv_ura_opcao) AS qtd_opcao, umv_ura_opcao, umv_opcao, nome_comando, umv_ura_id FROM pbx_ura_movimento a INNER JOIN pbx_ura_destino b ON a.umv_ura_id = b.id_ura AND umv_ura_opcao = numero WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim' AND umv_ura_opcao IS NOT NULL "; $query .= $this->___ura ? "AND id_ura = $this->___ura " : ""; $query .= " GROUP BY 1,3,4,5,6 "; $query .= "UNION SELECT umv_ura_nome, SUM(CASE WHEN((SELECT COUNT(umv_tipo) FROM pbx_ura_movimento bx WHERE bx.uniqueid = ax.uniqueid AND umv_tipo IN ('seq', 'opc')) = 0) THEN 1 ELSE 0 END) AS qtd_opcao, 'NULO' AS umv_ura_opcao, 'desligou' AS umv_opcao, 'FINALIZOU NA URA' AS nome_comando, umv_ura_id FROM pbx_ura_movimento ax WHERE NOT EXISTS (SELECT umv_tipo FROM pbx_ura_movimento bx WHERE bx.uniqueid = ax.uniqueid AND umv_tipo IN ('seq', 'opc')) AND umv_data >= '$dataIni' AND umv_data <= '$dataFim' "; $query .= $this->___ura ? "AND umv_ura_id = $this->___ura " : ""; $query .= "GROUP BY 1,3,4,5,6 "; $query .= "UNION SELECT umv_ura_nome, SUM(CASE WHEN(length(umv_ura_opcao) > 1)THEN 1 END) AS qtd_opcao, 'INTEGRACAO > ' || b.numero AS umv_ura_opcao, umv_opcao, nome_comando, umv_ura_id FROM pbx_ura_movimento a INNER JOIN pbx_ura_destino b ON b.id_ura = a.umv_ura_id AND tipo = umv_opcao WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim' AND tipo = 'integativa' AND numero = '_X.' "; $query .= $this->___ura ? "AND id_ura = $this->___ura " : ""; $query .= "GROUP BY 1,3,4,5,6"; $query .= "UNION SELECT distinct umv_ura_nome,(select count(*) from pbx_ura_movimento bx WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim' AND bx.umv_ura_opcao IS NOT NULL and bx.umv_ura_id = a.id_ura AND bx.umv_ura_opcao = a.numero) AS qtd_opcao, numero,tipo,nome_comando,umv_ura_id FROM pbx_ura_destino a inner join pbx_ura_movimento b on b.umv_ura_id = a.id_ura WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim' AND (select count(*) from pbx_ura_movimento bx WHERE umv_data >= '$dataIni' AND umv_data <= '$dataFim' AND bx.umv_ura_opcao IS NOT NULL and bx.umv_ura_id = a.id_ura AND bx.umv_ura_opcao = a.numero) = 0 AND umv_opcao is not null AND numero <> '_X.' "; $query .= $this->___ura ? "AND id_ura = $this->___ura " : ""; $query .= "ORDER BY umv_ura_nome,umv_ura_opcao, umv_ura_id"; //if(IsAdmin()){echo $query;} $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); $ultClass = ''; $somaReg = 0; $dados = $this->GetData()[0]; $regUra = 0; foreach ($dados as $row) { $count++; if ($count != 1) { if ($ultClass != $row['umv_ura_nome']) { $dataRel[] = GenerateCsvFromArray(array("Registros: ", $somaReg, 'Total: ', $regUra)); $dataRel[] = GenerateCsvFromArray(array('', '')); unset($somaReg); $dataRel[] = GenerateCsvFromArray(array('Nome', 'Opcao', 'Destino', 'Quantidade Selecao')); } } else { unset($somaReg); $dataRel[] = GenerateCsvFromArray(array('Nome', 'Opcao', 'Destino', 'Quantidade Selecao')); } unset($regUra); foreach ($dados as $reg) { if ($reg['umv_ura_nome'] == $row['umv_ura_nome']) { $regUra += $reg['qtd_opcao']; } } $somaReg++; $row['umv_ura_nome'] = RemoveAcentos($row['umv_ura_nome']); $row['umv_ura_opcao'] = RemoveAcentos($row['umv_ura_opcao']); $row['umv_opcao'] = strtoupper($row['umv_opcao']) . ' > ' . strtoupper($row['nome_comando']); $row['qtd_opcao'] = strtoupper($row['qtd_opcao']) . ' ' . $this->___GetPorcentagem($row['qtd_opcao'], $regUra); // Formata linha de dados. $dataRel[] = GenerateCsvFromArray(array($row['umv_ura_nome'], $row['umv_ura_opcao'], $row['umv_opcao'], $row['qtd_opcao'])); $ultClass = $row['umv_ura_nome']; if (count($dados) == $count) { $dataRel[] = GenerateCsvFromArray(array("Registros: ", $somaReg, 'Total: ', $regUra)); } } $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; $dadosField = array('umv_ura_nome', 'umv_ura_opcao', 'umv_opcao', 'qtd_opcao'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $ultClass = ''; $somaReg = 0; $regUra = 0; $dados = $this->GetData()[0]; foreach ($dados as $row) { $count++; if ($count != 1) { if ($ultClass != $row['umv_ura_nome']) { $dataRel[] = array('LABEL', "Registros: ", 'Total: ', $somaReg); $dataRel[] = array('LABEL', '', ''); unset($somaReg); $dataRel[] = array('LABEL', 'Nome', 'Opcao', 'Destino', 'Quantidade Selecao'); } } else { $dataRel[] = array('LABEL', 'Nome', 'Opcao', 'Destino', 'Quantidade Selecao'); } unset($regUra); foreach ($dados as $reg) { if ($reg['umv_ura_nome'] == $row['umv_ura_nome']) { $regUra += $reg['qtd_opcao']; } } $somaReg++; $row['umv_ura_nome'] = RemoveAcentos($row['umv_ura_nome']); $row['umv_ura_opcao'] = RemoveAcentos($row['umv_ura_opcao']); $row['umv_opcao'] = strtoupper($row['umv_opcao']) . ' > ' . strtoupper($row['nome_comando']); $row['qtd_opcao'] = strtoupper($row['qtd_opcao']) . ' ' . $this->___GetPorcentagem($row['qtd_opcao'], $regUra); $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; $ultClass = $row['umv_ura_nome']; if (count($dados) == $count) { $dataRel[] = array('LABEL', "Registros: ", $somaReg, 'Total: ', $somaReg); } } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $colspan = 4; $dadosCabecalio = array( 'Nome' => 'align="center"', 'Opção' => 'align="center"', 'Destino' => 'align="center"', 'Quantidade Seleção' => 'align="center"' ); $dadosField = array( 'umv_ura_nome' => 'align="center"', 'umv_ura_opcao' => 'align="center"', 'umv_opcao' => 'align="center"', 'qtd_opcao' => 'align="center"' ); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $dataRel[] = ""; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Relatório URA
%s
", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaReg = 0; $ultUra = ""; $count = 0; $regUra = 0; $dados = $this->GetData()[0]; /* * Linhas de dados. */ foreach ($dados as $row) { if ($ultUra != $row['umv_ura_nome']) { if ($count > 0) { $linha = "Registros: %sTotal: %s"; $dataRel[] = sprintf($linha, $somaReg, $regUra); $dataRel[] = " "; unset($somaReg); unset($regUra); } foreach ($dados as $reg) { if ($reg['umv_ura_nome'] == $row['umv_ura_nome']) { $regUra += $reg['qtd_opcao']; } } $linha = " URA {$row['umv_ura_nome']} "; $linha .= ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("%s", $value, $key); } $linha .= ""; $dataRel[] = $linha; } $count++; $somaReg++; $ultUra = $row['umv_ura_nome']; // Formata linha de dados. $link = $row['umv_ura_nome'] ? sprintf("%s", $row['umv_opcao'], $this->___dataIni, $this->___dataFim, strtoupper($row['qtd_opcao'])) : '--'; $linha = ""; $linha .= sprintf("%s", $row['umv_ura_nome']); $linha .= sprintf("%s", $row['umv_ura_opcao']); $linha .= sprintf("%s", strtoupper($row['nome_comando'])); $opcoesUraLink = ["INTEGRACAO > _X.", "NULO"]; if (!in_array($row['umv_ura_opcao'], $opcoesUraLink) && $row['qtd_opcao'] > 0) { $linha .= sprintf("%s [ %s ]", $link, $this->___GetPorcentagem($row['qtd_opcao'], $regUra)); } else { $linha .= sprintf("%s [ %s ]", $row['qtd_opcao'] ? $row['qtd_opcao'] : "0", $this->___GetPorcentagem($row['qtd_opcao'], $regUra)); } $linha .= ""; $dataRel[] = $linha; if (count($dados) == $count) { $linha = "Registros: %s Total: %s"; $dataRel[] = sprintf($linha, $somaReg, $regUra); unset($somaReg); } } /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; $dados = array(); $tables = array(); $header = null; $x = 0; $t = 0; $ultUra = ""; $regUra = 0; $somaReg = 0; $dataHeader = array( 'umv_ura_nome' => 'C', 'umv_ura_opcao' => 'C', 'umv_opcao' => 'C', 'qtd_opcao' => 'C' ); $widthHeader = array(50, 20, 70, 35); foreach ($this->GetData()[0] as $row) { $count++; if ($x) { if ($ultUra != $row['umv_ura_nome']) { $totalizador = array("Registros: $somaReg", '', '', 'Total: ' . $regUra); ${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); array_push($tables, ${"table" . $t}); $t++; unset($somaReg); unset($dados); unset($regUra); $x = 0; $header = array('Nome' => 'C', 'Opção' => 'C', 'Destino' => 'C', 'Quantidade Seleção' => 'C'); foreach ($this->GetData()[0] as $reg) { if ($reg['umv_ura_nome'] == $row['umv_ura_nome']) { $regUra += $reg['qtd_opcao']; } } } } else { foreach ($this->GetData()[0] as $reg) { if ($reg['umv_ura_nome'] == $row['umv_ura_nome']) { $regUra += $reg['qtd_opcao']; } } $header = array('Nome' => 'C', 'Opção' => 'C', 'Destino' => 'C', 'Quantidade Seleção' => 'C'); } $somaReg++; $ultUra = $row['umv_ura_nome']; $dados[$x]["umv_ura_nome"] = $row["umv_ura_nome"]; $dados[$x]["umv_ura_opcao"] = $row['umv_ura_opcao']; $dados[$x]["umv_opcao"] = strtoupper($row['umv_opcao']) . ' > ' . strtoupper($row['nome_comando']); $dados[$x]["qtd_opcao"] = strtoupper($row['qtd_opcao']) . ' [ ' . $this->___GetPorcentagem($row['qtd_opcao'], $regUra) . ' ]'; $x++; $z++; if (count($this->GetData()[0]) == $count) { $totalizador = array("Registros: $somaReg", '', '', 'Total: ' . $regUra); ${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); array_push($tables, ${"table" . $t}); } } $this->___dataRel = $tables; } protected function ___GetPorcentagem($parcial, $total) { $result = ($parcial * 100) / $total; return round($result, 2) . '%'; } 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_ura_opcao IS NOT NULL AND umv_tipo = 'opc'", 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 RelUraDesempenho($idProg, $dbcon, 0); $relUraGeral->ExecutaRelatorio();