___tempoDuracao = isset($_POST["tempoDuracao"]) ? $_POST["tempoDuracao"] : 1; $this->___dataIni = IsPostBack() ? $_POST['dataIni'] : date('d/m/Y') . " 00:00"; $this->___dataFim = IsPostBack() ? $_POST['dataFim'] : date('d/m/Y') . " 23:59"; } function ___ValidaForm() { parent::___ValidaForm(); if (!IsPostBack()) { return; } if (!$this->___tempoDuracao) { GeraExcept('Informe um tempo de duração!'); } } function ___FiltrosRelatorio() { if ($this->___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) { return sprintf("Data Inicial: %s Data Final: %s ", $this->___dataIni, $this->___dataFim); } $fltCsv = array(); $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, 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'); } /* * Personalise esta função se necessitar de outras opções de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= '' . ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
 Data Inicial Data Final Duração 
 
'; $filtro .= sprintf('Todos' . 'maior que(>0)' . 'Igual a 0 (= 0)', $this->___tempoDuracao == 1 ? 'checked' : '', $this->___tempoDuracao == 2 ? 'checked' : '', $this->___tempoDuracao == 3 ? 'checked' : ''); $filtro .= '
%s
'; /* * Guarda os filtros passados para recuperar na emiss�o dos relat?ios para impress�o. */ $_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = strlen($this->___dataIni) == 10 ? FormatDtMssql($this->___dataIni) . " 00:00": FormatDtMssql(substr($this->___dataIni, 0, 10)). substr($this->___dataIni, 10, 16); $dataFim = strlen($this->___dataFim) == 10 ? FormatDtMssql($this->___dataFim) . " 23:59": FormatDtMssql(substr($this->___dataFim, 0, 10)). substr($this->___dataFim, 10, 16); $duracao = $this->___tempoDuracao; $query = sprintf("SELECT a.uniqueid, a.calldate, a.src, a.dst, CASE WHEN(d.evento = 'ABANDON')THEN strtoint(d.param3) ELSE a.billsec END AS tempo_atendimento, d.evento, CASE WHEN(tplg_codigo in(33,34))THEN 'MÓVEL' ELSE c.nome_municipio END AS nome_municipio, c.uf, b.tplg_descricao FROM pbx_bilhetes a INNER JOIN pbx_tipo_ligacao b ON b.tplg_codigo = a.tipo_chamada INNER JOIN pbx_municipios c ON c.id = a.id_municipio LEFT JOIN pbx_eventos_dacs d ON d.uid2 = a.uniqueid AND d.evento IN('COMPLETEAGENT','COMPLETECALLER','ABANDON') LEFT JOIN pbx_usuarios e ON e.matricula = SUBSTRING(d.agente,7,4) WHERE b.tplg_tipo = 3 AND a.calldate::timestamp >= '%s' AND a.calldate::timestamp <= '%s' AND a.lastapp <> 'Transferred Call'", $dataIni, $dataFim); if ($duracao == 2) $query .= " AND a.billsec > 0 "; if ($duracao == 3) $query .= " AND a.billsec = 0 "; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { $dataRel = array(); $dataAgrup = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array( 'Tipo' => 'align="left"', 'Quantidade' => 'align="right"', 'Duracao' => 'align="right"', ); $dadosField = array( 'tplg_descricao' => 'align="left"', 'quantidade' => 'align="right"', 'tempo_atendimento' => 'align="right"', ); $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ $tipoLg = array(); $x = 1; foreach ($this->GetData()[0] as $row) { $chave = null; foreach ($tipoLg as $key => $value) { if ($value['tplg_descricao'] == $row['tplg_descricao']) { $chave = $key; break; } } if ($chave) { $tipoLg[$chave]['quantidade'] ++; $tipoLg[$chave]['tempo_atendimento'] += $row['tempo_atendimento']; } else { $tipoLg[$x]['tplg_descricao'] = $row['tplg_descricao']; $tipoLg[$x]['quantidade'] = 1; $tipoLg[$x]['tempo_atendimento'] += $row['tempo_atendimento']; $x++; } $somaTempo += $row["tempo_atendimento"]; $row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); $somaQuantidade ++; } foreach ($tipoLg as $rowData) { $linha = array(); $rowData["tplg_descricao"] = str_replace("Saída", "", $rowData["tplg_descricao"]); $rowData["tempo_atendimento"] = SecondToStrTime($rowData["tempo_atendimento"]); // Formata linha de dados. foreach ($dadosField as $keyA => $valorA) { $linha[] = $rowData["$keyA"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = $linha; $linha1 = array('Total', 'Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = GenerateCsvFromArray($linha1); $dataRel[] = $linha1; $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { $dataRel = array(); $dataAgrup = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ /* * Cria os filtros */ $linha1 = array('LABEL'); foreach ($filtro as $values) { list($label, $values) = explode(":", $values); $linha1[] = $label; } $dataRel[] = $linha1; $linha0 = array('DADOS'); foreach ($filtro as $values) { list($label, $values) = explode(":", $values); $linha0[] = $values; } $dataRel[] = $linha0; $dadosCabecalio = array('Tipo', 'Quantidade', 'Duracao'); $dadosField = array('tplg_descricao', 'quantidade', 'tempo_atendimento'); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ $tipoLg = array(); $x = 1; foreach ($this->GetData()[0] as $row) { $chave = null; foreach ($tipoLg as $key => $value) { if ($value['tplg_descricao'] == $row['tplg_descricao']) { $chave = $key; break; } } if ($chave) { $tipoLg[$chave]['quantidade'] ++; $tipoLg[$chave]['tempo_atendimento'] += $row['tempo_atendimento']; } else { $tipoLg[$x]['tplg_descricao'] = $row['tplg_descricao']; $tipoLg[$x]['quantidade'] = 1; $tipoLg[$x]['tempo_atendimento'] += $row['tempo_atendimento']; $x++; } $somaTempo += $row["tempo_atendimento"]; $row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); $somaQuantidade ++; } foreach ($tipoLg as $rowData) { $rowData["tplg_descricao"] = str_replace("Saída", "", $rowData["tplg_descricao"]); $rowData["tempo_atendimento"] = SecondToStrTime($rowData["tempo_atendimento"]); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $keyA) { $linha[] = $rowData["$keyA"]; } $dataRel[] = $linha; } $linha2 = array('LABEL', 'Total', 'Registros: ' . $somaQuantidade, 'Duracao: ' . SecondToStrTime($somaTempo)); $dataRel[] = $linha2; $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dadosCabecalio = array( 'Tipo' => 'align="center"', 'Quantidade' => 'align="right"', 'Duração' => 'align="right"', ); /* * Inicia o relat�rio. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linhaH = ''; foreach ($dadosCabecalio as $key => $value) { $linhaH .= sprintf("", $value, $key); } $linhaH .= ""; $dataRel[] = $linhaH; /* * 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; } $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ $dadosField = array(); $x = 1; foreach ($this->GetData()[0] as $row) { $chave = null; foreach ($dadosField as $key => $value) { if ($value['tplg_descricao'] == $row['tplg_descricao']) { $chave = $key; break; } } if ($chave) { $dadosField[$chave]['quantidade'] ++; $dadosField[$chave]['tempo_atendimento'] += $row['tempo_atendimento']; } else { $dadosField[$x]['tplg_descricao'] = $row['tplg_descricao']; $dadosField[$x]['quantidade'] = 1; $dadosField[$x]['tempo_atendimento'] += $row['tempo_atendimento']; $x++; } $somaTempo += $row["tempo_atendimento"]; $row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); $somaQuantidade ++; } foreach ($dadosField as $rowField) { $linkRel = sprintf("javaScript:NovaJanela('index.php?idProg=101&dataIni=%s&dataFim=%s&dur=%s&tipo=%s', 'Chamadas Entrantes', '850', '600', 'resizable=YES,scrollbars=YES')\"style=\"color:#000;", $this->___dataIni, $this->___dataFim, $this->___tempoDuracao,base64_encode($rowField['tplg_descricao'])); $linha .= ""; $linha .= sprintf("%s" . "%s" . "%s", $linkRel,$rowField['tplg_descricao'], $rowField['quantidade'], SecondToStrTime($rowField['tempo_atendimento'])); $linha .= ""; } $dataRel[] = $linha; /* * Linha de totalizacao. */ $linha = 'TotalRegistros: %sDuração: %s'; $dataRel[] = sprintf($linha, $somaQuantidade, SecondToStrTime($somaTempo)); /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; $somaTempo = 0; $somaQuantidade = 0; $x = 1; $dadosField = array(); $header = array( 'Tipo' => 'C', 'Quantidade' => 'R', 'Duração' => 'R' ); $dataHeader = array( 'tplg_descricao' => 'C', 'quantidade' => 'R', 'tempo_atendimento' => 'R' ); $widthHeader = array(65, 60, 65); foreach ($this->GetData()[0] as $row) { $chave = null; foreach ($dadosField as $key => $value) { if ($value['tplg_descricao'] == $row['tplg_descricao']) { $chave = $key; break; } } if ($chave) { $dadosField[$chave]['quantidade'] ++; $dadosField[$chave]['tempo_atendimento'] += $row['tempo_atendimento']; } else { $dadosField[$x]['tplg_descricao'] = $row['tplg_descricao']; $dadosField[$x]['quantidade'] = 1; $dadosField[$x]['tempo_atendimento'] += $row['tempo_atendimento']; $x++; } $somaTempo += $row["tempo_atendimento"]; $row["tempo_atendimento"] = SecondToStrTime($row["tempo_atendimento"]); $somaQuantidade ++; } foreach ($dadosField as $key => $valor) { $dadosField[$key]['tempo_atendimento'] = SecondToStrTime($valor['tempo_atendimento']); } $totaliza = array('Total', "Registros: " . $somaQuantidade, "Duração: " . SecondToStrTime($somaTempo)); $table1 = array($header, $dataHeader, $dadosField, $widthHeader, $totaliza, 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'); } } $relSaintes = new SaintesTipoLigacao($idProg, $dbcon, null); $relSaintes->ExecutaRelatorio(); ?>