___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuário. */ 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(); 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 operações de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $this->GetIncDac() ? $filtro .= '' : ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $this->GetIncDac() ? $filtro .= sprintf('', $dacs) : ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaData InicialData Final  
%s%s
'; /* * Guarda os filtros passados para recuperar na emissão dos relatórios 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); $dataCorte = GetDataRelatorio(); $query = "select agente, matricula, sum(tempo::bigint) as tempo, count(*) as quant from(select c.apelido as agente,c.matricula,a.billsec as tempo from pbx_bilhetes a,pbx_usuarios c, pbx_eventos_dacs d where c.matricula = substring(d.agente, 7, 4) and d.uid2 = a.uniqueid and d.evento in('COMPLETEAGENT','COMPLETECALLER','COMPLETAAGENT','COMPLETACALLER') and a.lastapp <> 'Transferred Call' --and a.data_bilhete >= '$dataCorte' and a.data_bilhete >= '$dataIni' and a.data_bilhete <= '$dataFim' and exists(select '' from pbx_bilhetes where data_bilhete = a.data_bilhete and accountcode = a.uniqueid) union all select c.apelido as agente,c.matricula,d.param4::bigint as tempo from pbx_bilhetes a, pbx_usuarios c, pbx_eventos_dacs d where c.matricula = substring(a.dstchannel, 7, 4) and d.uid2 = a.uniqueid and param4 <> '' and d.evento in('TRANSFER', 'TRANSFERORIG') and a.lastapp <> 'Transferred Call' --and a.data_bilhete < '$dataCorte' and a.data_bilhete >= '$dataIni' and a.data_bilhete <= '$dataFim' )as transf group by 1,2 order by 1 "; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { $dataRel = array(); $chmTotal = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array('Agente','Quantidade','TMA'); $dadosField = array('agente','quant','tma'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaReg = 0; $somaTempo = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg += $row['quant']; $somaTempo += $row['tempo']; $row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant'])); $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Geral:', $somaReg, SecondToStrTime(round($somaTempo/$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('Agente','Quantidade','TMA'); $dadosField = array('agente','quant','tma'); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaReg = 0; $somaTempo = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg += $row['quant']; $somaTempo += $row['tempo']; $row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant'])); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Geral: ', $somaReg, SecondToStrTime(round($somaTempo/$somaReg))); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Agente' => 'align="left"', 'Quantidade' => 'align="right"', 'TMA' => 'align="right"' ); $dadosField = array( 'agente' => 'align="left"', 'quant' => 'align="right"', 'tma' => 'align="right"' ); /* * 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("
Transferência por Agente
%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; $somaReg = 0; $somaTempo = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg += $row['quant']; $somaTempo += $row['tempo']; $row['agente'] = sprintf("%s",$row['matricula'], $this->___dataIni, $this->___dataFim,$row['agente']); $row['tma'] = SecondToStrTime(round($row['tempo']/$row['quant'])); $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } $dataRel[] = sprintf("Geral: $somaReg%s", SecondToStrTime(round($somaTempo/$somaReg))); $dataRel[] = ""; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; $dadosCabecalio = array( 'Agente' => 'C', 'Quantidade' => 'C', 'TMA' => 'C' ); $dadosField = array( 'agente' => 'C', 'quant' => 'C', 'tma' => 'C' ); $somaReg = 0; $somaTempo = 0; $x = 0; $dados = $this->GetData()[0]; /* * Linhas de dados. */ foreach ($dados as $row) { $somaReg += $row['quant']; $somaTempo += $row['tempo']; $dados[$x]['tma'] = SecondToStrTime(round($row['tempo']/$row['quant'])); $x++; } $widthHeader = array(60, 60, 60); $totaliza = array("Geral: ", $somaReg, SecondToStrTime(round($somaTempo/$somaReg))); $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totaliza, 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'); } } $relTransferAgente = new RelTrasfAgente($idProg, $dbcon, 0); $relTransferAgente->ExecutaRelatorio(); ?>