Conheça as melhorias da versão 8.0, 8.1, 8.2!
Clique aqui para saber mais
Títulos e atributos em linhas excedem as larguras -relatórios Código abaixo e, em anexo, o arquivo PDF gerado! ...
CN
Títulos e atributos em linhas excedem as larguras -relatórios  
Código abaixo e, em anexo, o arquivo PDF gerado!

 
  1. <?php
  2. /**
  3. * EscalaReport Report
  4. * @author <your name here>
  5. */
  6. class EscalaReport extends TPage
  7. {
  8. protected $form; // form
  9. /**
  10. * Class constructor
  11. * Creates the page and the registration form
  12. */
  13. function __construct()
  14. {
  15. parent::__construct();
  16. // creates the form
  17. $this->form = new BootstrapFormBuilder('form_Escala_report');
  18. $this->form->setFormTitle('Escala de Serviço');
  19. // create the form fields
  20. $dt_lancamento = new TDate('dt_lancamento');
  21. $output_type = new TRadioGroup('output_type');
  22. // add the fields
  23. $this->form->addFields( [ new TLabel('DATA') ], [ $dt_lancamento ] );
  24. $this->form->addFields( [ new TLabel('Output') ], [ $output_type ] );
  25. $output_type->addValidation('Output', new TRequiredValidator);
  26. // set sizes
  27. $dt_lancamento->setSize('100%');
  28. $output_type->setSize('100%');
  29. $output_type->addItems(array('html'=>'HTML', 'pdf'=>'PDF', 'rtf'=>'RTF', 'xls' => 'XLS'));
  30. $output_type->setLayout('horizontal');
  31. $output_type->setUseButton();
  32. $output_type->setValue('pdf');
  33. $output_type->setSize(70);
  34. // add the action button
  35. $btn = $this->form->addAction(_t('Generate'), new TAction(array($this, 'onGenerate')), 'fa:cog');
  36. $btn->class = 'btn btn-sm btn-primary';
  37. // vertical box container
  38. $container = new TVBox;
  39. $container->style = 'width: 90%';
  40. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  41. $container->add($this->form);
  42. parent::add($container);
  43. }
  44. /**
  45. * Generate the report
  46. */
  47. function onGenerate()
  48. {
  49. try
  50. {
  51. // open a transaction with database 'ortotrauma'
  52. TTransaction::open('ortotrauma');
  53. // get the form data into an active record
  54. $data = $this->form->getData();
  55. $this->form->validate();
  56. $repository = new TRepository('Escala');
  57. $criteria = new TCriteria;
  58. if ($data->dt_lancamento)
  59. {
  60. $criteria->add(new TFilter('dt_lancamento', '>=', "%{$data->dt_lancamento}%"));
  61. }
  62. $objects = $repository->load($criteria, FALSE);
  63. $format = $data->output_type;
  64. if ($objects)
  65. {
  66. $widths = array(100,100,100,100,100,100,100,100);
  67. switch ($format)
  68. {
  69. case 'html':
  70. $tr = new TTableWriterHTML($widths);
  71. break;
  72. case 'pdf':
  73. $tr = new TTableWriterPDF($widths);
  74. break;
  75. case 'xls':
  76. $tr = new TTableWriterXLS($widths);
  77. break;
  78. case 'rtf':
  79. $tr = new TTableWriterRTF($widths);
  80. break;
  81. }
  82. // create the document styles
  83. $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#A3A3A3', 'LR');
  84. $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#EEEEEE', 'LR');
  85. $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff', 'LR');
  86. $tr->addStyle('header', 'Arial', '12', '', '#ffffff', '#6B6B6B', 'LR');
  87. $tr->addStyle('footer', 'Times', '10', 'I', '#000000', '#A3A3A3', 'LR');
  88. // add a header row
  89. $tr->addRow();
  90. $tr->addCell('ESCALA DE SERVIÇO', 'center', 'header', 8);
  91. // add titles row
  92. $tr->addRow();
  93. $tr->addCell('DATA', 'center', 'title');
  94. $tr->addCell('NOME DO SERVIÇO 1', 'center', 'title');
  95. $tr->addCell('NOME DO SERVIÇO 2', 'center', 'title');
  96. $tr->addCell('NOME DO SERVIÇO 3', 'center', 'title');
  97. $tr->addCell('NOME DO SERVIÇO 4', 'center', 'title');
  98. $tr->addCell('NOME DO SERVIÇO 5', 'center', 'title');
  99. $tr->addCell('NOME DO SERVIÇO 6', 'center', 'title');
  100. $tr->addCell('NOME DO SERVIÇO 7', 'center', 'title');
  101. // controls the background filling
  102. $colour= FALSE;
  103. // data rows
  104. foreach ($objects as $object)
  105. {
  106. $style = $colour ? 'datap' : 'datai';
  107. $tr->addRow();
  108. $tr->addCell($object->dt_lancamento, 'center', $style);
  109. $tr->addCell($object->Medico_Coluna1->nome, 'center', $style);
  110. $tr->addCell($object->Medico_Coluna2->nome, 'center', $style);
  111. $tr->addCell($object->Medico_Coluna3->nome, 'center', $style);
  112. $tr->addCell($object->Medico_Coluna4->nome, 'center', $style);
  113. $tr->addCell($object->Medico_Coluna5->nome, 'center', $style);
  114. $tr->addCell($object->Medico_Coluna6->nome, 'center', $style);
  115. $tr->addCell($object->Medico_Coluna7->nome, 'center', $style);
  116. $colour = !$colour;
  117. }
  118. // footer row
  119. $tr->addRow();
  120. $tr->addCell(date('Y-m-d h:i:s'), 'center', 'footer', 8);
  121. // stores the file
  122. if (!file_exists("app/output/Escala.{$format}") OR is_writable("app/output/Escala.{$format}"))
  123. {
  124. $tr->save("app/output/Escala.{$format}");
  125. }
  126. else
  127. {
  128. throw new Exception(_t('Permission denied') . ': ' . "app/output/Escala.{$format}");
  129. }
  130. // open the report file
  131. parent::openFile("app/output/Escala.{$format}");
  132. // shows the success message
  133. new TMessage('info', 'Report generated. Please, enable popups.');
  134. }
  135. else
  136. {
  137. new TMessage('error', 'No records found');
  138. }
  139. // fill the form with the active record data
  140. $this->form->setData($data);
  141. // close the transaction
  142. TTransaction::close();
  143. }
  144. catch (Exception $e) // in case of exception
  145. {
  146. // shows the exception error message
  147. new TMessage('error', $e->getMessage());
  148. // undo all pending operations
  149. TTransaction::rollback();
  150. }
  151. }
  152. }

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


NR

Você pode imprimir como paisagem, basta passar "L" no segundo parâmetro do construtor da classe TTableWriterPDF. Veja a assinatura do construtor:
 
  1. <?php
  2. public function __construct($widths, $orientation='P', $format = 'A4')
  3. ?>
CN

Testei, porém, ainda esta cortanto o título. Tem como quebrar somente o título, como se fosse numa planilha no excel?
Ex.
Total de
Dias
NR

A TTableWriterPdf não tem esse recurso. Se não for possível diminuir a fonte ou aumentar o tamanho dessa coluna você precisa trabalhar diretamente com a FPDF ou Dompdf, por exemplo.