__agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : ''; $this->__tipoLigacao = isset($_POST["tipoLigacao"]) ? $_POST["tipoLigacao"] : 0; $this->__filtro = isset($_POST["filtro"]) ? $_POST["filtro"] : ''; $this->__classificacao = isset($_POST["classificacao"]) ? $_POST["classificacao"] : ''; $this->__pesquisa = isset($_POST["pesquisa"]) ? $_POST["pesquisa"] : ''; } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuário. */ list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio, $this->___agente, $this->__classificacao, $this->__pesquisa) = $_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); } $agentes = $this->getAgentes(); $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 opcoes de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; if ($this->GetIncDac()){ $filtro .= ''; } $filtro .= ''; $filtro .= ''; $class = $this->__classificacao ? "checked" : ''; $pesq = $this->__pesquisa ? "checked" : ''; $filtro .= sprintf('', $class, $pesq); $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; if ($this->GetIncDac()){ $filtro .= sprintf('', $dacs); } $filtro .= ""; $filtro .= sprintf('', $this->__filtro); $entrada = $this->__tipoLigacao == 2 ? "checked" : ""; $saida = $this->__tipoLigacao == 3 ? "checked" : ""; $ambos = $this->__tipoLigacao == 0 ? "checked" : ""; $filtro .= sprintf('', $entrada, $saida, $ambos); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
Data InicialData Final FilaAgenteFiltro' . '' . '' . '
' . '
' . ' Classificação  ' . ' Pesquisa  ' . '
' . '
%s$agentes' . '
' . 'Entrada  ' . 'Saída  ' . 'Ambos' . '
' . '
%s
'; /* * Guarda os filtros passados para recuperar na emissão dos relatóios para impressão. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio, $this->___agente, $this->__classificacao, $this->__pesquisa); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $classificacao = $this->__classificacao ? "LEFT JOIN (SELECT id_bilhetes, STRING_AGG(remove_acentos(clas_descricao || ' -> ' || clit_descricao) , '; ' ORDER BY cr.clas_id) AS classificacao FROM pbx_classifica_reg cr INNER JOIN pbx_classifica_atendimento ca ON cr.clas_id = ca.clas_id INNER JOIN pbx_classifica_item ci ON cr.clit_id = ci.clit_id WHERE data_reg::DATE >= '$dataIni' AND data_reg::DATE <= '$dataFim' GROUP BY id_bilhetes) AS class ON class.id_bilhetes = a.uniqueid": ''; $pesquisa = $this->__pesquisa ? "LEFT JOIN (SELECT a.uniqueid, STRING_AGG(remove_acentos(pq_questao || ' -> ' || po_opcao) , '; ' ORDER BY po_display) AS pesquisa FROM pbx_pesquisa_movimento a INNER JOIN pbx_pesquisa_questoes b ON b.pp_id = a.pp_id AND b.pq_id = a.pq_id INNER JOIN pbx_pesquisa_opcoes c ON c.pp_id = b.pp_id AND c.pq_id = b.pq_id AND c.po_id = a.po_id INNER JOIN pbx_pesquisa_regitra d ON d.uniqueid = a.uniqueid INNER JOIN pbx_pesquisa e ON e.pp_id = a.pp_id WHERE a.data_reg::DATE >= '$dataIni' AND a.data_reg::DATE <= '$dataFim' GROUP BY a.uniqueid) AS pesq ON pesq.uniqueid = a.uniqueid" : ''; $columnPesq = $this->__pesquisa ? "pesquisa," : ""; $columnClass = $this->__classificacao ? "classificacao," : ""; $query = "SELECT calldate, protocolo, src, dst, tplg_descricao, CASE WHEN(ed.evento = 'ABANDON')THEN strtoint(ed.param3) ELSE a.billsec END AS tempo_atendimento, userfield, fila, apelido, evento, $columnClass $columnPesq REPLACE(SUBSTRING(retorno_cliente, POSITION('||' in retorno_cliente), 99999), '||', '') AS dados_cliente, CASE WHEN (abdsr_agente IS NOT NULL) THEN 'RETORNADA' ELSE '-' END AS retorno_abd FROM pbx_bilhetes a LEFT JOIN pbx_eventos_dacs ed ON a.uniqueid = ed.uid2 AND evento IN ('COMPLETAAGENT','COMPLETACALLERRAMAL','COMPLETACALLER','COMPLETECALLERRAMAL','COMPLETEAGENT','COMPLETEAGENTRAMAL','COMPLETECALLER','ABANDON') LEFT JOIN pbx_usuarios us ON us.matricula = substring(ed.agente,7,4) LEFT JOIN pbx_protocolo_reg pr ON pr.uniqueid = a.uniqueid LEFT JOIN pbx_tipo_ligacao tp ON tp.tplg_codigo = a.tipo_chamada $classificacao $pesquisa LEFT JOIN pbx_abandonadas_semretorno asr ON asr.abdsr_uniqueid = a.uniqueid LEFT JOIN pbx_integracao_reg ir ON ir.reg_uniqueid = a.uniqueid LEFT JOIN pbx_queues_grupos qg ON qg.nome = ed.fila WHERE calldate::DATE >= '$dataIni' AND calldate::DATE <= '$dataFim' AND a.lastapp NOT IN ('Transferred Call','Playback','BackGround', 'AppDial2', 'Goto') "; if($this->__filtro){ $query .= "AND ((src LIKE '%{$this->__filtro}%') OR (dst LIKE '%{$this->__filtro}%') OR (protocolo::VARCHAR LIKE '%{$this->__filtro}%')) "; } if($this->___dac){ $query .= "AND qg.id = {$this->___dac} "; } if($this->__tipoLigacao){ $query .= "AND tplg_tipo = {$this->__tipoLigacao} "; } $query .= "ORDER BY a.uniqueid"; $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); $dadosCabecalio = array( 'Data Hora', 'Tipo', 'Protocolo', 'Origem', 'Destino', 'Duração', 'Fila', 'Agente', 'Status', 'Retornada ABD.', ); $this->__classificacao ? $dadosCabecalio[] = 'Classificação' : ''; $this->__pesquisa ? $dadosCabecalio[] = 'Pesquisa' : ''; $dadosField = array( 'calldate', 'tplg_descricao', 'protocolo', 'src', 'dst', 'tempo_atendimento', 'fila', 'apelido', 'evento', 'retorno_abd' ); $this->__classificacao ? $dadosField[] = 'classificacao' : ''; $this->__pesquisa ? $dadosField[] = 'pesquisa' : ''; /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['tempo_atendimento'] = SecondToStrTime($row["tempo_atendimento"]); $row['retorno_abd'] = $row["retorno_abd"] ? $row["retorno_abd"] : '-'; $row['evento'] = $this->__statusEventos($row['evento']); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : '-'; $row['apelido'] = $row['apelido'] ? $row['apelido'] : '-'; $row['classificacao'] = $row['classificacao'] ? RemoveAcentos($row['classificacao']) : '-'; $row['pesquisa'] = $row['pesquisa'] ? RemoveAcentos($row['pesquisa']) : '-'; // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Total', '')); $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', 'Tipo', 'Protocolo', 'Origem', 'Destino', 'Duracao', 'Fila', 'Agente', 'Status', 'Retornada ABD.', ); $this->__classificacao ? $dadosCabecalio[] = 'Classificacao' : ''; $this->__pesquisa ? $dadosCabecalio[] = 'Pesquisa' : ''; $dadosField = array( 'calldate', 'tplg_descricao', 'protocolo', 'src', 'dst', 'tempo_atendimento', 'fila', 'apelido', 'evento', 'retorno_abd' ); $this->__classificacao ? $dadosField[] = 'classificacao' : ''; $this->__pesquisa ? $dadosField[] = 'pesquisa' : ''; /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['tempo_atendimento'] = SecondToStrTime($row["tempo_atendimento"]); $row['retorno_abd'] = $row["retorno_abd"] ? $row["retorno_abd"] : '-'; $row['evento'] = $this->__statusEventos($row['evento']); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : '-'; $row['apelido'] = $row['apelido'] ? $row['apelido'] : '-'; $row['classificacao'] = $row['classificacao'] ? RemoveAcentos($row['classificacao']) : '-'; $row['pesquisa'] = $row['pesquisa'] ? RemoveAcentos($row['pesquisa']) : '-'; // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Total'); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data Hora' => 'align="center"', 'Tipo' => 'align="center"', 'Protocolo' => 'align="center"', 'Origem' => 'align="center"', 'Destino' => 'align="center"', 'Duração' => 'align="center"', 'Fila' => 'align="center"', 'Agente' => 'align="center"', 'Status' => 'align="center"', 'Retornada ABD.' => 'align="center"', ); $this->__classificacao ? $dadosCabecalio['Classificação'] = 'align="center"' : ''; $this->__pesquisa ? $dadosCabecalio['Pesquisa'] = 'align="center"' : ''; $dadosField = array( 'calldate' => 'align="center"', 'tplg_descricao' => 'align="center"', 'protocolo' => 'align="center"', 'src' => 'align="center"', 'dst' => 'align="center"', 'tempo_atendimento' => 'align="center"', 'fila' => 'align="center"', 'apelido' => 'align="center"', 'evento' => 'align="center"', 'retorno_abd' => 'align="center"' ); $this->__classificacao ? $dadosField['classificacao'] = 'align="center"' : ''; $this->__pesquisa ? $dadosField['pesquisa'] = 'align="center"' : ''; /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $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("
%s
%s
", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['tempo_atendimento'] = SecondToStrTime($row["tempo_atendimento"]); $row['retorno_abd'] = $row["retorno_abd"] ? $row["retorno_abd"] : '-'; $row['evento'] = $this->__statusEventos($row['evento']); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : '-'; $row['apelido'] = $row['apelido'] ? $row['apelido'] : '-'; $row['classificacao'] = $row['classificacao'] ? $row['classificacao'] : '-'; $row['pesquisa'] = $row['pesquisa'] ? $row['pesquisa'] : '-'; // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Total%s%s%s%s%s%s%s'; $dataRel[] = sprintf($linha, ''); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio, $this->___agente, $this->__classificacao, $this->__pesquisa) = $_SESSION["SSstorageFiltros"]; $this->settype("L"); /** * TABELA DADOS PRINCIPAIS */ $dadosCabecalio = array( 'Data Hora' => 'C', 'Tipo' => 'C', 'Protocolo' => 'C', 'Origem' => 'C', 'Destino' => 'C', 'Duração' => 'C', 'Fila' => 'C', 'Agente' => 'C', 'Status' => 'C', 'Retornada ABD.' => 'C', ); $this->__classificacao ? $dadosCabecalio['Classificação'] = 'C' : ''; $this->__pesquisa ? $dadosCabecalio['Pesquisa'] = 'C' : ''; $dadosField = array( 'calldate' => 'C', 'tplg_descricao' => 'C', 'protocolo' => 'C', 'src' => 'C', 'dst' => 'C', 'tempo_atendimento' => 'C', 'fila' => 'C', 'apelido' => 'C', 'evento' => 'C', 'retorno_abd' => 'C' ); $this->__classificacao ? $dadosField['classificacao'] = 'C' : ''; $this->__pesquisa ? $dadosField['pesquisa'] = 'C' : ''; $dados = $this->GetData()[0]; $x = 0; foreach ($dados as $row) { $dados[$x]['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $dados[$x]['tempo_atendimento'] = SecondToStrTime($row["tempo_atendimento"]); $dados[$x]['retorno_abd'] = $row["retorno_abd"] ? $row["retorno_abd"] : '-'; $dados[$x]['evento'] = $this->__statusEventos($row['evento']); $dados[$x]['protocolo'] = $row['protocolo'] ? $row['protocolo'] : '-'; $dados[$x]['apelido'] = $row['apelido'] ? $row['apelido'] : '-'; $dados[$x]['classificacao'] = $row['classificacao'] ? $row['classificacao'] : '-'; $dados[$x]['pesquisa'] = $row['pesquisa'] ? $row['pesquisa'] : '-'; $x++; } $widthHeader = array(25, 28, 17, 17, 17, 17, 23, 18, 35, 20); $this->__classificacao ? $widthHeader[] = 30 : ''; $this->__pesquisa ? $widthHeader[] = 30 : ''; $totalizador = array('Total' , ''); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table1 = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totalizador, 1); $this->___dataRel = array($table1); } protected function getAgentes() { $sel = $this->__agente ? '' : 'selected'; $agentes = ""; return $agentes; } public function __statusEventos($status){ // 'COMPLETECALLER', 'COMPLETEAGENTRAMAL' $eventos = [ 'COMPLETAAGENT' => "ATENDIDA - DESL. AGENTE", 'COMPLETACALLERRAMAL' => "ATENDIDA - DESL. CLIENTE", 'COMPLETACALLER' => "ATENDIDA - DESL. CLIENTE", 'COMPLETECALLERRAMAL' => "ATENDIDA - DESL. CLIENTE", 'COMPLETEAGENT' => "ATENDIDA - DESL. AGENTE", 'COMPLETEAGENTRAMAL' => "ATENDIDA - DESL. AGENTE", 'COMPLETECALLER' => "ATENDIDA - DESL. CLIENTE", 'ABANDON' => "ABANDONADA", 'TRANSFER' => "TRANSFERIDA", 'BUSY' => "OCUPADA", ]; return $eventos[$status]; } 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'); } } $relChamadasGeral = new RelChamadasGeral($idProg, $dbcon, 1); $relChamadasGeral->ExecutaRelatorio(); ?>