CD
Relatório Tabular com SQL Filtro Período ( não acha registros)
Pessoal
Gerei um relatorio tabular SQL com filtro de duas datas pelo Studio Pro, e a query não retorna nenhum registro.
Executando ela na mão aparecem os registros.
Comentei o filtro no código, mas daí não grava nenhum PDF e também não dá erro
Gerei um relatorio tabular SQL com filtro de duas datas pelo Studio Pro, e a query não retorna nenhum registro.
Executando ela na mão aparecem os registros.
Comentei o filtro no código, mas daí não grava nenhum PDF e também não dá erro
- <?php
- /**
- * Tabular Query Report
- *
- * @version 1.0
- * @package samples
- * @subpackage tutor
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class ocor_navio_per extends TPage
- {
- private $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_ocor_navio_per.php_report');
- $this->form->setFormTitle( 'Relatório Navio x Ocorrência' );
- // create the form fields
- $DATA_INI = new TDate('DATA_INI');
- $DATA_FIM = new TDate('DATA_FIM');
- $DATA_INI->setmask('dd/mm/yyyy');
- $DATA_FIM->setmask('dd/mm/yyyy');
- $this->form->addFields( [new TLabel('Data Inicial: ', 'red')], [$DATA_INI] );
- $this->form->addFields( [new TLabel('Data Final..: ', 'red')], [$DATA_FIM] );
- $DATA_INI->addValidation('Data Ini ', new TRequiredValidator);
- $DATA_FIM->addValidation('Data Fim ', new TRequiredValidator);
- $output_type = new TRadioGroup('output_type');
- $this->form->addFields( [new TLabel('Output')], [$output_type] );
- // define field properties
- $output_type->setUseButton();
- $options = ['html' =>'HTML', 'pdf' =>'PDF', 'rtf' =>'RTF', 'xls' =>'XLS'];
- $output_type->addItems($options);
- $output_type->setValue('pdf');
- $output_type->setLayout('horizontal');
- $this->form->addAction( 'Gerar', new TAction(array($this, 'onGenerate')), 'fa:download blue');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * method onGenerate()
- * Executed whenever the user clicks at the generate button
- */
- function onGenerate()
- {
- try
- {
- // get the form data into an active record Customer
- $data = $this->form->getData();
- $this->form->setData($data);
- $format = $data->output_type;
- // open a transaction with database 'datasiop'
- $source = TTransaction::open('datasiop');
- // define the query
- $query = 'SELECT B.NOME AS NAVIO, B.IMO AS IMO, C.DESCRICAO AS OCORRENCIA,COUNT(0) AS TOTAL
- FROM OCORRENCIA A, BZM_NAVIO B, bzm_tipo_ocorrencia C
- WHERE
- B.ID_NAVIO=A.id_navio_pk
- AND C.ID_TIPO_OCORRENCIA = A.id_tp_ocorrencia
- AND A.DATA_OCORRENCIA BETWEEN :DATA_INI AND :DATA_FIM
- GROUP BY B.NOME, B.IMO,C.DESCRICAO
- ORDER BY 1,3';
- $filters = [];
- $filters['DATA_INI'] = TDate::date2us($data->DATA_INI);
- $filters['DATA_FIM'] = TDate::date2us($data->DATA_FIM);
- $data = TDatabase::getData($source, $query, null, $filters );
- if ($data)
- {
- $widths = [200,200,200,200];
- switch ($format)
- {
- case 'html':
- $table = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $table = new TTableWriterPDF($widths);
- break;
- case 'rtf':
- $table = new TTableWriterRTF($widths);
- break;
- case 'xls':
- $table = new TTableWriterXLS($widths);
- break;
- }
- if (!empty($table))
- {
- // create the document styles
- $table->addStyle('header', 'Helvetica', '16', 'B', '#ffffff', '#4B8E57');
- $table->addStyle('title', 'Helvetica', '10', 'B', '#ffffff', '#6CC361');
- $table->addStyle('datap', 'Helvetica', '10', '', '#000000', '#E3E3E3', 'LR');
- $table->addStyle('datai', 'Helvetica', '10', '', '#000000', '#ffffff', 'LR');
- $table->addStyle('footer', 'Helvetica', '10', '', '#2B2B2B', '#B5FFB4');
- $table->setHeaderCallback( function($table) {
- $table->addRow();
- $table->addCell('Customers', 'center', 'header', 4);
- $table->addRow();
- $table->addCell('Navio', 'center', 'title');
- $table->addCell('Imo', 'center', 'title');
- $table->addCell('Ocorrencia', 'center', 'title');
- $table->addCell('Total', 'center', 'title');
- });
- $table->setFooterCallback( function($table) {
- $table->addRow();
- $table->addCell(date('d-m-Y h:i:s'), 'left', 'footer', 4);
- });
- // controls the background filling
- $colour= FALSE;
- // data rows
- foreach ($data as $row)
- {
- $style = $colour ? 'datap' : 'datai';
- $table->addRow();
- $table->addCell($row['NAVIO'], 'left', $style);
- $table->addCell($row['IMO'], 'left', $style);
- $table->addCell($row['OCORRENCIA'], 'left', $style);
- $table->addCell($row['TOTAL'], 'right', $style);
- $colour = !$colour;
- }
- $output = "app/output/tabular.{$format}";
- // stores the file
- if (!file_exists($output) OR is_writable($output))
- {
- $table->save($output);
- parent::openFile($output);
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . $output);
- }
- // shows the success message
- new TMessage('info', 'Report generated. Please, enable popups in the browser.');
- }
- }
- else
- {
- new TMessage('error', 'Não há registros!');
- }
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
Carlos
Você executou esta query diretamente no BD?
Teve retorno, ou seja, esta query quando executada manualmente, retorna os registros esperados?
Carlos Usa estes filtros que é por padrão do adianti para que você tenha um melhor desempenho no resultado de suas aplicações!
abaixo o código completo de um relatório criado por builder, para melhor entende-lo!
Marcelo,
executando a query direto no banco funciona normalmente.
Carlos Roberto,
Obrigado pelo código.