___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___classificacao = isset($_POST['listaClas']) ? $_POST['listaClas'] : 0; $this->___classItem = isset($_POST['listaItem']) ? $_POST['listaItem'] : 0; $this->___agente = isset($_POST["listaAgente"]) ? $_POST["listaAgente"] : null; } 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) = $_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"'; if ($this->___dataIni && $this->___dataFim) { $agentes = $this->retornaAgente(); } /* * Personalise esta função se necessitar de outras operações de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $this->GetIncDac() ? $filtro .= '' : ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ global $dbcon; $filtro .= ''; $this->GetIncDac() ? $filtro .= sprintf('', $dacs) : ''; $filtro .= ''; $filtro .= ''; $filtro .= ""; $filtro .= sprintf('', GetClassificacao($dbcon, $this->___classificacao, $this->___dac)); $filtro .= sprintf('', GetItem($dbcon, $this->___classificacao, $this->___classItem)); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Agente Classificação Classificação Item  
%s$agentes%s%s%s
'; /* * Guarda os filtros passados para recuperar na emissão dos relatórios para impressão. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $dac = $this->___dac; $classificacao = $this->___classificacao; $classificaItem = $this->___classItem; $agente = $this->___agente ? $this->___agente : 0; $query = "SELECT calldate, apelido, src AS origem, dst AS destino, f.nome, clas_descricao, clit_descricao,tplg_descricao, CASE WHEN (g.conf_uid <> '' AND g.conf_discado = 1) THEN 'S' ELSE 'N' END AS discador FROM pbx_bilhetes a INNER JOIN pbx_tipo_ligacao h ON h.tplg_codigo = a.tipo_chamada INNER JOIN pbx_classifica_reg b ON a.uniqueid = b.id_bilhetes AND a.calldate = (SELECT MAX(calldate) FROM pbx_bilhetes WHERE uniqueid = b.id_bilhetes) INNER JOIN pbx_classifica_atendimento c ON c.clas_id = b.clas_id INNER JOIN pbx_classifica_item d ON d.clit_id = b.clit_id INNER JOIN pbx_usuarios e ON e.matricula = b.matricula INNER JOIN pbx_dacs f ON f.id = b.id_dac LEFT JOIN pbx_campanha_contato_fone g ON a.uniqueid = g.conf_uid WHERE data_bilhete >= '%s' AND data_bilhete <= '%s' AND a.lastapp <> 'Transferred Call' AND b.id_dac = %s"; if($classificacao){ $query .= "AND b.clas_id = $classificacao"; } if($classificaItem){ $query .= "AND b.clit_id = $classificaItem"; } if($agente){ $query .= "AND apelido = '$agente'"; } $query .= "ORDER BY calldate"; $query = sprintf($query,$dataIni, $dataFim, $dac); $subQuery = sprintf("SELECT count(1) as chmd FROM pbx_bilhetes a INNER JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS') INNER JOIN pbx_usuarios c ON c.matricula = substring(b.agente, 7, 4) INNER JOIN pbx_dacs d ON d.nome = b.fila WHERE data_bilhete >= '%s' AND data_bilhete <= '%s' AND d.id = %s AND a.lastapp <> 'Transferred Call'",$dataIni, $dataFim, $dac); $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); $subResult = $this->___GetQuery($subQuery); $subRow = pg_fetch_assoc($subResult); $this->SetData($subRow ? $subRow : array()); $this->SetData($this->___agente ? $this->___agente : 0); } protected function ___PreparaCsv() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array( 'Data/Hora', 'Origem', 'Agente', 'Classificacao', 'Item', 'Tipo', 'Discador', ); $dadosField = array( 'calldate', 'origem', 'apelido', 'clas_descricao', 'clit_descricao', 'tplg_descricao', 'discador', ); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg ++; $row['clit_descricao'] = RemoveAcentos($row['clit_descricao']); $row['clas_descricao'] = RemoveAcentos($row['clas_descricao']); $row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0]; $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '','', 'Registros: ' . $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', 'Agente', 'Classificacao', 'Item', 'Tipo', 'Discador' ); $dadosField = array( 'calldate', 'origem', 'apelido', 'clas_descricao', 'clit_descricao', 'tplg_descricao', 'discador' ); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaChmTotal = 0; foreach ($this->GetData()[0] as $row) { $somaChmTotal += $row['chmd']; } $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg ++; $row['clit_descricao'] = RemoveAcentos($row['clit_descricao']); $row['clas_descricao'] = RemoveAcentos($row['clas_descricao']); $row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0]; $row['calldate'] = date('d/m/Y H:i:s',strtotime($row['calldate'])); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '','', 'Registros: ' . $somaReg); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data/Hora' => 'align="center"', 'Origem' => 'align="left"', 'Agente' => 'align="left"', 'Classificação' => 'align="left"', 'Item' => 'align="center"', 'Tipo' => 'align="center"', 'Discador' => 'align="Center"', ); $dadosField = array( 'calldate' => 'align="center"', 'origem' => 'align="left"', 'apelido' => 'align="left"', 'clas_descricao' => 'align="left"', 'clit_descricao' => 'align="center"', 'tplg_descricao' => 'align="center"', 'discador' => '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) - 1, (!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["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"])); $row['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0]; $row['origem'] = ocultarTelefone($row['origem']); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Total [ Chamadas Periodo ]: %sRegistros: %s'; $dataRel[] = sprintf($linha, $this->GetData()[1]['chmd'], $somaReg); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ //HEADER DA TABELA DO PDF -> DADOS EM ARRAY $header = array( 'Data/Hora' => 'C', 'Origem' => 'C', 'Agente' => 'C', 'Classificação' => 'C', 'Item' => 'C', 'Tipo' => 'C', 'Discador' => 'C', ); $dataHeader = array( 'calldate' => 'C', 'origem' => 'C', 'apelido' => 'C', 'clas_descricao' => 'C', 'clit_descricao' => 'C', 'tplg_descricao' => 'C', 'discador' => 'C', ); $somaReg = 0; $dados = array(); $x = 0; foreach ($this->GetData()[0] as $row) { $somaReg ++; $dados[$x]["clas_descricao"] = $row["clas_descricao"]; $dados[$x]["clit_descricao"] = $row["clit_descricao"]; $dados[$x]["origem"] = $row['origem']; $dados[$x]["apelido"] = $row['apelido']; $dados[$x]["discador"] = $row["discador"]; $dados[$x]["calldate"] = date('d/m/Y H:i:s',strtotime($row['calldate'])); $dados[$x]['tplg_descricao'] = explode(' ', $row['tplg_descricao'])[0]; $x++; } $widthHeader = array(30, 15, 30, 40, 40, 20,15); $totalizador = array('Total Chamadas: ' . $this->GetData()[1]['chmd'], '', '','', 'Registros: ' . $somaReg,'','',); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); $this->___dataRel = array($table); } protected function retornaAgente() { global $dbcon; $codSel = $this->GetData()[2] ? $this->GetData()[2] : ''; $agentes = ""; return $agentes; } 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'); } } $relClassDetalhes = new RelClassificacaoDetalhes($idProg, $dbcon, 1); $relClassDetalhes->ExecutaRelatorio(); /* * ************************************************************************* * BACKUP DAS QUERYS ANTIGAS * ************************************************************************* $query = "select distinct c.matricula, c.apelido as nome from pbx_classifica_reg a, pbx_bilhetes b, pbx_usuarios c where b.uniqueid = a.id_bilhetes and c.matricula = a.matricula and b.lastapp <> 'Transferred Call' and a.id_dac = $idDac and b.data_bilhete >= '$dataInicial' and b.data_bilhete <= '$dataFinal' order by 2 "; if ($total) { $query = "select count(1) as chmd from pbx_bilhetes d, pbx_eventos_dacs e, pbx_usuarios f, pbx_dacs a where e.uid2 = d.uniqueid and e.evento in('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL','BUSY','NOANSWER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','BUSYS','NOANSWERS') and a.nome = e.fila and f.matricula = substring(e.agente, 7, 4) and d.lastapp <> 'Transferred Call' and coalesce(a.id, 0) = case when($dac > 0)then $dac else coalesce(a.id, 0) end and b.data_bilhete >= '$dataInicial' and b.data_bilhete <= '$dataFinal' "; } else { $query .= "from pbx_classifica_reg a, pbx_classifica_atendimento b, pbx_classifica_item c, pbx_bilhetes d, pbx_usuarios e, pbx_dacs f where b.clas_id = a.clas_id and c.clit_id = a.clit_id and d.uniqueid = a.id_bilhetes and e.matricula = a.matricula and f.id = a.id_dac and d.lastapp <> 'Transferred Call' and coalesce(a.id_dac, 0) = case when($dac > 0)then $dac else coalesce(a.id_dac, 0) end and b.data_bilhete >= '$dataInicial' and b.data_bilhete <= '$dataFinal'"; } */ ?>