___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___origem = isset($_POST["origem"]) ? $_POST["origem"] : ''; } 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"'; /* * 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 .= sprintf('', $this->___origem); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final Origem 
%s%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); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtHoraBD($this->___dataFim); $dac = $this->___dac; $origem = soNumero($this->___origem); $query = "SELECT FILA, ORIGEM ,COUNT(QTDE) AS QTDE ,SUM (TEMPO_ATENDE) AS TEMPO_ATENDE ,SUM (TEMPO_TRANSF) AS TEMPO_TRANSF FROM (select b.fila, case when(coalesce(a.src, '') = '')then 'NI*' else a.src end as origem, a.uniqueid as qtde, (case when(b.evento in('COMPLETEAGENT','COMPLETECALLER', 'COMPLETAAGENT','COMPLETACALLER'))then strtoint(param2) else 0 end) as tempo_atende, (case when(exists(select * from pbx_bilhetes where data_bilhete = a.data_bilhete and accountcode = a.uniqueid ))then a.billsec else 0 end) as tempo_transf from pbx_bilhetes a, pbx_eventos_dacs b where b.uid2 = a.uniqueid and a.id_bilhetes = (select max (l.id_bilhetes) from pbx_bilhetes l where l.uniqueid = a.uniqueid and l.lastapp <> 'Transferred Call' ) and b.evento in('COMPLETEAGENT','COMPLETECALLER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFER', 'TRANSFERORIG') and a.lastapp <> 'Transferred Call' and a.data_bilhete >= '$dataIni' and a.data_bilhete <= '$dataFim' and b.fila = (select nome from pbx_dacs where id = '$dac')"; if ($origem) { $query .= " and a.src like '%$origem%' \n"; } $query .= " ) AS RECHAMADAS GROUP BY FILA, ORIGEM having count(*) > 1 ORDER BY 3 desc"; $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('Origem', 'Quantidade', 'TMA', 'Tempo'); $dadosField = array('origem', 'qtde', 'tma', 'tempo_atende'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); foreach ($this->GetData()[0] as $row) { $row['tma'] = SecondToStrTime(round($row['tempo_atende']/$row['qtde'])); $row['tempo_atende'] = SecondToStrTime($row['tempo_atende']); $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$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('Origem', 'Quantidade', 'TMA', 'Tempo'); $dadosField = array('origem', 'qtde', 'tma', 'tempo_atende'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; foreach ($this->GetData()[0] as $row) { $row['tma'] = SecondToStrTime(round($row['tempo_atende']/$row['qtde'])); $row['tempo_atende'] = SecondToStrTime($row['tempo_atende']); $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Origem' => 'align="center"', 'Quantidade' => 'align="center"', 'TMA' => 'align="center"', 'Tempo' => 'align="center"' ); $dadosField = array( 'origem' => 'align="center"', 'qtde' => 'align="center"', 'tma' => 'align="center"', 'tempo_atende' => 'align="center"' ); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; $linha .= ""; $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Rechamadas
%s
", count(1) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $linhaC = ""; foreach ($dadosCabecalio as $key => $value) { $linhaC .= sprintf("%s", $value, $key); } $linhaC .= ""; $dataRel[] = $linhaC; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $row['origem'] = ocultarTelefone($row['origem']); $row['tma'] = SecondToStrTime(round($row['tempo_atende']/$row['qtde'])); $row['tempo_atende'] = SecondToStrTime($row['tempo_atende']); $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; $dadosCabecalio = array( 'Origem' => 'C', 'Quantidade' => 'C', 'TMA' => 'C', 'Tempo' => 'C' ); $dadosField = array( 'origem' => 'C', 'qtde' => 'C', 'tma' => 'C', 'tempo_atende' => 'C' ); $x = 0; $dados = $this->GetData()[0]; /* * Linhas de dados. */ foreach ($dados as $row) { $dados[$x]['tma'] = SecondToStrTime(round($row['tempo_atende']/$row['qtde'])); $dados[$x]['tempo_atende'] = SecondToStrTime($row['tempo_atende']); $x++; } $widthHeader = array(45, 45, 45, 45); $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, 0, 0); $this->___dataRel = array($table); } 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'); } } $relRechamadas = new RelRechamadas($idProg, $dbcon, 1); $relRechamadas->ExecutaRelatorio(); ?>