___dac = isset($_POST["listaDacs"]) ? $_POST["listaDacs"] : 0; $this->___lstPesquisa = isset($_POST["lstPesquisa"]) ? $_POST["lstPesquisa"] : '0| | | |0| '; $this->___matricula = isset($_POST["matricula"]) ? $_POST["matricula"] : 0; } function ___FiltrosRelatorio() { global $dbcon; if ($this->___lstPesquisa) { $this->___plId = explode('|', $this->___lstPesquisa)[0]; } $lstPesquisa = GetPesquisaRel($dbcon, $this->___plId, $this->___matricula); if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessao do usuario. */ list($this->___dac, $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 ($this->___dataCount) { $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 funcao se necessitar de outras opnioes de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= ""; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ""; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
PesquisaFilaAgenteData InicialData Final  
%s %s
'; /* * Guarda os filtros passados para recuperar na emissao dos relatoios para impressao. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { global $dbcon; $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $plId = $this->___plId; $ppId = $this->___ppId; $dac = $this->___dac; $ppNome = $this->___ppNome; $plDescricao = $this->___plDescricao; $datas = $this->___datas; $matricula = $this->___matricula; GetDadosPesq($dbcon, $this->___lstPesquisa, $plId, $plDescricao, $ppId, $ppNome, $datas); $query = "SELECT pq_display, pq_questao, (select count(*) from pbx_pesquisa_movimento where pl_id = $plId and pp_id = a.pp_id and pq_id = a.pq_id and id_dac = $dac and user_reg = '$matricula' and pm_data >= '$dataIni' and pm_data <= '$dataFim') as num_resp,pq_id from pbx_pesquisa_questoes a, pbx_pesquisa_liberacao b where b.pp_id = a.pp_id and b.pl_id = '$plId' and pq_status = 1 order by 1"; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); foreach ($row as $dataPsq) { $sql = "select a.po_id, a.po_tecla, a.po_opcao, count(b.po_id) as num_resp from pbx_pesquisa_opcoes a left outer join pbx_pesquisa_movimento b on b.po_id = a.po_id and pl_id = $plId and b.pq_id = a.pq_id and b.id_dac = $dac and b.user_reg = '$matricula' and b.pm_data >= '$dataIni' and b.pm_data <= '$dataFim' where a.pq_id = {$dataPsq['pq_id']} group by a.po_id, a.po_tecla, a.po_opcao order by 2"; $res = $this->___GetQuery($sql); $rows = pg_fetch_all($res); $this->SetData($rows ? $rows : array()); } $query_status = "SELECT fila, d.matricula, apelido, SUM(CASE WHEN (c.data_reg IS NOT NULL)THEN 1 ELSE 0 END) AS envio_pesquisa, SUM(CASE WHEN (c.data_fim IS NOT NULL)THEN 1 ELSE 0 END) AS completou_pesquisa, COUNT(*) AS chamadas_realizadas FROM pbx_bilhetes a INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 LEFT JOIN pbx_pesquisa_regitra c ON a.uniqueid = c.uniqueid LEFT JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente, 7, 4) LEFT JOIN pbx_queues_grupos e ON e.nome = b.fila WHERE calldate::DATE >= '{$dataIni}' AND calldate::DATE <= '{$dataFim}' AND b.evento IN('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL', 'COMPLETACALLER', 'COMPLETAAGENT') AND e.id = {$dac} AND d.matricula = '{$matricula}' GROUP BY fila, d.matricula, apelido"; $res = $this->___GetQuery($query_status); $rows = pg_fetch_all($res); $this->SetData($rows ? $rows : array()); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array('Opcao', 'Resposta', 'Quantidade', 'Porcentagem'); $dadosField = array('po_tecla', 'po_opcao', 'num_resp', 'por_resp'); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $x = 1; $somaResp = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaResp = $this->__CalculaPorcentagem($row['pq_questao'], $this->GetData()[0]); $dataRel[] = GenerateCsvFromArray(array('', '', RemoveAcentos($row['pq_questao']))); $linha = array(); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = GenerateCsvFromArray($linha); // Formata linha de dados. foreach ($this->GetData()[$x] as $dataPsq) { $linha = array(); foreach ($dadosField as $key) { if ($key == 'po_opcao') { $linha[] = RemoveAcentos($dataPsq["$key"]); } else if ($key == 'por_resp') { $dataPsq['por_resp'] = $dataPsq["num_resp"] ?? number_format(($dataPsq["num_resp"] / $somaResp) * 100.0, 2, ',', '.') . '%'; $linha[] = $dataPsq['por_resp']; } else { $linha[] = $dataPsq["$key"]; } } $dataRel[] = GenerateCsvFromArray($linha); unset($linha); } $dataRel[] = GenerateCsvFromArray(array('Total', '', 'Resp.: ' . $somaResp, $somaResp ?? number_format(($somaResp / $somaResp) * 100.0, 2, ',', '.') . '%')); $x++; } $dataRel[] = GenerateCsvFromArray(array('')); $dadosCabecalio = array('Fila', 'Apelido', 'Direcionamento Pesquisa', 'Conclusao Pesquisa', 'Chamadas'); $dadosField = array('fila', 'apelido', 'envio_pesquisa', 'completou_pesquisa', 'chamadas_realizadas'); $linha = array(); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $linha = array(); foreach ($this->GetData()[$x] as $stat) { $linha = array(); foreach ($dadosField as $key) { $linha[] = $stat[$key]; } } $dataRel[] = GenerateCsvFromArray($linha); $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('Opcao', 'Resposta', 'Quantidade', 'Porcentagem'); $dadosField = array('po_tecla', 'po_opcao', 'num_resp', 'por_resp'); /* * Monta a linha de cabecalio. */ $x = 1; $somaResp = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaResp = $this->__CalculaPorcentagem($row['pq_questao'], $this->GetData()[0]); $dataRel[] = array('LABEL', '', '', RemoveAcentos($row['pq_questao'])); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; // Formata linha de dados. foreach ($this->GetData()[$x] as $dataPsq) { $linha = array('DADOS'); foreach ($dadosField as $key) { if ($key == 'po_opcao') { $linha[] = RemoveAcentos($dataPsq["$key"]); } else if ($key == 'por_resp') { $dataPsq['por_resp'] = $dataPsq["num_resp"] ?? number_format(($dataPsq["num_resp"] / $somaResp) * 100.0, 2, ',', '.') . '%'; $linha[] = $dataPsq['por_resp']; } else { $linha[] = $dataPsq["$key"]; } } $dataRel[] = $linha; unset($linha); } $dataRel[] = array('LABEL', 'Total', '', 'Resp.: ' . $somaResp, $somaResp ?? number_format(($somaResp / $somaResp) * 100.0, 2, ',', '.') . '%'); $x++; } $dataRel[] = array('LABEL', ''); $dadosCabecalio = array('Fila', 'Apelido', 'Direcionamento Pesquisa', 'Conclusao Pesquisa', 'Chamadas'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $dadosField = array('fila', 'apelido', 'envio_pesquisa', 'completou_pesquisa', 'chamadas_realizadas'); $linha = array('DADOS'); foreach ($this->GetData()[$x] as $stat) { $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $stat[$key]; } } $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Opção' => 'align="center"', 'Resposta' => 'align="center"', 'Quantidade' => 'align="center"', 'Porcentagem [ % ]' => 'align="center"' ); $dadosField = array( 'po_tecla' => 'align="center"', 'po_opcao' => 'align="center"', 'num_resp' => 'align="center"', 'por_resp' => '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 Pesquisa
%s
", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } //print_r($this->GetData()); $x = 1; $somaResp = 0; $linhas = ''; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { //Monta a Questão da Pergunta da pesquisa. $linhas .= sprintf("%s", $row['pq_questao']); $linhas .= ""; foreach ($dadosCabecalio as $key => $value) { $linhas .= sprintf("%s", $value, $key); } $linhas .= ""; $dataRel[] = $linhas; unset($linhas); //Cria as linha dos resultado de acordo com as respostas $somaResp = $this->__CalculaPorcentagem($row['pq_questao'], $this->GetData()[0]); foreach ($this->GetData()[$x] as $dataPesquisa) { $linhas .= ""; foreach ($dadosField as $k => $value) { if ($k == 'por_resp') { $linhas .= sprintf("%s%%", $value, $dataPesquisa["num_resp"] ?? number_format(($dataPesquisa["num_resp"] / $somaResp) * 100.0, 2, ',', '.')); } else { $linhas .= sprintf("%s", $value, $dataPesquisa["$k"]); } } $linhas .= ""; } $linhas .= sprintf("Total$somaResp%s", $somaResp ?? number_format(($somaResp / $somaResp) * 100.0, 2, ',', '.') . '%'); $x++; $dataRel[] = $linhas; unset($linhas); } /* * Fecha relatorio. */ $dataRel[] = ''; $dataRel[] = "
"; $dataRel[] = ''; $dataRel[] = ""; $dataRel[] = "" . "" . "" . "" . "" . "" . ""; foreach ($this->GetData()[$x] as $est) { $dataRel[] = "" . "" . "" . "" . "" . "" . ""; } $dataRel[] = '
Estátistica Agente
FilaAgenteDirecionamento PesquisaConclusao PesquisaChamadas
{$est['fila']}{$est['apelido']}{$est['envio_pesquisa']}{$est['completou_pesquisa']}{$est['chamadas_realizadas']}
'; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ $dadosCabecalio = array( 'Opção' => 'C', 'Resposta' => 'C', 'Quantidade' => 'C', 'Porcentagem [ % ]' => 'C' ); $dadosField = array( 'po_tecla' => 'C', 'po_opcao' => 'C', 'num_resp' => 'C', 'por_resp' => 'C' ); $somaTotalQtd = 0; $dados = $this->GetData()[0]; $x = 1; $z = 0; $dataQst = array(); $tables = array(); $widthHeader = array(37, 77, 37, 37); foreach ($dados as $row) { $somaTotalQtd = $this->__CalculaPorcentagem($row['pq_questao'], $this->GetData()[0]); foreach ($this->GetData()[$x] as $data) { $dataQst[$z]['pq_questao'] = $data['pq_questao']; $dataQst[$z]['po_opcao'] = $data['po_opcao']; $dataQst[$z]['num_resp'] = $data['num_resp']; $dataQst[$z]['po_tecla'] = $data['po_tecla']; $dataQst[$z]['por_resp'] = $data["num_resp"] ?? number_format(($data["num_resp"] / $somaTotalQtd) * 100.0, 2, ',', '.') . '%'; $z++; } $totalizador = array('Total: ', $row['pq_questao'], 'Resp.: ' . $somaTotalQtd, $somaTotalQtd ?? number_format(($somaTotalQtd / $somaTotalQtd) * 100.0, 2, ',', '.') . '%'); $tables[] = array($dadosCabecalio, $dadosField, $dataQst, $widthHeader, $totalizador, 0); $x++; unset($dataQst); } $dadosCabecalio = array( 'Fila' => 'C', 'Agente' => 'C', 'Direcionamento Pesquisa' => 'C', 'Conclusao Pesquisa' => 'C', 'Chamadas' => 'C' ); $dadosField = array( 'fila' => 'C', 'apelido' => 'C', 'envio_pesquisa' => 'C', 'completou_pesquisa' => 'C', 'chamadas_realizadas' => 'C' ); $widthHeader = array(20, 20, 40, 40, 20); $tables[] = array($dadosCabecalio, $dadosField, $this->GetData()[$x], $widthHeader, 0, 0); $this->___dataRel = $tables; } protected function __CalculaPorcentagem($coluna, $array) { $somaQtd = 0; foreach ($array as $value) { if ($value['pq_questao'] == $coluna) { $somaQtd += $value['num_resp']; } } return $somaQtd; } 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'); } } $relPesquisaAgt = new RelPesquisaAgente($idProg, $dbcon, 1); $relPesquisaAgt->ExecutaRelatorio();