Numeração de página em relatório tabular e relatório de consulta Boa noite. Alguém sabe como incluir um código para numeração de páginas no Relatório Tabular e no Relatório de Consulta? Poderia ser no footer mesmo, tipo: "Pág. 1 de 8". Grato...
CM
Numeração de página em relatório tabular e relatório de consulta  
Boa noite.
Alguém sabe como incluir um código para numeração de páginas no Relatório Tabular e no Relatório de Consulta?
Poderia ser no footer mesmo, tipo: "Pág. 1 de 8".
Grato

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


NR

Veja a função footer do link abaixo:
https://www.adianti.com.br/forum/pt/view_851?criando-cabecalhos-e-rodapes-nos-re
CM

Bom dia Natalie.
Conheço esse post.
Mas dá para aplicar em relatórios tabulares e de consulta?

Tentei mas sempre ocorre erro.
Obrugado
CM

Desculpe o erro no seu nome. Corretor de telefone.
NR

Sim, pode aplicar em qualquer classe que utilize a FPDF para geração dos relatórios. Lembrando que isso só funciona para o formato pdf.

Você pode usar a função setHeaderCallback. Veja os comentários do Pablo nos posts abaixo:
www.adianti.com.br/forum/pt/view_833?cabecalho-de-relatorio-usando-t
https://www.adianti.com.br/forum/pt/view_1368?como-alterar-o-header-e-footer-em-
CM

Boa tarde Nataniel.

Infelizmente não consegui aplicar de forma alguma.

Tenho esta classe de cabeçalho e rodapé:

 
  1. <?php
  2. class TReportHeaderFooter extends TPDFDesigner
  3. {
  4. public function Header()
  5. {
  6. $this->SetY(5);
  7. $this->Cell(0, 10, utf8_decode('NOME DA SUA EMPRESA'),0,0,'C');
  8. }
  9. public function Footer()
  10. {
  11. $this->SetY(-12);
  12. $this->Cell(0, 10, utf8_decode('PÁGINA ').$this->PageNo().' / {nb}',0,0,'C');
  13. }
  14. }
  15. ?>


