PC
Relatório Tabular não seleciona TDBCombo e a não imprime soma
No meu relatório Tabular, minha soma esta fazendo corretamente, mas não consigo colocá-la no PDF. E ao selecionar o TDBCombo de uma unidade não aparece somente a selecionada, esta aparecendo todas.
- <?php
- class RelatorioTeste 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_RelatorioTeste_report');
- $this->form->setFormTitle( 'Report' );
- $tipo_conta_id = new TDBCombo('tipo_conta_id', 'gecon', 'TipoConta', 'id', 'descricao');
- $unidade_id = new TDBCombo('unidade_id', 'gecon', 'Unidade', 'id', 'numero');
- // create the form fields
- $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
- [ new TLabel('Unidade') ], [ $unidade_id]);
- $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( 'Generate', 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 ''
- $source = TTransaction::open('gecon');
- // define the query
- $query = 'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
- FROM unidade, tipo_conta, condominio_lancamento
- WHERE condominio_lancamento.valor > 0
- AND tipo_conta.id = condominio_lancamento.tipo_conta_id ';
- $filters = [];
- $data = TDatabase::getData($source, $query, null, $filters );
- if ($data)
- {
- $widths = [200,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('Relatorio Condomínio Lançamento', 'center', 'header', 4);
- $table->addRow();
- $table->addCell('Unidade', 'center', 'title');
- $table->addCell('Tipo Conta', 'center', 'title');
- //$table->addCell('Area Util', 'center', 'title');
- $table->addCell('Valor', 'center', 'title');
- $table->addCell('Total', 'center', 'title');
- });
- $table->setFooterCallback( function($table) {
- $table->addRow();
- $table->addCell(date('d/m/Y h:i:s'), 'center', 'footer', 4);
- });
- // controls the background filling
- $colour= FALSE;
- $ValorTotal = 0;
- // data rows
- foreach ($data as $row)
- {
- $style = $colour ? 'datap' : 'datai';
- $table->addRow();
- $table->addCell($row['numero'], 'left', $style);
- $table->addCell($row['descricao'], 'left', $style);
- //$table->addCell($row['areaUtil'], 'left', $style);
- $table->addCell($row['valor'], 'rigth', $style);
- $table->addCell(number_format($row['Total'],2,',','.'), 'rigth', $style);
- $ValorTotal += $row['Total'];
- $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', 'No records found');
- }
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
O total vc tem que jogar anter desta linha, exemplo:
O filtro vc pode fazer ai direto no seu SQL $query
Coloca um if abaixo, exemplo:
Bom dia Leandro Coelho, agradeço pela rapidez do retorno. O filtro funcionou 100%.
Quando coloco echo imprime, mas a impressão do Valor Total não aparece no PDF, somente no formulário html.
Onde vc colocou o echo $ValorTotal , coloca isso:
Leandro Coelho, consegui meu amigo. Coloquei as duas linhas abaixo do foreach e esta aparecendo o valor total no relatório PDF.