___opcao = isset($_GET["opcao"]) ? $_GET["opcao"] : ''; $this->___uraOpcao = isset($_GET["ura_opcao"]) ? $_GET["ura_opcao"] : ''; $this->___dataIni = isset($_GET["dataIni"]) ? $_GET["dataIni"] : date('d/m/Y'); $this->___dataFim = isset($_GET["dataFim"]) ? $_GET["dataFim"] : date('d/m/Y'); $this->___uraId = isset($_GET['ura_id']) ? $_GET['ura_id'] : 0; $_POST['btConsulta'] = 1; } public function ___ValidaForm() { if (!$_SESSION["SSstorageFiltros"]) { return; } } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuário. */ list($this->___dataIni, $this->___dataFim, $this->___opcao) = $_SESSION["SSstorageFiltros"]; $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; } $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'); } $filtro = ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
Impressão%s
'; $_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim, $this->___idUni); return sprintf($filtro, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $query = "SELECT calldate,umv_opcao, umv_acao, src, SUBSTRING(c.agente,7,4) AS matricula,apelido AS agente, param2 AS tempo_conversacao, CASE WHEN (param2 IS NOT NULL) THEN (billsec::int - param2::int) ELSE null END AS tempo_ura, billsec AS tempo_total FROM pbx_ura_movimento a INNER JOIN pbx_bilhetes b ON a.uniqueid = b.uniqueid LEFT JOIN pbx_eventos_dacs c ON a.uniqueid = c.uid2 AND evento IN('COMPLETEAGENT','COMPLETECALLER') LEFT JOIN pbx_usuarios d ON d.matricula = SUBSTRING(c.agente,7,4) WHERE umv_data >= '{$dataIni}' AND umv_data <= '{$dataFim}' AND umv_ura_opcao = '{$this->___uraOpcao}' AND umv_opcao = '{$this->___opcao}' AND umv_ura_id = '{$this->___uraId}' ORDER BY 1,3"; $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('Data/Hora','Origem','Destino','Agente','Tempo Conversacao','Tempo Ura','Tempo Total'); $dadosField = array('calldate','src','umv_tipo','agente','tempo_conversacao','tempo_ura','tempo_total'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $totalUra = 0; $totalConversa = 0; $totalTotal = 0; $totalQuant = 0; foreach ($this->GetData()[0] as $row) { $totalQuant ++; $totalUra += $row['tempo_ura']; $totalConversa += $row['tempo_conversacao']; $totalTotal += $row['tempo_total']; $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['umv_tipo'] = strtoupper($row['umv_opcao']) . " > " . $row['umv_acao']; $row['agente'] = $row['agente'] ? $row['agente'] : '-'; $row['tempo_conversacao'] = $row['tempo_conversacao'] ? SecondToStrTime($row['tempo_conversacao']) : '-'; $row['tempo_ura'] = $row['tempo_ura'] ? SecondToStrTime($row['tempo_ura']) : '-'; $row['tempo_total'] = $row['tempo_total'] ? SecondToStrTime($row['tempo_total']) : '-'; // Formata linha de dados. $linha = array(); foreach ($dadosField as $value) { $linha[] = $row["$value"]; } $dataRel[] = GenerateCsvFromArray($linha); if (count($this->GetData()[0]) == $totalQuant) { $dataRel[] = GenerateCsvFromArray(array("Registros: ", $totalQuant, '','', 'Conversacao: '.SecondToStrTime($totalConversa), 'Ura: '.SecondToStrTime($totalUra), 'Total: '.SecondToStrTime($totalTotal))); } } $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','Destino','Agente','Tempo Conversacao','Tempo Ura','Tempo Total'); $dadosField = array('calldate','src','umv_tipo','agente','tempo_conversacao','tempo_ura','tempo_total'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $totalUra = 0; $totalConversa = 0; $totalTotal = 0; $totalQuant = 0; foreach ($this->GetData()[0] as $row) { $totalQuant ++; $totalUra += $row['tempo_ura']; $totalConversa += $row['tempo_conversacao']; $totalTotal += $row['tempo_total']; $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['umv_tipo'] = strtoupper($row['umv_opcao']) . " > " . $row['umv_acao']; $row['agente'] = $row['agente'] ? $row['agente'] : '-'; $row['tempo_conversacao'] = $row['tempo_conversacao'] ? SecondToStrTime($row['tempo_conversacao']) : '-'; $row['tempo_ura'] = $row['tempo_ura'] ? SecondToStrTime($row['tempo_ura']) : '-'; $row['tempo_total'] = $row['tempo_total'] ? SecondToStrTime($row['tempo_total']) : '-'; $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; if (count($this->GetData()[0]) == $totalQuant) { $dataRel[] = array('LABEL', "Registros: ", $totalQuant, '','', 'Conversacao: '.SecondToStrTime($totalConversa), 'Ura: '.SecondToStrTime($totalUra), 'Total: '.SecondToStrTime($totalTotal)); } } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data/Hora' => 'align="center"', 'Origem' => 'align="center"', 'Destino' => 'align="center"', 'Agente' => 'align="center"', 'Tempo Conversação' => 'align="center"', 'Tempo Ura' => 'align="center"', 'Tempo Total' => 'align="center"' ); $dadosField = array( 'calldate' => 'align="center"', 'src' => 'align="center"', 'umv_tipo' => 'align="center"', 'agente' => 'align="center"', 'tempo_conversacao' => 'align="center"', 'tempo_ura' => 'align="center"', 'tempo_total' => 'align="center"' ); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $dataRel[] = ""; $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("
Relatório URA
%s
%s
", count($dadosCabecalio) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $totalUra = 0; $totalConversa = 0; $totalTotal = 0; $totalQuant = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $totalQuant ++; $totalUra += $row['tempo_ura']; $totalConversa += $row['tempo_conversacao']; $totalTotal += $row['tempo_total']; $row['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $row['umv_tipo'] = strtoupper($row['umv_opcao']) . " > " . $row['umv_acao']; $row['agente'] = $row['agente'] ? $row['agente'] : '-'; $row['tempo_conversacao'] = $row['tempo_conversacao'] ? SecondToStrTime($row['tempo_conversacao']) : '-'; $row['tempo_ura'] = $row['tempo_ura'] ? SecondToStrTime($row['tempo_ura']) : '-'; $row['tempo_total'] = $row['tempo_total'] ? SecondToStrTime($row['tempo_total']) : '-'; $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'Registro(s): %sConversação: %sUra: %sTotal: %s'; $dataRel[] = sprintf($linha, $totalQuant,SecondToStrTime($totalConversa),SecondToStrTime($totalUra),SecondToStrTime($totalTotal)); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; $dadosCabecalio = array( 'Data/Hora' => 'C', 'Origem' => 'C', 'Destino' => 'C', 'Agente' => 'C', 'Tempo Conversação' => 'C', 'Tempo Ura' => 'C', 'Tempo Total' => 'C' ); $dadosField = array( 'calldate' => 'C', 'src' => 'C', 'umv_tipo' => 'C', 'agente' => 'C', 'tempo_conversacao' => 'C', 'tempo_ura' => 'C', 'tempo_total' => 'C' ); $totalUra = 0; $totalConversa = 0; $totalTotal = 0; $dados = $this->GetData()[0]; $x = 0; foreach ($dados as $row) { $totalUra += $row['tempo_ura']; $totalConversa += $row['tempo_conversacao']; $totalTotal += $row['tempo_total']; $dados[$x]['calldate'] = date('d/m/Y H:i:s', strtotime($row['calldate'])); $dados[$x]['umv_tipo'] = strtoupper($row['umv_opcao']) . " > " . $row['umv_acao']; $dados[$x]['agente'] = $row['agente'] ? $row['agente'] : '-'; $dados[$x]['tempo_conversacao'] = $row['tempo_conversacao'] ? SecondToStrTime($row['tempo_conversacao']) : '-'; $dados[$x]['tempo_ura'] = $row['tempo_ura'] ? SecondToStrTime($row['tempo_ura']) : '-'; $dados[$x]['tempo_total'] = $row['tempo_total'] ? SecondToStrTime($row['tempo_total']) : '-'; $x++; } $totalizador = array("Registros: $x", '', '', '', 'Conversão: ' . SecondToStrTime($row['tempo_conversacao']),'Ura: '.SecondToStrTime($row['tempo_ura']), 'Total: '.SecondToStrTime($row['tempo_total'])); $widthHeader = array(35, 35, 25, 25, 25, 25, 25); $table = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totalizador, 0); $this->___dataRel = array($table); } public function ExecutaRelatorio() { global $jsStartup, $jsJQuery, $smarty; try { $this->___FiltrosRelatorio(); /* * 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'); } } $relUraDesempenhoDetalhes = new RelUraDesempenhoDetalhes($idProg, $dbcon, 0); $relUraDesempenhoDetalhes->ExecutaRelatorio();