___dac = isset($_REQUEST['listaDacs']) ? $_REQUEST['listaDacs'] : ''; $this->___tipo = isset($_REQUEST['tipo']) ? $_REQUEST['tipo'] : 'TRANSBORDANDO'; $this->___dataIni = isset($_POST['dataIni']) ? $_POST['dataIni'] : date('d/m/Y'); $this->___dataFim = isset($_POST['dataFim']) ? $_POST['dataFim'] : date('d/m/Y'); $this->___modo = isset($_GET['window']) ? $_GET['window'] : 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->___tipo) = $_SESSION["SSstorageFiltros"]; $fltCsv = array(); if ($this->GetIncDac()) { $fltCsv[] = "Fila:" . $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, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, 'prt-xls.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, 'prt-pdf.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, 'prt-csv.png'); } /* * Rotulos. */ if ($_GET['window']) { /* * Personalise esta função se necessitar de outras opções de filtro. */ $filtro = ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= "'; $filtro .= ''; $filtro .= ''; $filtro .= ''; } else { $filtro = '
DacData Inicial Data Final  

{$this->___dac}

"; $filtro .= '

%s

%s

%s
'; $filtro .= ''; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) { $filtro .= ""; } $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; } $filtro .= '
FilaData InicialData Final Tipo Transbordo  
$dacs
'; $filtro .= sprintf('Entrada  ' . 'Saída  ', $this->___tipo == 'TRANSBORDADO' ? 'checked' : '', $this->___tipo == 'TRANSBORDANDO' ? 'checked' : ''); $filtro .= '
%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->___tipo); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $dac = ($this->___dac == 'TODOS') ? '' : $this->___dac; $tipo = ($this->___tipo == 'TRANSBORDANDO') ? 'S' : 'E'; $query = "select a.uniqueid, a.calldate, a.billsec as duracao, a.src, a.dst, c.fila, b.evento, c.fila || (case when(c.trbd_tipo = 'S')then ' >> ' else ' << ' end ) || trbd_origem_destino as tipo, case when(exists(select '' from pbx_eventos_dacs where fila = c.fila and uid2 = a.uniqueid and evento in('COMPLETEAGENT','COMPLETECALLER','TRANSFER')))then 'ATENDIDA' when(a.billsec > 0 )then 'ATENDIDA' else 'ABANDONADA' end as status, trbd_tipo from pbx_bilhetes a inner join pbx_eventos_dacs b on a.uniqueid = b.uid2 inner join pbx_eventos_transbordo c on c.uniqueid = a.uniqueid where c.data_reg::date >= '$dataIni' and c.data_reg::date <= '$dataFim' and b.evento = 'TRANSBORDANDO' "; if($tipo){ $query .= " and trbd_tipo = '{$tipo}' "; } if ($dac && $_GET['window']) { $query .= " and c.fila = '{$dac}' "; } else if($dac){ $query .= " and c.fila = (SELECT nome FROM pbx_queues_grupos WHERE id = '{$dac}') "; } $query .= "order by b.evento, a.calldate;"; $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', 'Fila', 'Origem', 'Destino', 'Duracao', 'Tipo Transbordo', 'Direcao', 'Status'); $dadosField = array('calldate', 'fila', 'src', 'dst', 'duracao', 'trbd_tipo', 'tipo', 'status'); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaReg = 0; $somaDuracao = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $somaDuracao += $row['duracao']; $row['src'] = ocultarTelefone($row['src']); $row['duracao'] = SecondToStrTime($row['duracao']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Saída'; // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Total Chamadas: ', $somaReg, '', 'Duracao Total: ', SecondToStrTime($somaDuracao))); $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', 'Fila', 'Origem', 'Destino', 'Duracao', 'Tipo Transbordo', 'Direcao', 'Status'); $dadosField = array('calldate', 'fila', 'src', 'dst', 'duracao', 'trbd_tipo', 'tipo', 'status'); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaReg = 0; $somaDuracao = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $somaDuracao += $row['duracao']; $row['src'] = ocultarTelefone($row['src']); $row['duracao'] = SecondToStrTime($row['duracao']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Saída'; // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Total Chamadas: ', $somaReg, '', 'Duracao Total: ', SecondToStrTime($somaDuracao)); $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data/Hora' => 'align="center"', 'Fila' => 'align="center"', 'Origem' => 'align="center"', 'Destino' => 'align="center"', 'Duração' => 'align="center"', 'Tipo Transbordo' => 'align="center"', 'Direção' => 'align="center"', 'Status' => 'align="center"' ); $dadosField = array( 'calldate' => 'align="center"', 'fila' => 'align="center"', 'src' => 'align="center"', 'dst' => 'align="center"', 'duracao' => 'align="center"', 'trbd_tipo' => 'align="center"', 'tipo' => 'align="center"', 'status' => '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 (!$this->___modo) { 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; } } $somaReg = 0; $somaDuracao = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaReg++; $somaDuracao += $row['duracao']; $row['src'] = ocultarTelefone($row['src']); $row['duracao'] = SecondToStrTime($row['duracao']); $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['trbd_tipo'] = $row['trbd_tipo'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Saída'; // 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: %sDuração Total: %s'; $dataRel[] = sprintf($linha, $somaReg, SecondToStrTime($somaDuracao)); /* * 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', 'Fila' => 'C', 'Origem' => 'C', 'Destino' => 'C', 'Duração' => 'C', 'Tipo Transbordo' => 'C', 'Direção' => 'C', 'Status' => 'C' ); $dataHeader = array( 'calldate' => 'C', 'fila' => 'C', 'src' => 'C', 'dst' => 'C', 'duracao' => 'C', 'trbd_tipo' => 'C', 'tipo' => 'C', 'status' => 'C', ); $somaReg = 0; $dados = $this->GetData()[0]; $somaDuracao = 0; $x = 0; foreach ($dados as $row) { $somaReg++; $somaDuracao += $row['duracao']; $dados[$x]['src'] = ocultarTelefone($row['src']); $dados[$x]['duracao'] = SecondToStrTime($row['duracao']); $dados[$x]['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $dados[$x]['evento'] = $row['evento'] == 'E' ? 'Transbordo Entrada' : 'Transbordo Saída'; $x++; } $widthHeader = array(25, 25, 21, 21, 15, 25, 43, 20); $totalizador = array('Total Chamadas: ' . $somaReg, '', '', '', '', 'Duração Total: ', SecondToStrTime($somaDuracao), ''); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table1 = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); $this->___dataRel = array($table1); } 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'); } } $relTransbordo = new RelTransbordo($idProg, $dbcon, 1); $relTransbordo->ExecutaRelatorio();