AM
Como Ordenar duas colunas num Relatório?
Eu tenho uma coleção de Revistas e quero fazer ordenação primeiro pelo nome e segundo pelo número da revista.
Meu relatório está exibindo corretamente a ordenação pelo nome da revista, mas os números de uma coleção, está exibindo desordenada. Como eu posso resolver isso?
Tentei colocar nessa ordem abaixo, mas não funciona.
$criteria->setProperty('order', 'nome');
$criteria->setProperty('order', 'numero');
Veja o anexo, têm uma foto do relatório.
Veja abaixo, meu código completo do relatório.
Meu relatório está exibindo corretamente a ordenação pelo nome da revista, mas os números de uma coleção, está exibindo desordenada. Como eu posso resolver isso?
Tentei colocar nessa ordem abaixo, mas não funciona.
$criteria->setProperty('order', 'nome');
$criteria->setProperty('order', 'numero');
Veja o anexo, têm uma foto do relatório.
Veja abaixo, meu código completo do relatório.
- <?php
- class ImpRelatorio7 extends TPage
- {
- protected $form;
- protected $notebook;
- function __construct()
- {
- parent::__construct();
- // Set focus no campo especificado
- TScript::create('setTimeout(function() { $("input[name=\'id\']").focus() }, 500);');
- // Executa um script que substitui o Tab pelo Enter.
- parent::include_js('app/lib/include/application.js');
- // creates the form
- $this->form = new TQuickForm('form_Revista_report');
- $this->form->class = 'tform'; // change CSS class
- $this->form->style = 'width: 830px';
- // creates the table container
- $table = new TTable;
- $table->width = '100%';
- // add the table inside the form
- $this->form->add($table);
- // define the form title
- $table->addRowSet( new TLabel('Relatório de Revistas'), new TLabel('(Estilo 7) Em Ordem Alfabética') )->class = 'tformtitle';
- // create the form fields
- $nome = new TEntry('nome');
- $numero = new TEntry('numero');
- $ano = new TEntry('ano');
- $nota = new TCombo('nota');
- $combo_items = array();
- $combo_items['Péssimo'] ='Péssimo';
- $combo_items['Ruim'] ='Ruim';
- $combo_items['Médio'] ='Médio';
- $combo_items['Bom'] ='Bom';
- $combo_items['Muito Bom'] ='Muito Bom';
- $combo_items['Excelente'] ='Excelente';
- $nota->addItems($combo_items);
- $output_type = new TRadioGroup('output_type');
- // define the sizes
- $nome->setSize(650);
- $numero->setSize(70);
- $ano->setSize(70);
- $nota->setSize(100);
- $output_type->setSize(100);
- // MaxLength
- $nome->setMaxLength(70);
- $numero->setMaxLength(4);
- $ano->setMaxLength(4);
- // Define um valor inicial para os campos.
- $nome->setValue('');
- $numero->setValue('');
- $ano->setValue('');
- $nota->setValue('');
- // $output_type = new TRadioGroup('output_type');
- // validação
- $output_type->addValidation('Output', new TRequiredValidator);
- // add one row for each form field
- $table->addRowSet( new TLabel('Nome:'), $nome );
- $table->addRowSet( new TLabel('Número:'), $numero );
- $table->addRowSet( new TLabel('Ano:'), $ano );
- $table->addRowSet( new TLabel('Nota:'), $nota );
- $table->addRowSet( $label_output_type = new TLabel('Saída:'), $output_type );
- $label_output_type->setFontColor('#cc0000');
- $this->form->setFields(array($nome,$numero,$ano,$nota,$output_type));
- $output_type->addItems(array('html'=>'HTML', 'pdf'=>'PDF', 'rtf'=>'RTF'));;
- $output_type->setValue('pdf');
- $output_type->setLayout('horizontal');
- $generate_button = TButton::create('generate', array($this, 'onGenerate'), ('Gerar'), 'ico_apply.png');
- $this->form->addField($generate_button);
- $limp = TButton::create('Limpar', array($this, 'onShow'), ('Limpar Campos'), 'ico_ok.png');
- $this->form->addField($limp);
- // add a row for the form action
- $table->addRowSet( $generate_button, '' )->class = 'tformaction';
- parent::add($this->form);
- }
- function onShow() {
- }
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'revista'
- TTransaction::open('revista');
- // get the form data into an active record
- $formdata = $this->form->getData();
- $repository = new TRepository('Revista');
- $criteria = new TCriteria;
- if ($formdata->nome)
- {
- $criteria->add(new TFilter('nome', 'like', "%{$formdata->nome}%"));
- }
- if ($formdata->numero)
- {
- $criteria->add(new TFilter('numero', 'like', "%{$formdata->numero}%"));
- }
- if ($formdata->ano)
- {
- $criteria->add(new TFilter('ano', 'like', "%{$formdata->ano}%"));
- }
- if ($formdata->nota)
- {
- $criteria->add(new TFilter('nota', 'like', "%{$formdata->nota}%"));
- }
- // Ordenação
- $criteria->setProperty('order', 'nome');
- $criteria->setProperty('order', 'numero');
- $objects = $repository->load($criteria, FALSE);
- $format = $formdata->output_type;
- if ($objects)
- {
- $widths = array(375,40,40,80);
- switch ($format)
- {
- case 'html':
- $tr = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $tr = new TTableWriterPDF($widths);
- break;
- case 'rtf':
- if (!class_exists('PHPRtfLite_Autoloader'))
- {
- PHPRtfLite::registerAutoloader();
- }
- $tr = new TTableWriterRTF($widths);
- break;
- }
- // Cria o estilo do documento
- $tr->addStyle('title', 'Arial', '12', 'B', '#ffffff', '#EA9C98'); // Cabeçalho, Cor: Letra - Fundo
- $tr->addStyle('title2', 'Arial', '12', 'B', '#ffffff', '#EA9C98'); // Cabeçalho, Cor: Letra - Fundo
- $tr->addStyle('datap', 'Arial', '12', '', '#000000', '#EEEEEE'); // 2º Registro
- $tr->addStyle('datai', 'Arial', '12', '', '#000000', '#ffffff'); // 1º Registro
- $tr->addStyle('header', 'Arial', '16', '', '#ffffff', '#904F49'); // Título
- $tr->addStyle('header2', 'Arial', '16', '', '#ffffff', '#904F49'); // Título
- $tr->addStyle('footer', 'Times', '12', 'I', '#000000', '#F2BEBC'); // Rodapé
- // add a header row
- $tr->addRow();
- $tr->addCell(utf8_decode('Relatório de Todas as Revistas'), 'center', 'header', 4);
- // adiciona títulos na linha.
- $tr->addRow();
- $tr->addCell(utf8_decode('Nome'), 'center', 'title2');
- $tr->addCell(utf8_decode('Nº'), 'center', 'title2');
- $tr->addCell('Ano', 'center', 'title2');
- $tr->addCell(utf8_decode('Nota'), 'center', 'title2');
- // controls the background filling
- $colour= FALSE;
- // data rows
- foreach ($objects as $object)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell(utf8_decode($object->nome), 'left', $style);
- $tr->addCell(str_pad($object->numero, 2, "0", STR_PAD_LEFT), 'center', $style);
- $tr->addCell(utf8_decode($object->ano), 'center', $style);
- $tr->addCell(utf8_decode($object->nota), 'center', $style);
- $colour = !$colour;
- }
- // footer row
- $tr->addRow();
- $tr->addCell(utf8_decode('Data e Hora da Impressão: ').date(' d/m/Y | h:i:s'), 'left', 'footer', 4);
- // stores the file
- if (!file_exists("app/output/Revista.{$format}") OR is_writable("app/output/Revista.{$format}"))
- {
- $tr->save("app/output/Revista.{$format}");
- }
- else
- {
- throw new Exception(_t('Acesso Negado.') . ': ' . "app/output/Revista.{$format}");
- }
- // open the report file
- parent::openFile("app/output/Revista.{$format}");
- // shows the success message
- new TMessage('info', 'Relatório Gerado. Deixe sempre habilitado o Pop-Up Menu do seu Navegador.');
- }
- else
- {
- new TMessage('error', 'Nenhum registro foi encontrado.');
- }
- // fill the form with the active record data
- $this->form->setData($formdata);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
Olá Alex.
Tenta fazer assim: