___matricula = isset($_POST["matricula"]) ? $_POST["matricula"] : ''; $this->___usuario = isset($_POST["apelido"]) ? $_POST["apelido"] : ''; $this->___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() { global $dbcon; if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sess�o do usu�rio. */ list($this->___dataIni, $this->___dataFim, $this->___matricula, $this->___usuario, $this->___tempoDuracao) = $_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 .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= sprintf('', $this->___matricula); $filtro .= sprintf('', $this->___usuario); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
 Data Inicial Data Final Conta Usuário 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); $matricula = $this->___matricula; $apelido = $this->___usuario; $duracao = $this->___tempoDuracao; $query = "select distinct src, c.conta, dst, calldate, (case when a.lastdata like ('CONTASENHA%') then 0 else (a.billsec) end) as billsec, 0.0 as valor, b.apelido from pbx_bilhetes a, pbx_usuarios_cs b, pbx_bilhetes_complemento c where c.uniqueid2 = a.uniqueid and b.id = c.id_usuario and not exists(select '' from pbx_eventos_dacs where uid2 = a.uniqueid) and coalesce(trim(c.dac), '') = '' and a.id_bilhetes = (select max (l.id_bilhetes) from pbx_bilhetes l where l.uniqueid = a.uniqueid and l.lastapp <> 'Transferred Call' ) and a.calldate::timestamp >= '$dataIni' and a.calldate::timestamp <= '$dataFim' "; if (!empty($matricula)) { $query .= " and b.matricula = '$matricula' "; } else if (!empty($apelido)) { $query .= " and b.apelido like '%$apelido%' "; } if ($duracao == 2) $query .= " and a.billsec > 0 and a.lastdata not like ('CONTASENHA%') "; if ($duracao == 3) $query .= " and (a.billsec = 0 or a.lastdata like ('CONTASENHA%'))"; $query .= " ORDER BY src"; //if(IsAdmin()) echo $sql; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { $nomeDac = ""; $dataRel = array(); $dataAgrup = array(); $filtro = $this->___FiltrosRelatorio(); $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array( 'Ramal' => 'align="center"', 'Conta' => 'align="center"', 'Usuario' => 'align="center"', 'Destino' => 'align="left"', 'Data/Hora' => 'align="center"', 'Duracao' => 'align="right"' ); $dadosField = array( 'src' => 'align="center"', 'conta' => 'align="center"', 'apelido' => 'align="center"', 'dst' => 'align="left"', 'calldate' => 'align="center"', 'billsec' => 'align="right"' ); $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaTempo = 0; $somaQuantidade = 0; /* * Inicia o relat�rio. */ foreach ($this->GetData()[0] as $row) { $somaTempo += $row["billsec"]; $somaQuantidade ++; $row["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"])); $row["billsec"] = SecondToStrTime($row["billsec"]); $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = $linha; $linha1 = array('Total', '', '', 'Registros: '.$somaQuantidade,'', 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 */ $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('Ramal', 'Conta', 'Usuario', 'Destino', 'Data/Hora', 'Duracao'); $dadosField = array('src', 'conta', 'apelido', 'dst', 'calldate', 'billsec'); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaTempo = 0; $somaQuantidade = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $somaTempo += $row["billsec"]; $somaQuantidade ++; $row["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"])); $row["billsec"] = SecondToStrTime($row["billsec"]); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $linha = array('LABEL', 'Total', '', '', 'Registros: '.$somaQuantidade,'', SecondToStrTime($somaTempo)); $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $nomeDac = ""; $dataRel = array(); $dataAgrup = array(); $dadosCabecalio = array('Ramal' => 'align="center"', 'Conta' => 'align="center"', 'Usuário' => 'align="center"', 'Destino' => 'align="left"', 'Data/Hora' => 'align="center"', 'Duração' => 'align="right"'); $dadosField = array('src' => 'align="center"', 'conta' => 'align="center"', 'apelido' => 'align="center"', 'dst' => 'align="left"', 'calldate' => 'align="center"', 'billsec' => 'align="right"'); /* * 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 (!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. */ foreach ($this->GetData()[0] as $row) { $somaTempo += $row["billsec"]; $somaQuantidade ++; $row['dst'] = ocultarTelefone($row['dst']); $row["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"])); $row["billsec"] = SecondToStrTime($row["billsec"]); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * Linha de totalizacao. */ $linha = 'TotalRegistros: %s%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"]; $dados = array(); $x = 0; $somaQtd = 0; foreach ($this->GetData()[0] as $row) { $dados[$x]["calldate"] = date('d/m/Y H:i:s', strtotime($row["calldate"])); $dados[$x]["src"] = $row["src"]; $dados[$x]["dst"] = $row["dst"]; $dados[$x]["conta"] = $row["conta"]; $dados[$x]["apelido"] = $row["apelido"]; $dados[$x]["billsec"] = SecondToStrTime($row["billsec"]); $somaTempo += $row["billsec"]; $somaQtd ++; $x++; } //HEADER DA TABELA DO PDF -> DADOS EM ARRAY $header = array( 'Ramal' => 'C', 'Conta' => 'C', 'Usuário' => 'C', 'Destino' => 'L', 'Data/Hora' => 'C', 'Duração' => 'R' ); $dataHeader = array( 'src' => 'C', 'conta' => 'C', 'apelido' => 'C', 'dst' => 'L', 'calldate' => 'C', 'billsec' => 'R' ); $widthHeader = array(20, 30, 35, 35, 35, 35); $totaliza = array('Total', '','', "Registros: " . $somaQtd, '', "Duração: " . SecondToStrTime($somaTempo)); //Monta o array para passar para o prepara; Necessário passar 6 parametros $table1 = array($header, $dataHeader, $dados, $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 SaintesConta($idProg, $dbcon, null); $relSaintes->ExecutaRelatorio(); ?>