Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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. ...
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.

  1. <?php
  2. class RelatorioTeste extends TPage
  3. {
  4.     private $form// form
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page and the registration form
  9.      */
  10.     function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         // creates the form
  15.         $this->form = new BootstrapFormBuilder('form_RelatorioTeste_report');
  16.         $this->form->setFormTitle'Report' );
  17.         
  18.         $tipo_conta_id = new TDBCombo('tipo_conta_id''gecon''TipoConta''id''descricao');
  19.         $unidade_id = new TDBCombo('unidade_id''gecon''Unidade''id''numero');
  20.         
  21.         // create the form fields
  22.         $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
  23.                                 [ new TLabel('Unidade') ], [ $unidade_id]);
  24.         
  25.         $output_type  = new TRadioGroup('output_type');
  26.         $this->form->addFields( [new TLabel('Output')],   [$output_type] );
  27.         
  28.         // define field properties
  29.         $output_type->setUseButton();
  30.         $options = ['html' =>'HTML''pdf' =>'PDF''rtf' =>'RTF''xls' =>'XLS'];
  31.         $output_type->addItems($options);
  32.         $output_type->setValue('pdf');
  33.         $output_type->setLayout('horizontal');
  34.         
  35.         $this->form->addAction'Generate', new TAction(array($this'onGenerate')), 'fa:download blue');
  36.         
  37.         // wrap the page content using vertical box
  38.         $vbox = new TVBox;
  39.         $vbox->style 'width: 100%';
  40.         // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  41.         $vbox->add($this->form);
  42.         
  43.         parent::add($vbox);
  44.     }
  45.     /**
  46.      * method onGenerate()
  47.      * Executed whenever the user clicks at the generate button
  48.      */
  49.     function onGenerate()
  50.     {
  51.         try
  52.         {
  53.             // get the form data into an active record Customer
  54.             $data $this->form->getData();
  55.             $this->form->setData($data);
  56.             
  57.             $format $data->output_type;
  58.             
  59.             // open a transaction with database ''
  60.             $source TTransaction::open('gecon');
  61.                         
  62.             // define the query
  63.             $query =   'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
  64.                         FROM unidade, tipo_conta, condominio_lancamento 
  65.                         WHERE condominio_lancamento.valor > 0
  66.                         AND tipo_conta.id = condominio_lancamento.tipo_conta_id ';
  67.                         
  68.             $filters = [];
  69.                         
  70.             $data TDatabase::getData($source$querynull$filters );
  71.             
  72.             if ($data)
  73.             {
  74.                 $widths = [200,200,200,200,200];
  75.                 
  76.                 switch ($format)
  77.                 {
  78.                     case 'html':
  79.                         $table = new TTableWriterHTML($widths);
  80.                         break;
  81.                     case 'pdf':
  82.                         $table = new TTableWriterPDF($widths);
  83.                         break;
  84.                     case 'rtf':
  85.                         $table = new TTableWriterRTF($widths);
  86.                         break;
  87.                     case 'xls':
  88.                         $table = new TTableWriterXLS($widths);
  89.                         break;
  90.                 }
  91.                 
  92.                 if (!empty($table))
  93.                 {
  94.                     // create the document styles
  95.                     $table->addStyle('header''Helvetica''16''B''#ffffff''#4B8E57');
  96.                     $table->addStyle('title',  'Helvetica''10''B''#ffffff''#6CC361');
  97.                     $table->addStyle('datap',  'Helvetica''10''',  '#000000''#E3E3E3''LR');
  98.                     $table->addStyle('datai',  'Helvetica''10''',  '#000000''#ffffff''LR');
  99.                     $table->addStyle('footer''Helvetica''10''',  '#2B2B2B''#B5FFB4');
  100.                     
  101.                     $table->setHeaderCallback( function($table) {
  102.                         $table->addRow();
  103.                         $table->addCell('Relatorio Condomínio Lançamento''center''header'4);
  104.                         
  105.                         $table->addRow();
  106.                         $table->addCell('Unidade''center''title');
  107.                         $table->addCell('Tipo Conta''center''title');
  108.                         //$table->addCell('Area Util', 'center', 'title');
  109.                         $table->addCell('Valor''center''title');
  110.                         $table->addCell('Total''center''title');
  111.                     });
  112.                     
  113.                     $table->setFooterCallback( function($table) {
  114.                         $table->addRow();                                            
  115.                         $table->addCell(date('d/m/Y h:i:s'), 'center''footer'4);
  116.                     });
  117.                     
  118.                     
  119.                     // controls the background filling
  120.                     $colourFALSE;                    
  121.                     $ValorTotal 0;
  122.                     // data rows
  123.                     foreach ($data as $row)
  124.                     {
  125.                         $style $colour 'datap' 'datai';
  126.                         
  127.                         $table->addRow();
  128.                         $table->addCell($row['numero'], 'left'$style);
  129.                         $table->addCell($row['descricao'], 'left'$style);
  130.                         //$table->addCell($row['areaUtil'], 'left', $style);
  131.                         $table->addCell($row['valor'], 'rigth'$style);
  132.                         $table->addCell(number_format($row['Total'],2,',','.'), 'rigth'$style);
  133.                         
  134.                         $ValorTotal += $row['Total'];
  135.                         
  136.                         $colour = !$colour;
  137.                     }
  138.                     
  139.                     $output "app/output/tabular.{$format}";
  140.                     
  141.                     // stores the file
  142.                     if (!file_exists($output) OR is_writable($output))
  143.                     {
  144.                         $table->save($output);
  145.                         parent::openFile($output);
  146.                     }
  147.                     else
  148.                     {
  149.                         throw new Exception(_t('Permission denied') . ': ' $output);
  150.                     }
  151.                     
  152.                     // shows the success message
  153.                     new TMessage('info''Report generated. Please, enable popups in the browser.');
  154.                 }
  155.             }
  156.             else
  157.             {
  158.                 new TMessage('error''No records found');
  159.             }
  160.     
  161.             // close the transaction
  162.             TTransaction::close();
  163.         }
  164.         catch (Exception $e// in case of exception
  165.         {
  166.             new TMessage('error'$e->getMessage());
  167.             TTransaction::rollback();
  168.         }
  169.     }
  170. }

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


