___empresa = isset($_POST['emp_id']) ? $_POST['emp_id'] : 0; $this->___telefone = isset($_POST['telefone']) ? $_POST['telefone'] : ''; $this->___quantidade = isset($_POST['quantidade']) ? $_POST['quantidade'] : ''; } function ___ValidaForm() { } function ___FiltrosRelatorio() { if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sess�o do usu�rio. */ list($this->___empresa, $this->___dataIni, $this->___dataFim, $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(); $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'); } $tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"'; /* * Personalise esta fun��o se necessitar de outras op��es de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= sprintf('', $this->getEmpresa($this->___empresa)); $filtro .= sprintf('', $this->___telefone); $filtro .= sprintf('', $this->getQuantidade($this->___quantidade)); $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
Data InicialData Final EmpresaTelefoneQuantidade  
%s%s%s
'; /* * Guarda os filtros passados para recuperar na emissao dos relatorios para impressao. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb() { $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $query = "SELECT b.emp_id, emp_nome_fantasia, emp_razao_social, chm_data_bilhete, chm_dst, COUNT(chm_dst) AS chm_quantidade FROM vds_chamadas a INNER JOIN vds_empresas b ON b.emp_id = a.emp_id INNER JOIN vds_classificacoes c ON c.uid = a.uid WHERE a.chm_data_bilhete >= '{$dataIni}' AND a.chm_data_bilhete <= '{$dataFim}' "; if (!$this->___empresa) { $query .= " AND a.emp_id IN(SELECT emp_id FROM vds_empresas WHERE emp_status = 0) "; } else { $query .= " AND a.emp_id = {$this->___empresa} "; } if ($this->___telefone) { $query .= " AND chm_dst = '{$this->___telefone}'"; } $query .= " AND chm_evento IN ('COMPLETACALLER', 'COMPLETAAGENT') AND clas_descricao = 'VENDA' GROUP BY b.emp_id, emp_nome_fantasia, emp_razao_social,chm_data_bilhete, chm_dst ORDER BY chm_data_bilhete, emp_id desc "; $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', 'Empresa', 'Destino', 'Chamadas'); $dadosField = array('chm_data_bilhete', 'emp_nome_fantasia', 'chm_dst', 'chm_quantidade'); $dataRel[] = GenerateCsvFromArray(array_keys($dadosCabecalio)); $somaReg = 0; /* * Inicia o relat�rio. */ foreach ($this->GetData()[0] as $row) { if ($row['chm_quantidade'] >= $this->___quantidade) { $somaReg++; $row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete'])); $linha = array(); foreach ($dadosField as $key => $value) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } } $dataRel[] = $linha; $linha1 = array('Total', '', '', 'Registros: ' . $somaReg); $dataRel[] = GenerateCsvFromArray($linha1); $dataRel[] = $linha1; $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * 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', 'Empresa', 'Destino', 'Chamadas'); $dadosField = array('chm_data_bilhete', 'emp_nome_fantasia', 'chm_dst', 'chm_quantidade'); /* * Monta a linha de cabecalio. */ $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { if ($row['chm_quantidade'] >= $this->___quantidade) { $somaReg++; $row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete'])); // Formata linha de dados. $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } } $linha = array('LABEL', 'Total', '', '', 'Registros: ' . $somaReg); $dataRel[] = $linha; $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { $dataRel = array(); $dadosCabecalio = array( 'Data' => 'align="center"', 'Empresa' => 'align="center"', 'Destino' => 'align="center"', 'Chamadas' => 'align="center"' ); $dadosField = array( 'chm_data_bilhete' => 'align="center"', 'emp_nome_fantasia' => 'align="center"', 'chm_dst' => 'align="center"', 'chm_quantidade' => 'align="center"' ); /* * 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), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } $somaReg = 0; /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { if ($row['chm_quantidade'] >= $this->___quantidade) { $somaReg++; $row['chm_data_bilhete'] = date('d/m/Y', strtotime($row['chm_data_bilhete'])); // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; } } $linha = 'TotalRegistros: %s'; $dataRel[] = sprintf($linha, $somaReg); $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { list($this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; $dados = $this->GetData()[0]; $somaReg = 0; foreach ($dados as $key => $row) { if ($row['chm_quantidade'] >= $this->___quantidade) { $somaReg++; $dados[$key]["chm_data_bilhete"] = date('d/m/Y H', strtotime($row["chm_data_bilhete"])); } } $header = array( 'Data' => 'C', 'Empresa' => 'C', 'Destino' => 'C', 'Chamadas' => 'C' ); $dataHeader = array( 'chm_data_bilhete' => 'C', 'emp_nome_fantasia' => 'C', 'chm_dst' => 'C', 'chm_quantidade' => 'C' ); $widthHeader = array(50, 50, 50, 50); $totaliza = array('Total', "Registros: ", $somaReg, '', ''); //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); } private function getEmpresa($codEmpresa) { $query = "SELECT emp_id, emp_nome_fantasia FROM vds_empresas WHERE emp_status = 0 "; $query .= " order by emp_nome_fantasia"; $result = pg_query($query); $data = pg_fetch_all($result); $opt = ""; return $opt; return $data; } private function getQuantidade($select = false) { $opt = ""; return $opt; } public function ExecutaRelatorio() { global $jsStartup, $jsJQuery, $smarty; try { /* * Formata as linha da função date */ setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese"); /* * 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'); } } $relMetricasDiaria = new RelRealizaChamada($idProg, $dbcon, 1); $relMetricasDiaria->ExecutaRelatorio(); ?>