Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Melhorar código Pessoal eu gerei um relatório com mestre detalhe ficou muito bom e tá funcionando perfeito, porém eu gostaria que os amigos dessem uma olhada no meu código e visse se tem algo que eu possa melhorar no código e depois de pronto eu vou colocar como um artigo para ajudar outros amigos, em anexo como ficou o relatório, obrigado a todos que me ajudaram. ...
MO
Melhorar código  
Pessoal eu gerei um relatório com mestre detalhe ficou muito bom e tá funcionando perfeito, porém eu gostaria que os amigos dessem uma olhada no meu código e visse se tem algo que eu possa melhorar no código e depois de pronto eu vou colocar como um artigo para ajudar outros amigos, em anexo como ficou o relatório, obrigado a todos que me ajudaram.

  1. <?php
  2. class BensQueryReport extends TPage
  3. {
  4.     private $form;
  5.     
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         
  10.         $this->form = new BootstrapFormBuilder;
  11.         $this->form->setFormTitle('Clientes');
  12.         
  13.         $combo_destino  = new TDBUniqueSearch('destino_id''patrimonio''Destino''id''nome');
  14.         $output         = new TRadioGroup('output');
  15.         
  16.         $this->form->addFields( [new TLabel('Cidade')], [$combo_destino] );
  17.         $this->form->addFields( [new TLabel('Formato')], [$output] );
  18.         
  19.         $output->setUseButton();
  20.         $combo_destino->setMinLength(1);
  21.         
  22.         $output->addItems( ['html' => 'HTML''pdf' => 'PDF''rtf' => 'RTF''xls' => 'XLS'] );
  23.         $output->setValue'pdf' );
  24.         $output->setLayout('horizontal');
  25.         
  26.         $this->form->addAction('Gerar', new TAction([$this'onGenerate']), 'fa:download blue');
  27.         $this->form->addActionLink('Voltar', new TAction(array('BensList','onReload')),'fa:table blue');
  28.         parent::add$this->form );
  29.     }
  30.     
  31.     public function onGenerate($param)
  32.     {
  33.         try
  34.         {
  35.             $conn TTransaction::open('patrimonio');
  36.             $data $this->form->getData();
  37.             
  38.             if (!$data->destino_id){
  39.                 $sql "SELECT m.destino_id,d.nome, m.bens_id,b.num_tombamento, b.descricao, e.estadoprod, m.ativo FROM movimentacao m 
  40.                                     JOIN bens AS b ON m.bens_id = b.id  
  41.                                     JOIN destino AS d ON m.destino_id = d.id 
  42.                                     JOIN estadoprod as e ON b.estadoprod_id = e.id
  43.                                     WHERE m.ativo = 'S' ORDER BY m.destino_id;";
  44.                 //echo'Entrou no primeiro....';                     
  45.                 $rows TDatabase::getData$conn$sqlnull );                    
  46.             }else{
  47.                 $sql "SELECT m.destino_id,d.nome, m.bens_id,b.num_tombamento, b.descricao, e.estadoprod, m.ativo FROM movimentacao m 
  48.                                     JOIN bens AS b ON m.bens_id = b.id  
  49.                                     JOIN destino AS d ON m.destino_id = d.id 
  50.                                     JOIN estadoprod as e ON b.estadoprod_id = e.id
  51.                                     WHERE m.ativo = 'S' and m.destino_id = :destino_id ORDER BY m.destino_id;";
  52.                 //echo'Entrou no segundo....';                                    
  53.                 $rows TDatabase::getData$conn$sqlnull, [ 'destino_id' => $data->destino_id ] );                                    
  54.             
  55.             }                        
  56.             
  57.             if ($rows)
  58.             {
  59.                 //$widths = [40, 200, 80, 120, 80];
  60.                 $widths = [800nullnull,nullnull];
  61.                                 
  62.                 switch ($data->output)
  63.                 {
  64.                     case 'html':
  65.                         $table = new TTableWriterHTML($widths);
  66.                         break;
  67.                     case 'pdf':
  68.                         $table = new TTableWriterPDF($widths);
  69.                         break;
  70.                     case 'rtf':
  71.                         $table = new TTableWriterRTF($widths);
  72.                         break;
  73.                     case 'xls':
  74.                         $table = new TTableWriterXLS($widths);
  75.                         break;
  76.                 }
  77.                 // id, nome, categoria, email, nascimento
  78.             
  79.                 if (!empty($table))
  80.                 {
  81.                     $table->addStyle('header''Helvetica''16''B''#ffffff''#4B5D8E');
  82.                     $table->addStyle('title',  'Helvetica''10''B''#ffffff''#617FC3');
  83.                     $table->addStyle('datap',  'Helvetica''10''B',  '#000000''#E3E3E3''LR');
  84.                     $table->addStyle('datai',  'Helvetica''10''',  '#000000''#ffffff''LR');
  85.                     $table->addStyle('footer''Helvetica''10''',  '#2B2B2B''#B4CAFF');
  86.                 }
  87.                 
  88.                 $table->setHeaderCallback( function($table) {
  89.                     $table->addRow();
  90.                     $table->addCell('Listagem de Bens Patrimoniais por Setor''center''header'5);
  91.                     
  92.                     $table->addRow();
  93.                     $table->addCell('Setor''left''title');
  94.                     $table->addRow();
  95.                     $table->addCell('Bem Patrimonial''left''title');
  96.                 });
  97.                 
  98.                 $table->setFooterCallback( function ($table) {
  99.                     $table->addRow();
  100.                     $table->addCell(date('d/m/Y H:i:s'), 'right''footer'5);
  101.                 });
  102.                 
  103.                 $colore true;
  104.                 $previous_dest null;
  105.                 foreach ($rows as $row)
  106.                 {
  107.                     //$style = $colore ? 'datap' : 'datai';
  108.                     
  109.                     if ($row['destino_id'] != $previous_dest) {  // checa se destino se é diferente do anterior
  110.                         $style 'datap';
  111.                         $table->addRow();
  112.                         $table->addCell$row['destino_id'].' - '.$row['nome'], 'left'$style);
  113.                         $style 'datai';
  114.                     }
  115.                     
  116.                     $table->addRow();
  117.                     $table->addCell'     '.$row['num_tombamento'].' - '.$row['descricao'].'   ('.$row['estadoprod'].')''left'$style);
  118.                     
  119.                     $previous_dest $row['destino_id'];     
  120.                     $colore = !$colore;
  121.                 }
  122.                 
  123.                 $output 'app/output/tabular.'.$data->output;
  124.                 
  125.                 if (!file_exists($output) OR is_writable($output))
  126.                 {
  127.                     $table->save($output);
  128.                     parent::openFile($output);
  129.                     
  130.                     new TMessage('info''Relatório gerado com sucesso');
  131.                 }
  132.                 else
  133.                 {
  134.                     throw new Exception('Permissão negada: ' $output);
  135.                 }
  136.                 
  137.                 return;
  138.                 
  139.             }
  140.             
  141.             $this->form->setData($data);
  142.             
  143.             TTransaction::close();
  144.         }
  145.         catch (Exception $e)
  146.         {
  147.             new TMessage('error'$e->getMessage());
  148.         }
  149.     }
  150.     function onshow()
  151.     {
  152.         parent::show();
  153.     }
  154.     
  155. }

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (0)