Imprimir Data Início e Data Fim no Relatório Tabular Boa noite Dev's estou tentando imprimir no relatório pdf a data inicio e data fim que coloco no formulário para pesquisar dados. Mas esta aparecendo assim no relatório tabular: " Data Início: ci/in/data Data Fim: /fi/data " Abaixo código usado para mostrar as datas. ...
PC
Imprimir Data Início e Data Fim no Relatório Tabular  
Boa noite Dev's estou tentando imprimir no relatório pdf a data inicio e data fim que coloco no formulário para pesquisar dados. Mas esta aparecendo assim no relatório tabular:
" Data Início: ci/in/data Data Fim: /fi/data "
Abaixo código usado para mostrar as datas.

 
  1. <?php
  2. $table->addRow();
  3. $table->addCell('Data Início: '.TDate::date2br('data_inicio').' Data Fim: '.TDate::date2br('data_fim'), 'center','title', 4);
  4. ?>

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 (13)


LC

Documentação do comando:
https://www.adianti.com.br/api-framework-widget-form-TDate#date2br

Passe como parametro a data no formato ano-mes-dia (yyyy-mm-dd)
TDate::date2br('2020-03-05')
PC

Luiz Coelho, quando coloco números da certo (2020-03-05), mas quando é variável não aparece a data_inicio que esta no formulário e nem a data_fim e sim o seguinte erro. Data Início: ci/in/data Data Fim: m/_f/$dat

 
  1. <?php
  2. class RelatorioUnidadeMensal 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_RelatorioUnidadeMensal_report');
  14. $this->form->setFormTitle( 'Relatório Mensal da Unidade' );
  15. $data_inicio = new TDate('data_inicio');
  16. $data_fim = new TDate('data_fim');
  17. $tipo_conta_id = new TDBCombo('tipo_conta_id', 'gecon', 'TipoConta', 'id', 'descricao');
  18. $unidade_id = new TDBCombo('unidade_id', 'gecon', 'Unidade', 'id', 'numero');
  19. // create the form fields
  20. $this->form->addFields( [ new TLabel('Data Início', 'red') ], [ $data_inicio] ,
  21. [ new TLabel('Data Fim', 'red') ], [ $data_fim ] );
  22. $this->form->addFields( [ new TLabel('Tipo Conta') ], [ $tipo_conta_id ] ,
  23. [ new TLabel('Unidade') ], [ $unidade_id]);
  24. //set Mask
  25. $data_inicio->setMask('dd/mm/yyyy');
  26. $data_fim->setMask('dd/mm/yyyy');
  27. $output_type = new TRadioGroup('output_type');
  28. $this->form->addFields( [new TLabel('Mostrar em:')], [$output_type] );
  29. // define field properties
  30. $output_type->setUseButton();
  31. $options = ['html' =>'HTML', 'pdf' =>'PDF', 'rtf' =>'RTF', 'xls' =>'XLS'];
  32. $output_type->addItems($options);
  33. $output_type->setValue('pdf');
  34. $output_type->setLayout('horizontal');
  35. $this->form->addAction( 'Gerar Relatório', new TAction(array($this, 'onGenerate')), 'fa:download blue');
  36. // wrap the page content using vertical box
  37. $vbox = new TVBox;
  38. $vbox->style = 'width: 100%';
  39. // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  40. $vbox->add($this->form);
  41. parent::add($vbox);
  42. }
  43. /**
  44. * method onGenerate()
  45. * Executed whenever the user clicks at the generate button
  46. */
  47. function onGenerate()
  48. {
  49. try
  50. {
  51. // get the form data into an active record Customer
  52. $data = $this->form->getData();
  53. $this->form->setData($data);
  54. $format = $data->output_type;
  55. // open a transaction with database ''
  56. $source = TTransaction::open('gecon');
  57. // define the query
  58. $query = 'SELECT unidade.numero, tipo_conta.descricao, unidade.areaUtil, condominio_lancamento.valor, (unidade.areaUtil * condominio_lancamento.valor) AS Total
  59. FROM unidade, tipo_conta, condominio_lancamento
  60. WHERE condominio_lancamento.valor > 0
  61. AND tipo_conta.id = condominio_lancamento.tipo_conta_id
  62. AND condominio_lancamento.data_lancamento BETWEEN :data_inicio AND :data_fim ';
  63. /*
  64. if ( !empty($data->data_lancamento ) )
  65. {
  66. $query .= " and data_lancamento >= '" . DateTime::createFromFormat('d/m/Y', $data->data_lancamento )->format( 'Y-m-d' ) ."' ";
  67. }
  68. */
  69. if ( !empty($data->tipo_conta_id) )
  70. {
  71. $query .= " and condominio_lancamento.tipo_conta_id = {$data->tipo_conta_id}";
  72. }
  73. if ( !empty($data->unidade_id) )
  74. {
  75. $query .= " and unidade.id = {$data->unidade_id}";
  76. }
  77. $filters = [];
  78. $filters['data_inicio'] = TDate::date2us($data->data_inicio);
  79. $filters['data_fim'] = TDate::date2us($data->data_fim);
  80. $data = TDatabase::getData($source, $query, null, $filters );
  81. if ($data)
  82. {
  83. $widths = [200,200,200,200,200];
  84. switch ($format)
  85. {
  86. case 'html':
  87. $table = new TTableWriterHTML($widths);
  88. break;
  89. case 'pdf':
  90. $table = new TTableWriterPDF($widths);
  91. break;
  92. case 'rtf':
  93. $table = new TTableWriterRTF($widths);
  94. break;
  95. case 'xls':
  96. $table = new TTableWriterXLS($widths);
  97. break;
  98. }
  99. if (!empty($table))
  100. {
  101. // create the document styles
  102. $table->addStyle('header', 'Helvetica', '16', 'B', '#ffffff', '#4B8E57');
  103. $table->addStyle('title', 'Helvetica', '10', 'B', '#ffffff', '#6CC361');
  104. $table->addStyle('datap', 'Helvetica', '10', '', '#000000', '#E3E3E3', 'LR');
  105. $table->addStyle('datai', 'Helvetica', '10', '', '#000000', '#ffffff', 'LR');
  106. $table->addStyle('footer', 'Helvetica', '10', '', '#2B2B2B', '#B5FFB4');
  107. $table->setHeaderCallback( function($table) {
  108. $table->addRow();
  109. $table->addCell('Relatorio Condomínio Lançamento', 'center', 'header', 4);
  110. $table->addRow();
  111. $table->addCell('Data Início: '.TDate::date2br('data_inicio').' Data Fim: '.TDate::date2br('data_fim'), 'center','title', 4);
  112. $table->addRow();
  113. $table->addCell('Unidade', 'center', 'title');
  114. $table->addCell('Tipo Conta', 'center', 'title');
  115. $table->addCell('Valor', 'center', 'title');
  116. $table->addCell('Total', 'center', 'title');
  117. });
  118. $table->setFooterCallback( function($table) {
  119. $table->addRow();
  120. $table->addCell(date('d/m/Y h:i:s'), 'center', 'footer', 4);
  121. });
  122. // controls the background filling
  123. $colour= FALSE;
  124. $ValorTotal = 0;
  125. // data rows
  126. foreach ($data as $row)
  127. {
  128. $style = $colour ? 'datap' : 'datai';
  129. $table->addRow();
  130. $table->addCell($row['numero'], 'left', $style);
  131. $table->addCell($row['descricao'], 'left', $style);
  132. $table->addCell($row['valor'], 'rigth', $style);
  133. $table->addCell(number_format($row['Total'],2,',','.'), 'rigth', $style);
  134. $ValorTotal += $row['Total'];
  135. $colour = !$colour;
  136. }
  137. $table->addRow();
  138. $table->addCell('Valor Total: ', 'left', 'footer', 1);
  139. $table->addCell(number_format($ValorTotal,2,',','.'), 'rigth', 'footer', 3);
  140. $output = "app/output/tabular.{$format}";
  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. // shows the success message
  152. new TMessage('info', 'Relatório gerado. Por favor, ative popups no navegador.');
  153. }
  154. }
  155. else
  156. {
  157. new TMessage('error', 'Registros não encontrado');
  158. }
  159. // close the transaction
  160. TTransaction::close();
  161. }
  162. catch (Exception $e) // in case of exception
  163. {
  164. new TMessage('error', $e->getMessage());
  165. TTransaction::rollback();
  166. }
  167. }
  168. ?>
