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

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 (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.