Meu Relatório está assim:

 
  1. <?php
 
  1. <?php
  2. /**
  3. * Tabular Query Report
  4. *
  5. * @version 1.0
  6. * @package samples
  7. * @subpackage tutor
  8. * @author Pablo Dall'Oglio
  9. * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class RelatorioVisitas extends TPage
  13. {
  14. private $form; // form
  15. /**
  16. * Class constructor
  17. * Creates the page and the registration form
  18. */
  19. function __construct()
  20. {
  21. parent::__construct();
  22. // creates the form
  23. $this->form = new BootstrapFormBuilder('form_RelatorioVisitas_report');
  24. $this->form->setFormTitle( 'Relatório de Visitas' );
  25. // create the form fields
  26. $visitante_id = new TDBCombo('visitante_id', 'grao7', 'SystemUser', 'id', 'name');
  27. $this->form->addFields( [new TLabel('Visitante ', 'red')], [$visitante_id] );
  28. $visitante_id->addValidation('Visitante Id ', new TRequiredValidator);
  29. $output_type = new TRadioGroup('output_type');
  30. $this->form->addFields( [new TLabel('Tipo')], [$output_type] );
  31. // define field properties
  32. $output_type->setUseButton();
  33. $options = ['html' =>'HTML', 'pdf' =>'PDF', 'rtf' =>'RTF', 'xls' =>'XLS'];
  34. $output_type->addItems($options);
  35. $output_type->setValue('pdf');
  36. $output_type->setLayout('horizontal');
  37. $btn = $this->form->addAction('Gerar Relatório', new TAction(array($this, 'onGenerate')), 'fa:download white');
  38. $btn->class = 'btn btn-sm btn-primary';
  39. // wrap the page content using vertical box
  40. $vbox = new TVBox;
  41. $vbox->style = 'width: 100%';
  42. // $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  43. $vbox->add($this->form);
  44. parent::add($vbox);
  45. }
  46. /**
  47. * method onGenerate()
  48. * Executed whenever the user clicks at the generate button
  49. */
  50. function onGenerate()
  51. {
  52. try
  53. {
  54. // get the form data into an active record Customer
  55. $data = $this->form->getData();
  56. $this->form->setData($data);
  57. $format = $data->output_type;
  58. // open a transaction with database 'grao7'
  59. $source = TTransaction::open('grao7');
  60. // define the query
  61. $query = ' SELECT clientes_visitas.cliente_txt as "cliente_nome_curto",
  62. clientes_visitas.data_visita as "data_visita", system_user.name as "name",
  63. clientes_visitas.sellout as "sellout", clientes_visitas.estoque_saida as "estoque_saida",
  64. clientes_visitas.estoque_alto_baixo as "estoque_alto_baixo", clientes_visitas.display_local as "display_local"
  65. FROM clientes_visitas, system_user
  66. WHERE visitante_id = system_user.id
  67. AND clientes_visitas.visitante_id = :visitante_id
  68. ORDER BY data_visita asc';
  69. $filters = [];
  70. $filters['visitante_id'] = $data->visitante_id;
  71. $data = TDatabase::getData($source, $query, null, $filters );
  72. if ($data)
  73. {
  74. $widths = [300,70,50,40,150,100,100];
  75. switch ($format)
  76. {
  77. case 'html':
  78. $table = new TTableWriterHTML($widths);
  79. break;
  80. case 'pdf':
  81. $table = new TTableWriterPDF($widths);
  82. break;
  83. case 'rtf':
  84. $table = new TTableWriterRTF($widths);
  85. break;
  86. case 'xls':
  87. $table = new TTableWriterXLS($widths);
  88. break;
  89. }
  90. if (!empty($table))
  91. {
  92. // create the document styles
  93. $table = new TTableWriterPDF($widths,'L');
  94. $table->addStyle('header', 'Helvetica', '16', 'B', '#ffffff', '#4B8E57');
  95. $table->addStyle('title', 'Helvetica', '9', 'B', '#ffffff', '#6CC361');
  96. $table->addStyle('datap', 'Helvetica', '8', '', '#000000', '#E3E3E3', 'LR');
  97. $table->addStyle('datai', 'Helvetica', '8', '', '#000000', '#ffffff', 'LR');
  98. $table->addStyle('footer', 'Helvetica', '10', '', '#2B2B2B', '#B5FFB4');
  99. $table->setHeaderCallback( function($table) {
  100. $table->addRow();
  101. $table->addCell('Grão Chocolates - Relatório de Visitas', 'center', 'header', 7);
  102. $table->addRow();
  103. $table->addCell('Cliente', 'center', 'title');
  104. $table->addCell('Data Visita', 'center', 'title');
  105. $table->addCell('Sellout', 'center', 'title');
  106. $table->addCell('A/B', 'center', 'title');
  107. $table->addCell('Saída', 'center', 'title');
  108. $table->addCell('Local', 'center', 'title');
  109. $table->addCell('Visitante', 'center', 'title');
  110. });
  111. $table->setFooterCallback( function($table) {
  112. $table->addRow();
  113. $table->addCell(date('d/m/Y - H:i:s '), 'center', 'footer', 7);
  114. });
  115. // controls the background filling
  116. $colour= FALSE;
  117. // data rows
  118. foreach ($data as $row)
  119. {
  120. $style = $colour ? 'datap' : 'datai';
  121. $table->addRow();
  122. $table->addCell($row['cliente_nome_curto'], 'center', $style);
  123. $table->addCell(TDate::date2br($row['data_visita']), 'center', $style);
  124. $table->addCell(number_format($row['sellout'], 2, ',', '.'), 'right', $style);
  125. $table->addCell($row['estoque_alto_baixo'], 'center', $style);
  126. $table->addCell($row['estoque_saida'], 'center', $style);
  127. $table->addCell($row['display_local'], 'center', $style);
  128. $table->addCell($row['name'], 'center', $style);
  129. $colour = !$colour;
  130. }
  131. $output = "app/output/tabular.{$format}";
  132. // stores the file
  133. if (!file_exists($output) OR is_writable($output))
  134. {
  135. $table->save($output);
  136. parent::openFile($output);
  137. }
  138. else
  139. {
  140. throw new Exception(_t('Permission denied') . ': ' . $output);
  141. }
  142. // shows the success message
  143. //new TMessage('info', 'Relatório gerado com Sucesso! Por favor, habilite janelas popup no navegador.');
  144. }
  145. }
  146. else
  147. {
  148. new TMessage('error', 'Nenhum registro encontrado para o Visitante.');
  149. }
  150. // close the transaction
  151. TTransaction::close();
  152. }
  153. catch (Exception $e) // in case of exception
  154. {
  155. new TMessage('error', $e->getMessage());
  156. TTransaction::rollback();
  157. }
  158. }
  159. }
  160. ?>


Obrigado