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

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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. $table->addRow();
  13. $table->addCell($row['numero'], 'left', $style);
  14. $table->addCell($row['descricao'], 'left', $style);
  15. //$table->addCell($row['areaUtil'], 'left', $style);
  16. $table->addCell($row['valor'], 'rigth', $style);
  17. $table->addCell(number_format($row['Total'],2,',','.'), 'rigth', $style);
  18. $ValorTotal += $row['Total'];
  19. $colour = !$colour;
  20. }
  21. echo $ValorTotal;
  22. $output = "app/output/tabular.{$format}";
  23. ?>
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. ?>