LC

Desta forma: TDate::date2br('data_inicio') você esta passando uma uma string e não uma data.
Tente:
TDate::date2br( $data->data_inicio );
PC

Leandro Coelho, já tinha colocado $data->data_inicio </> mas aparece Notice abaixo:

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 144

Notice: Trying to get property 'data_inicio' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 144
LC

Esta linha no incio recebe os dados da tela e joga em $data
$data = $this->form->getData();

Essa linha recebe os dados da consulta do banco e também joga em $data, isso mata os dados recebidos acima
$data = TDatabase::getData($source, $query, null, $filters );

Depois desta linha vc fica sem os dados recebidos da tela

Muda estas linhas:
$rows = TDatabase::getData($source, $query, null, $filters );
foreach ($rows as $row)
PC

Fiz alterações sugeridas, mas ainda nada de pegar a data do formulário.
PC

Pega este valor:

Data Início: 06pm31pm_373372020-03-06T17:37:57-03:00372020
LC

Coloca seu código ai pra eu ver como ficou
PC

Amigo Leandro, abaixo o código completo.

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

Troca essa linha:
 
  1. <?php
  2. if ($data)
  3. ?>

por:
 
  1. <?php
  2. if ($rows)
  3. ?>


Troca essa linha:
 
  1. <?php
  2. $table->addCell('Data Início: '.date('data_inicio').' - Data Fim: '.date('data_fim'), 'center','title', 4);
  3. ?>

por:
 
  1. <?php
  2. $table->addCell('Data Início: ' . $data->data_inicio . ' - Data Fim: ' . $data->data_fim, 'center','title', 4);
  3. ?>

PC

No formulário do relatório aparece assim na Data:
Data Início: - Data Fim:

No Form aparece estes erros:

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
Notice: Trying to get property 'data_inicio' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139

Notice: Undefined variable: data in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
Notice: Trying to get property 'data_fim' of non-object in /var/www/html/gecon/app/control/gecon/relatorios/RelatorioUnidadeMensal.php on line 139
LC

A função não consegue acessar o $data->data_inicio , pq no caso ela fica fora do onGenerate, é mais ou menos isso, rsrsrs.

Faz assim, no incio da classe, onde tem:
private $form; // form
Adicione uma linha abaixo, como esta:
protected $data;

Ai no onGenerate, vc vai trocar todos os $data, assim:
$data
para:
$this->data
PC

Leandro Coelho, show meu irmão. Deu certo. Grato pela contribuição. Espero um dia retornar para a comunidade.

Código correto.

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