LC

O total vc tem que jogar anter desta linha, exemplo:
  1. <?php
  2. $style $colour 'datap' 'datai'
  3. $table->addRow();
  4. $table->addCell('''left'$style);
  5. $table->addCell('''left'$style);
  6. $table->addCell('''left'$style);
  7. $table->addCell('''rigth'$style);
  8. $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth'$style);
  9. $output "app/output/tabular.{$format}";
  10. ?>


O filtro vc pode fazer ai direto no seu SQL $query
Coloca um if abaixo, exemplo:
  1. <?php
  2. if ( !empty($data->tipo_conta_id) )
  3. {
  4. $query .= " and condominio_lancamento.tipo_conta_id = {$data->tipo_conta_id}"
  5. }
  6. ?>
PC

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.

  1. <?php
  2. $table->setFooterCallback( function($table) {
  3.                         $table->addRow(); 
  4.                         $table->addCell('ValorTotal''rigth''footer'4);
  5.                         $table->addRow();                                            
  6.                         $table->addCell(date('d/m/Y h:i:s'), 'center''footer'4);                        
  7.                     });
  8.  // data rows
  9.                     foreach ($data as $row)
  10.                     {                       
  11.                         $style $colour 'datap' 'datai';
  12.                         
  13.                         $table->addRow();
  14.                         $table->addCell($row['numero'], 'left'$style);
  15.                         $table->addCell($row['descricao'], 'left'$style);
  16.                         //$table->addCell($row['areaUtil'], 'left', $style);
  17.                         $table->addCell($row['valor'], 'rigth'$style);
  18.                         $table->addCell(number_format($row['Total'],2,',','.'), 'rigth'$style);
  19.                         
  20.                         $ValorTotal += $row['Total'];
  21.                         
  22.                         $colour = !$colour;
  23.                     }
  24.                     echo $ValorTotal;
  25.                     $output "app/output/tabular.{$format}";
  26. ?>
LC

Onde vc colocou o echo $ValorTotal , coloca isso:
  1. <?php
  2. $style $colour 'datap' 'datai'
  3. $table->addRow();
  4. $table->addCell('''left'$style);
  5. $table->addCell('''left'$style);
  6. $table->addCell('''left'$style);
  7. $table->addCell('''rigth'$style);
  8. $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth'$style);
  9. ?>
PC

Leandro Coelho, consegui meu amigo. Coloquei as duas linhas abaixo do foreach e esta aparecendo o valor total no relatório PDF.

  1. <?php
  2.  $table->addRow();
  3.  $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth''footer'4);
  4.  $output "app/output/tabular.{$format}";
  5. ?>