___contrato = isset($_POST["contr_id"]) ? $_POST["contr_id"] : 0; $this->___empresa = isset($_POST["listaEmpresas"]) ? $_POST["listaEmpresas"] : 0; $this->___departamento = isset($_POST["listaDeptos"]) ? $_POST["listaDeptos"] : 0; $this->___conta = isset($_POST['conta']) ? $_POST['conta'] : ''; } function ___ValidaForm() { parent::___ValidaForm(); if ($this->___contrato < 0) { GeraExcept('Informe o contrato!'); } } function ___FiltrosRelatorio() { global $dbcon; $empresas = GetEmpresas($dbcon, $this->___empresa, '', 1, 0, 'Todos'); $departamentos = GetDeptos($dbcon, $this->___empresa, $this->___departamento, "", 1, 1, 'Todos'); if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessao do usuario. */ 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'); } /* * Personalise esta funcao se necessitar de outras opnioes de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= ""; $filtro .= ""; $filtro .= ''; $filtro .= ''; $filtro .= sprintf('', $this->___conta); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
Empresa Departamento Data Inicial Data Final Conta  
$departamentos%s
'; /* * Guarda os filtros passados para recuperar na emissao dos relatoios para impressao. */ $_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); $conta = $this->___conta; $empresa = $this->___empresa; $depto = $this->___departamento; $query = "select a.trr_id, a.oper_id_dest, a.oper_numero_dest, a.uniqueid, a.trr_link, a.trr_data, a.trr_origem, a.trr_destino, a.trr_inicio, a.trr_fim, a.trr_duracao, a.trr_preco, a.trr_vc, a.trr_preco_tipo, a.trr_tipo_opera, a.trr_sentido_chamada, a.trr_tarifa_zero, a.trr_conta_senha, a.trr_conta, a.trr_vc_cad, a.trr_vc_ext,a.trr_preco_total, b.oper_nome, coalesce(e.id, 0) as id_empresa, coalesce(e.nome, 'NI') as nome_empresa, coalesce(f.id,0) as id_depto, coalesce(f.nome_depto, 'NI') as nome_depto, case when(substring(a.trr_destino,1,4) = '0800')then 'Gratuito' else g.ttp_descricao end as ttp_descricao, (a.trr_duracao / 60)::int as duracao_mininuto, (a.trr_duracao % 60) as duracao_segundo, a.trr_franquia, h.contr_tipo_franquia, a.trr_duracao as duracao, a.trr_tipo_chamada, a.trr_duracao_transf,c.apelido from pbx_tarif_registra a inner join pbx_operadoras b on b.oper_id = a.oper_id_dest inner join pbx_tarif_contrato h on h.contr_id = a.contr_id left join pbx_cs_usuarios c on c.matricula::text = a.trr_conta left join pbx_empresa e on e.id = c.empresa left join pbx_departamentos f on f.id = c.departamento left join pbx_tarifa_tipo_preco g on g.ttp_id = a.trr_vc where a.trr_conta_senha = '1' and a.trr_data >= '$dataIni' and a.trr_data <= '$dataFim' "; if ($conta) { $query .= " and a.trr_conta = '$conta' "; } if ($empresa) { $query .= " and c.empresa = '$empresa' "; } if ($depto) { $query .= " and c.departamento = '$depto' "; } $query .= " order by a.trr_data, a.trr_inicio "; //echo $query; $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); /** * TABELA PRINCIPAL */ $dadosCabecalio = array( 'Data', 'Empresa', 'Departamento', 'Operadora', 'Tipo', 'Ramal', 'Conta','Usuario','Destino', 'Duracao', 'Valor' ); $dadosField = array( 'trr_data', 'nome_empresa', 'nome_depto', 'oper_nome', 'ttp_descricao', 'trr_origem', 'trr_conta','apelido' ,'trr_destino', 'trr_duracao', 'trr_preco_total' ); /* * Monta a linha de cabecalio. */ $dataRel[] = GenerateCsvFromArray($dadosCabecalio); $somaDuracao = 0; $somaReg = 0; $somaValor = 0; $agrupado = array(); /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { /** * ARMAZENA OS VALORES PARA APRESENTAR NO AGRUPADO */ $somaReg ++; $somaDuracao += $row['trr_duracao']; $somaValor += $row['trr_preco_total']; /** * ARMAZENA DADOS DO BANCO NAS VARIAVEIS */ $tipoFranquia = $row["contr_tipo_franquia"]; $tarifaZero = $row["trr_tarifa_zero"] > 0; $franquia = ($row["trr_franquia"] > 0) && ($tipoFranquia > 0); $franquiaParcial = $franquia && ($row["trr_franquia"] != $row["trr_duracao"]); $tipoTarifa = $row["trr_preco_tipo"]; $precoMinuto = $row["trr_preco"]; $fator = $row["trr_vc_cad"]; $cadencia = $row["trr_vc_ext"]; $dura = $franquiaParcial ? $row["trr_franquia"] : (int) $row["trr_duracao"]; $agrupado[$row['nome_empresa']][$row['nome_depto']]['duracao'] += (int) $row["trr_duracao"]; /** * VERIFICA O TIPO DE TARIFA */ if (($tarifaZero || $franquia) && (!$franquiaParcial)) { $valor = 0; $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor(0); } else { /* * [ TARIFA CHAMADA ] FUNÇÃO PARA CALCULAR O VALOR DA TARIFAÇÃO */ $valor = TarifaChamada($tipoTarifa, $dura, $precoMinuto, $fator, $cadencia); $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor($valor); } /* * FORMATA OS DADOS PARA SER APRESENTADOS */ $row['trr_data'] = date('d/m/Y', strtotime($row['trr_data'])); $row['trr_conta'] = $row['trr_conta'] ? $row['trr_conta'] : ' - '; $row['trr_duracao'] = $row['trr_duracao'] ? SecondToStrTime($row['trr_duracao']) : '00:00:00'; $row['ttp_descricao'] = RemoveAcentos($row['ttp_descricao']); // Formata linha de dados. $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $dataRel[] = GenerateCsvFromArray(array('Chamadas ', $somaReg, '', '', '','Totalizador', '', '', '', SecondToStrTime($somaDuracao), FormataValor($somaValor))); $dataRel[] = GenerateCsvFromArray(array()); /** * TABELA DE FRANQUIA */ $dataRel[] = GenerateCsvFromArray(array('Empresa', 'Departamento', 'Duracao', 'Valor')); foreach ($agrupado as $key => $valor) { foreach ($valor as $k => $chave) { $dataRel[] = GenerateCsvFromArray(array($key, $k ? $k : ' --- ',SecondToStrTime($chave['duracao']),FormataValor($chave['valor']))); } } $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; /** * TABELA PRINCIPAL */ $dadosCabecalio = array( 'Data', 'Empresa', 'Departamento', 'Operadora', 'Tipo', 'Ramal', 'Conta', 'Usuario', 'Destino', 'Duracao', 'Valor' ); $dadosField = array( 'trr_data', 'nome_empresa', 'nome_depto', 'oper_nome', 'ttp_descricao', 'trr_origem', 'trr_conta', 'apelido','trr_destino', 'trr_duracao', 'trr_preco_total' ); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $values) { list($label, $value) = explode(":", $values); $linha[] = $label; } $dataRel[] = $linha; $somaDuracao = 0; $somaReg = 0; $somaValor = 0; $agrupado = array(); /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { /** * ARMAZENA OS VALORES PARA APRESENTAR NO AGRUPADO */ $somaReg ++; $somaDuracao += $row['trr_duracao']; $somaValor += $row['trr_preco_total']; /** * ARMAZENA DADOS DO BANCO NAS VARIAVEIS */ $tipoFranquia = $row["contr_tipo_franquia"]; $tarifaZero = $row["trr_tarifa_zero"] > 0; $franquia = ($row["trr_franquia"] > 0) && ($tipoFranquia > 0); $franquiaParcial = $franquia && ($row["trr_franquia"] != $row["trr_duracao"]); $tipoTarifa = $row["trr_preco_tipo"]; $precoMinuto = $row["trr_preco"]; $fator = $row["trr_vc_cad"]; $cadencia = $row["trr_vc_ext"]; $dura = $franquiaParcial ? $row["trr_franquia"] : (int) $row["trr_duracao"]; $agrupado[$row['nome_empresa']][$row['nome_depto']]['duracao'] += (int) $row["trr_duracao"]; /** * VERIFICA O TIPO DE TARIFA */ if (($tarifaZero || $franquia) && (!$franquiaParcial)) { $valor = 0; $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor(0); } else { /* * [ TARIFA CHAMADA ] FUNÇÃO PARA CALCULAR O VALOR DA TARIFAÇÃO */ $valor = TarifaChamada($tipoTarifa, $dura, $precoMinuto, $fator, $cadencia); $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor($valor); } /* * FORMATA OS DADOS PARA SER APRESENTADOS */ $row['trr_data'] = date('d/m/Y', strtotime($row['trr_data'])); $row['trr_conta'] = $row['trr_conta'] ? $row['trr_conta'] : ' - '; $row['trr_duracao'] = $row['trr_duracao'] ? SecondToStrTime($row['trr_duracao']) : '00:00:00'; $row['ttp_descricao'] = RemoveAcentos($row['ttp_descricao']); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $dataRel[] = array('LABEL', 'Chamadas ', $somaReg, '', '', '','Totalizador', '', '', '', SecondToStrTime($somaDuracao), FormataValor($somaValor)); $dataRel[] = array('DADOS', ''); /** * TABELA DE FRANQUIA */ $dataRel[] = array('LABEL','Empresa', 'Departamento', 'Duracao', 'Valor'); foreach ($agrupado as $key => $valor) { foreach ($valor as $k => $chave) { $dataRel[] = array('DADOS',$key, $k ? $k : ' --- ',SecondToStrTime($chave['duracao']),FormataValor($chave['valor'])); } } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data' => 'align="center"', 'Empresa' => 'align="left"', 'Departamento' => 'align="left"', 'Operadora' => 'align="left"', 'Tipo' => 'align="left"', 'Ramal' => 'align="left"', 'Conta' => 'align="left"', 'Usuário' => 'align="left"', 'Destino' => 'align="left"', 'Duração' => 'align="right"', 'Valor' => 'align="right"' ); $dadosField = array( 'trr_data' => 'align="center"', 'nome_empresa' => 'align="left"', 'nome_depto' => 'align="left"', 'oper_nome' => 'align="left"', 'ttp_descricao' => 'align="left"', 'trr_origem' => 'align="left"', 'trr_conta' => 'align="left"', 'apelido' => 'align="left"', 'trr_destino' => 'align="left"', 'trr_duracao' => 'align="right"', 'trr_preco_total' => 'align="right"' ); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $dataRel[] = ""; $linhas = ""; foreach ($dadosCabecalio as $key => $value) { $linhas .= sprintf("", $value, $key); } $linhas .= ""; $dataRel[] = $linhas; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Relatório Tarifação por Fatura
%s
%s
", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaReg = 0; $somaValor = 0; $somaDuracao = 0; $agrupado = array(); /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { /** * ARMAZENA OS VALORES PARA APRESENTAR NO AGRUPADO */ $somaReg ++; $somaDuracao += $row['trr_duracao']; $somaValor += $row['trr_preco_total']; /** * ARMAZENA DADOS DO BANCO NAS VARIAVEIS */ $tipoFranquia = $row["contr_tipo_franquia"]; $tarifaZero = $row["trr_tarifa_zero"] > 0; $franquia = ($row["trr_franquia"] > 0) && ($tipoFranquia > 0); $franquiaParcial = $franquia && ($row["trr_franquia"] != $row["trr_duracao"]); $tipoTarifa = $row["trr_preco_tipo"]; $precoMinuto = $row["trr_preco"]; $fator = $row["trr_vc_cad"]; $cadencia = $row["trr_vc_ext"]; $dura = $franquiaParcial ? $row["trr_franquia"] : (int) $row["trr_duracao"]; $agrupado[$row['nome_empresa']][$row['nome_depto']]['duracao'] += (int) $row["trr_duracao"]; /** * VERIFICA O TIPO DE TARIFA */ if (($tarifaZero || $franquia) && (!$franquiaParcial)) { $valor = 0; $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor(0); } else { /* * [ TARIFA CHAMADA ] FUNÇÃO PARA CALCULAR O VALOR DA TARIFAÇÃO */ $valor = TarifaChamada($tipoTarifa, $dura, $precoMinuto, $fator, $cadencia); $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $row['trr_preco_total'] = FormataValor($valor); } /* * FORMATA OS DADOS PARA SER APRESENTADOS */ $row['trr_data'] = date('d/m/Y', strtotime($row['trr_data'])); $row['trr_conta'] = $row['trr_conta'] ? $row['trr_conta'] : ' - '; $row['trr_duracao'] = $row['trr_duracao'] ? SecondToStrTime($row['trr_duracao']) : '00:00:00'; $row['trr_destino'] = ocultarTelefone($row['trr_destino']); /** * MONTA A TABELA DO RELATORIO */ $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } /* * MONTA A TABELA DE AGRUPAMENTO DE ACORDO COM OS DADOS GUARDADOS */ $dataRel[] = sprintf("Chamadas: $somaRegTotalizador%s%s", SecondToStrTime($somaDuracao), FormataValor($somaValor)); $dataRel[] = ''; $dataRel[] = '
'; $dataRel[] = ''; $dataRel[] = ''; $dataRel[] = ''; foreach ($agrupado as $key => $valor) { foreach ($valor as $k => $chave) { $dataRel[] = sprintf('', $key, $k ? $k : ' --- ', SecondToStrTime($chave['duracao']), FormataValor($chave['valor'])); } } $dataRel[] = '
Agrupado Departamento
EmpresaDepartamentoDuraçãoValor
%s%s%s%s
'; /* * FECHA O RELATORIO */ $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ $dadosCabecalio = array( 'Data' => 'C', 'Empresa' => 'C', 'Departamento' => 'C', 'Operadora' => 'C', 'Tipo' => 'C', 'Ramal' => 'C', 'Conta' => 'C', 'Usuário' => 'C', 'Destino' => 'C', 'Duração' => 'C', 'Valor' => 'C' ); $dadosField = array( 'trr_data' => 'C', 'nome_empresa' => 'C', 'nome_depto' => 'C', 'oper_nome' => 'C', 'ttp_descricao' => 'C', 'trr_origem' => 'C', 'trr_conta' => 'C', 'apelido' => 'C', 'trr_destino' => 'C', 'trr_duracao' => 'C', 'trr_preco_total' => 'C' ); $somaReg = 0; $somaValor = 0; $somaDuracao = 0; $agrupado = array(); $widthHeader = array(20, 20, 15, 30, 20, 15, 10, 20, 20, 10, 15); $dados = $this->GetData()[0]; foreach ($dados as $row) { /** * ARMAZENA OS VALORES PARA APRESENTAR NO AGRUPADO */ $somaDuracao += $row['trr_duracao']; $somaValor += $row['trr_preco_total']; /** * ARMAZENA DADOS DO BANCO NAS VARIAVEIS */ $tipoFranquia = $row["contr_tipo_franquia"]; $tarifaZero = $row["trr_tarifa_zero"] > 0; $franquia = ($row["trr_franquia"] > 0) && ($tipoFranquia > 0); $franquiaParcial = $franquia && ($row["trr_franquia"] != $row["trr_duracao"]); $tipoTarifa = $row["trr_preco_tipo"]; $precoMinuto = $row["trr_preco"]; $fator = $row["trr_vc_cad"]; $cadencia = $row["trr_vc_ext"]; $dura = $franquiaParcial ? $row["trr_franquia"] : (int) $row["trr_duracao"]; $agrupado[$row['nome_empresa']][$row['nome_depto']]['duracao'] += (int) $row["trr_duracao"]; /** * VERIFICA O TIPO DE TARIFA */ if (($tarifaZero || $franquia) && (!$franquiaParcial)) { $valor = 0; $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $dados[$somaReg]['trr_preco_total'] = FormataValor(0); } else { /* * [ TARIFA CHAMADA ] FUNÇÃO PARA CALCULAR O VALOR DA TARIFAÇÃO */ $valor = TarifaChamada($tipoTarifa, $dura, $precoMinuto, $fator, $cadencia); $agrupado[$row['nome_empresa']][$row['nome_depto']]['valor'] += $valor; $somaValor += $valor; $dados[$somaReg]['trr_preco_total'] = FormataValor($valor); } /* * FORMATA OS DADOS PARA SER APRESENTADOS */ $dados[$somaReg]['trr_data'] = date('d/m/Y', strtotime($row['trr_data'])); $dados[$somaReg]['trr_conta'] = $row['trr_conta'] ? $row['trr_conta'] : ' - '; $dados[$somaReg]['trr_duracao'] = $row['trr_duracao'] ? SecondToStrTime($row['trr_duracao']) : '00:00:00'; $somaReg ++; } $totalizador = array('Chamadas: ', $somaReg, '', '', '','Totalizador', '', '', '', SecondToStrTime($somaDuracao), FormataValor($somaValor)); $tables[] = array($dadosCabecalio, $dadosField, $dados, $widthHeader, $totalizador, 0); /** * TABELA DE AGRUPADOS */ $agrpCabecalio = array( 'Empresa' => 'C', 'Departamento' => 'C', 'Duração' => 'C', 'Valor' => 'C' ); $agrpField = array( 'empresa' => 'C', 'departamento' => 'C', 'duracao' => 'C', 'valor' => 'C' ); $agrpHeader = array(50, 50, 50, 45); $dataAgp = array(); $z = 0; foreach ($agrupado as $key => $valor) { foreach ($valor as $k => $chave) { $dataAgp[$z]['empresa'] = $key; $dataAgp[$z]['departamento'] = $k ? $k : ' --- '; $dataAgp[$z]['duracao'] = SecondToStrTime($chave['duracao']); $dataAgp[$z]['valor'] = FormataValor($chave['valor']); $z++; } } $tables[] = array($agrpCabecalio, $agrpField, $dataAgp, $agrpHeader, 0, 0); $this->___dataRel = $tables; } private function ___GetInfoFatura($dbcon, $contr_id, $ano, $mes) { $query = "select distinct a.contr_dia_fechamento, b.prc_tipo, b.prc_franquia, b.prc_franquia_movel, a.contr_tipo_franquia, c.tfq_descricao, case when(b.prc_tipo::int = 1)then 'Minuto' else 'Chamada' end as prc_tipo_descricao from pbx_tarif_contrato a, pbx_tarif_contrato_preco b, pbx_tarif_tipo_franquia c where b.contr_id = a.contr_id and c.tfq_id = a.contr_tipo_franquia and a.contr_id = '$contr_id' "; $result = pg_query($dbcon, $query); $dados = @pg_fetch_array($result); $fecha = GetFechamentoContrato($ano, $mes, $dados['contr_dia_fechamento']); $dados['contr_dia_fechamento'] = $fecha ? $fecha : date('d'); return $dados; } private function ___GetAnosFatura($dbcon, $ano, $contrato) { $result = pg_query($dbcon, "select coalesce(date_part('year', min(trr_data) ), date_part('year', now() )), coalesce(date_part('year', max(trr_data) ),date_part('year', now() )) from pbx_tarif_registra where contr_id = '$contrato'"); if (!pg_num_rows($result)) return ""; $dados = @pg_fetch_row($result); $min = $dados[0]; $max = $dados[1]; while ($max >= $min) { $sel = ($dados[0] == $ano) ? "selected" : ""; $ano .= ""; $max--; } return $ano; } private function ___GetMesesFatura($mes) { $meses = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); $mes = $mes ? $mes : date('m'); $ret = ''; foreach ($meses as $mesA) { $sel = $mes == $mesA ? 'selected="selected"' : ''; $ret .= "\n"; } return $ret; } 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'); } } $relTarifaConta = new RelTarifaConta($idProg, $dbcon, 0); $relTarifaConta->ExecutaRelatorio();