___dac = isset($_POST['listaDacs']) ? $_POST['listaDacs'] : 0; $this->___mes = isset($_POST['listaMes']) ? $_POST['listaMes'] : date('m'); $this->___ano = isset($_POST['listaAno']) ? $_POST['listaAno'] : 0; } public function ___ValidaForm() { if (!IsPostBack()) return; if ($this->GetIncDac() && !StrToIntDef($this->___dac)) { GeraExcept('Informe uma Fila!'); } } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessão do usuário. */ list($this->___dac, $this->___ano, $this->___mes, $this->___tipoRelatorio) = $_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[] = "Ano:" . $this->___ano; $fltCsv[] = "Mes:" . $this->___mes; $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'); } $tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"'; /* * Personalise esta função se necessitar de outras operações de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $this->GetIncDac() ? $filtro .= '' : ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $this->GetIncDac() ? $filtro .= sprintf('', $dacs) : ''; $filtro .= sprintf("", GetMes($this->___mes, '', 1)); $filtro .= sprintf('', GetAno($this->___ano, 1)); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
FilaMêsAno 
%s%s%s%s
'; /* * Guarda os filtros passados para recuperar na emissão dos relatórios para impressão. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___ano, $this->___mes, $this->___tipoRelatorio); return sprintf($filtro, $lkPrint); } protected function ___GetDadosDb() { $ano = $this->___ano; $mes = $this->___mes; $dac = $this->___dac; $query = "select clas_descricao, clit_descricao, (select count(*) from pbx_classifica_reg d inner join pbx_bilhetes e on e.uniqueid = d.id_bilhetes and e.lastapp <> 'Transferred Call' and date_part('year',e.data_bilhete) = '$ano' and date_part('month',e.data_bilhete) = '$mes' where d.clas_id = c.clas_id and d.clit_id = c.clit_id and d.id_dac = '$dac') as qtde, (select count(distinct d.id_bilhetes) from pbx_classifica_reg d inner join pbx_bilhetes e on e.uniqueid = d.id_bilhetes and e.lastapp <> 'Transferred Call' and date_part('year',e.data_bilhete) = '$ano' and date_part('month',e.data_bilhete) = '$mes' where d.clas_id = c.clas_id and d.clit_id = c.clit_id and d.id_dac = '$dac') as chmd from pbx_classifica_atendimento a inner join pbx_classifica_item c on c.clas_id = a.clas_id inner join pbx_classifica_dacs d on d.clas_id = a.clas_id where d.id_dac = '$dac' order by clas_descricao, clit_descricao"; $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); $ultClass = ''; $somaReg = 0; foreach ($this->GetData()[0] as $row) { $count++; $row['clas_descricao'] = RemoveAcentos($row['clas_descricao']); if ($count != 1) { if ($ultClass != $row['clas_descricao']) { $dataRel[] = GenerateCsvFromArray(array("Total [ $ultClass ]", $somaReg)); $dataRel[] = GenerateCsvFromArray(array('', '')); unset($somaReg); $dataRel[] = GenerateCsvFromArray(array($row['clas_descricao'], 'Classificacoes')); } } else { $dataRel[] = GenerateCsvFromArray(array($row['clas_descricao'], 'Classificacoes')); } $somaReg += $row["qtde"]; $row['clit_descricao'] = RemoveAcentos($row['clit_descricao']); // Formata linha de dados. $dataRel[] = GenerateCsvFromArray(array($row['clit_descricao'],$row['qtde'])); $ultClass = $row['clas_descricao']; if (count($this->GetData()[0]) == $count) { $dataRel[] = GenerateCsvFromArray(array("Total [ $ultClass ]", $somaReg)); } } $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('Descricao', 'Quantidade'); $dadosField = array('clit_descricao', 'qtde'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $ultClass = ''; $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $count++; $row['clas_descricao'] = RemoveAcentos($row['clas_descricao']); if ($count != 1) { if ($ultClass != $row['clas_descricao']) { $dataRel[] = array('LABEL', "Total [ $ultClass ]", $somaReg); $dataRel[] = array('LABEL', '', ''); unset($somaReg); $dataRel[] = array('LABEL', $row['clas_descricao'], 'Classificacoes'); } } else { $dataRel[] = array('LABEL', $row['clas_descricao'], 'Classificacoes'); } $somaReg += $row["qtde"]; $row['clit_descricao'] = RemoveAcentos($row['clit_descricao']); $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; $ultClass = $row['clas_descricao']; if (count($this->GetData()[0]) == $count) { $dataRel[] = array('LABEL', "Total [ $ultClass ]", $somaReg); } } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); /* * Inicia o relatório. */ $dataRel[] = ''; /* * Monta a linha de cabecalio. */ $linha = ''; $linha .= sprintf("", 'align="center"', 'Relatório Classificação Mensal'); $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
%s
%s
", count(1) - 1, (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaReg = 0; $ultClass = ""; $pass = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $count ++; if ($ultClass != $row['clas_descricao']) { if ($pass) { $linha = 'Total [ %s ]%s'; $dataRel[] = sprintf($linha, $ultClass, $somaReg); $dataRel[] = ' '; unset($somaReg); } $linha = ''; $linha .= sprintf("%s", 'align="left"', $row['clas_descricao']); $linha .= sprintf("%s", 'align="right"', 'Classificações'); $linha .= ""; $dataRel[] = $linha; } $ultClass = $row['clas_descricao']; $somaReg += $row['qtde']; // Formata linha de dados. $linha = ""; $linha .= sprintf("%s", $row['clit_descricao']); $linha .= sprintf("%s", $row['qtde']); $linha .= ""; $dataRel[] = $linha; $pass = 1; if (count($this->GetData()[0]) == $count) { $linha = 'Total [ %s ]%s'; $dataRel[] = sprintf($linha, $ultClass, $somaReg); unset($somaReg); } } /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_SESSION["SSstorageFiltros"]; $dados = array(); $tables = array(); $header = null; $x = 0; $t = 0; $ultClass = ""; $somaReg = 0; $dataHeader = array('clit_descricao' => 'C', 'qtde' => 'C'); $widthHeader = array(130, 60); foreach ($this->GetData()[0] as $row) { $count ++; if ($x) { if ($ultClass != $row['clas_descricao']) { $totalizador = array("Total [ $ultClass ] ", $somaReg); ${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); array_push($tables, ${"table" . $t}); $t++; unset($somaReg); unset($dados); $x = 0; $header = array($row['clas_descricao'] => 'C', "Classificações" => 'C'); } } else { $header = array($row['clas_descricao'] => 'C', "Classificações" => 'C'); } $somaReg += $row['qtde']; $ultClass = $row['clas_descricao']; $dados[$x]["clit_descricao"] = $row["clit_descricao"]; $dados[$x]["qtde"] = $row['qtde']; $x++; $z++; if (count($this->GetData()[0]) == $count) { $totalizador = array("Total [ $ultClass ] ", $somaReg); ${'table' . $t} = array($header, $dataHeader, $dados, $widthHeader, $totalizador, 0); array_push($tables, ${"table" . $t}); } } $this->___dataRel = $tables; } 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'); } } $relClassMensal = new RelClassificacaoMensal($idProg, $dbcon, 1); $relClassMensal->ExecutaRelatorio(); ?>