Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Relação em forma de Etiqueta ...
AR
Relação em forma de Etiqueta  
  1. <?php
  2. /**
  3.  * Tabular report
  4.  *
  5.  * @version    1.0
  6.  * @package     
  7.  * @subpackage  
  8.  * @author      
  9.  * @copyright   
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12.  //http://fontawesome.io/icons/#web-application
  13. class Catalogo1ReportView extends TPage
  14. {
  15.     private $form// form
  16.     
  17.     /**
  18.      * Class constructor
  19.      * Creates the page and the registration form
  20.      */
  21.     function __construct()
  22.     {
  23.         parent::__construct();
  24.         
  25.         // creates the form
  26.         $this->form = new TForm('form_ReportPedido_adm');
  27.         $this->form->class 'tform'// CSS class
  28.         
  29.         // creates a table
  30.         $table = new TTable;
  31.         $table-> width '100%';
  32.         
  33.         // add the table inside the form
  34.         $this->form->add($table);
  35.         // create the form fields
  36.         $id = new TDBCombo('id','catalogo','Product','id','description_codprod');
  37.         $description = new TEntry('description');
  38.         $codprod_inic = new TEntry('codprod_inic');
  39.         $codprod_fim  = new TEntry('codprod_fim');
  40.      
  41.         // define the sizes
  42.         $id->setSize(300);
  43.         $codprod_inic->setMask('999999');
  44.         $codprod_fim->setMask('999999');
  45.         $codprod_inic->setSize(80);
  46.         $codprod_fim->setSize(80);
  47.       
  48.         $output_type  = new TRadioGroup('output_type');
  49.         
  50.         $options = array('html' => 'HTML''pdf' => 'PDF''rtf' => 'RTF');
  51.         $output_type->addItems($options);
  52.         $output_type->setValue('pdf');
  53.         $output_type->setLayout('horizontal');
  54.         
  55.        
  56.         
  57.         // add a row for the field name
  58.         $row  $table->addRowSet(new TLabel('Filtro : Consulta de Produtos'), '');
  59.         $row->class 'tformtitle'// CSS class
  60.         
  61.         // add the fields into the table
  62.         $table->addRowSet(new TLabel('Produto'':'), $id);
  63.         $table->addRowSet(new TLabel('Produto Inic :'), array($codprod_inic, new TLabel('Produto Final:'), $codprod_fim)); 
  64.         $table->addRowSet(new TLabel('Output' ': '), $output_type);
  65.         
  66.         // create an action button (save)
  67.         $save_button=new TButton('generate');
  68.         $save_button->setAction(new TAction(array($this'onGenerate')), 'Imprime');
  69.         $save_button->setImage('fa: fa-print blue');
  70.         // add a row for the form action
  71.         $row $table->addRowSet($save_button'');
  72.         $row->class 'tformaction';
  73.         // define wich are the form fields
  74.       //  $this->form->setFields(array($memb_nome,$classeebd_id,$classe_nome,$profissao_id,$statusmembro_id,$memb_ativo,$output_type,$save_button));
  75.         $this->form->setFields(array($id,$codprod_inic,$codprod_fim,$description,$output_type,$save_button));
  76.   
  77.  
  78.   
  79.         // wrap the page content using vertical box
  80.         $vbox = new TVBox;
  81.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  82.         $vbox->add($this->form);
  83.         parent::add($vbox);
  84.     }
  85.     /**
  86.      * method onGenerate()
  87.      * Executed whenever the user clicks at the generate button
  88.      */
  89.     function onGenerate()
  90.     {
  91.         try
  92.         {
  93.             // open a transaction with database 'samples'
  94.             TTransaction::open('catalogo');
  95.             
  96.             // get the form data into an active record Customer
  97.             $object $this->form->getData();
  98.             $mfunc= new Functerceiro();
  99.             
  100.             $repository = new TRepository('Product');
  101.             $criteria   = new TCriteria;
  102.            
  103.            
  104.           
  105.             if ($object->id)
  106.             {
  107.                 $criteria->add(new TFilter('id''='"{$object->id}"));
  108.             }
  109.             
  110.             if ($object->description)
  111.             {
  112.              //   $criteria->add(new TFilter('description', '=', "{$object->description}"));
  113.                 $criteria->add(new TFilter('sem_acento(description)''ilike'$mfunc->removeracentos(strtoupper(utf8_decode("%{$object->description}%")))));
  114.             }
  115.            
  116.            if ($object->codprod_inic)
  117.             {
  118.                 $criteria->add(new TFilter('codigo''>='"$object->codprod_inic")); 
  119.             }
  120.             
  121.             if ($object->codprod_fim)
  122.             {
  123.                 $criteria->add(new TFilter('codigo''<='"$object->codprod_fim"));        
  124.             }
  125.     
  126.          
  127.             
  128.             $count$repository->count($criteria);
  129.             $Produtos $repository->load($criteria);
  130.             $format  $object->output_type;
  131.             
  132.             if ($Produtos)
  133.             {
  134.                 $widths = array(401802060);
  135.                 
  136.                 switch ($format)
  137.                 {
  138.                     case 'html':
  139.                         $tr = new TTableWriterHTML($widths);
  140.                         break;
  141.                     case 'pdf':
  142.                         $tr = new TTableWriterPDF($widths);
  143.                         break;
  144.                     case 'rtf':
  145.                         if (!class_exists('PHPRtfLite_Autoloader'))
  146.                         {
  147.                             PHPRtfLite::registerAutoloader();
  148.                         }
  149.                         $tr = new TTableWriterRTF($widths);
  150.                         break;
  151.                 }
  152.                 
  153.                 // create the document styles
  154.                 $tr->addStyle('title''Arial''8''BI',  '#252526''#F1F1F1');
  155.                 $tr->addStyle('datap''Arial''8''',    '#000000''#869FBB');
  156.                 $tr->addStyle('datai''Arial''8''',    '#000000''#ffffff');
  157.                 $tr->addStyle('header''Times''16''BI''#F1F1F1''#252526');
  158.                 $tr->addStyle('footer''Times''12''BI''#2B2B2B''#F5F5F5');
  159.                
  160.                 // add a header row
  161.                 $tr->addRow();
  162.                 $tr->addCell('Relação de Produtos''center''header'4);
  163.                 
  164.                 // add titles row
  165.                 $tr->addRow();
  166.                 $tr->addCell('Produto(s) na consulta '.$count 'center''title',4);
  167.                 $tr->addRow();
  168.                 $tr->addCell('Codigo',      'center''title');
  169.                 $tr->addCell('Descrição',      'center''title');
  170.                 $tr->addCell('Un',      'center''title');
  171.                 $tr->addCell('Preço',  'left''title');
  172.              //   $tr->addCell('Foto',     'center', 'title');
  173.                 
  174.                 // controls the background filling
  175.                 $colourFALSE;
  176.                 
  177.                 // data rows
  178.                 foreach ($Produtos as $produto)
  179.                 {
  180.                     $style $colour 'datap' 'datai';
  181.                     $tr->addRow();
  182.                  //   $tr->addCell($produto->id,                 'center', $style);
  183.                     $tr->addCell($produto->codigo,                 'center'$style);
  184.                     $tr->addCell($mfunc->removeracentos(strtoupper(utf8_decode($produto->description))),'left'$style);
  185.                     $tr->addCell(number_format($produto->unity2',''.'),  'center'$style);
  186.                     $tr->addCell($produto->sale_price,          'center'$style);
  187.                   //  $tr->addCell($produto->photo_path,  'center', $style);
  188.                     $colour = !$colour;
  189.                 }
  190.                 
  191.                 // footer row
  192.                 $tr->addRow();
  193.                 $tr->addCell(date('d-m-Y h:i:s'), 'center''footer'4);
  194.                 // stores the file
  195.                 if (!file_exists("app/output/tabular.{$format}") OR is_writable("app/output/tabular.{$format}"))
  196.                 {
  197.                     $tr->save("app/output/tabular.{$format}");
  198.                 }
  199.                 else
  200.                 {
  201.                     throw new Exception(_t('Permission denied') . ': ' "app/output/tabular.{$format}");
  202.                 }
  203.                 
  204.                 parent::openFile("app/output/tabular.{$format}");
  205.                 
  206.                 // shows the success message
  207.                 new TMessage('info''Report generated. Please, enable popups in the browser (just in the web).');
  208.             }
  209.             else
  210.             {
  211.                 new TMessage('error''No records found');
  212.             }
  213.     
  214.             // fill the form with the active record data
  215.             $this->form->setData($object);
  216.             
  217.             // close the transaction
  218.             TTransaction::close();
  219.         }
  220.         catch (Exception $e// in case of exception
  221.         {
  222.             // shows the exception error message
  223.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  224.             
  225.             // undo all pending operations
  226.             TTransaction::rollback();
  227.         }
  228.     }
  229. }
  230. ?>


Olá, tenho a necessidade de transformar esta relação tabular, em uma relação na forma de catálogo "Etiqueta" com as colunas definidas programaticamente como o exemplo em anexo. É possível usando somente recurso do Framework ? Como posso iniciar ? Grato.

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


NR

Adriano, você teria que modificar as classes TTableWriter. Por exemplo, a TTableWriterPdf utiliza a função cell da FPDF para desenhar as colunas. Como você deseja incluir imagens, teria que criar outra função na classe para usar a função image da FPDF...
AR

Obrigado Nataniel. Posso instanciar TPDFDesigner junto com TTableWriterPdf para inserir imagens ?


Ex:

  1. <?php
  2. $tr = new TTableWriterPDF($widths);
  3. $designer = new TPDFDesigner;
  4.  foreach ($Produtos as $produto)
  5.                 {
  6.                   
  7.                    $style $colour 'datap' 'datai';
  8.                     $tr->addRow();
  9.                     $tr->addCell($produto->codigo,                 'center'$style);
  10.                     $tr->addCell($mfunc->removeracentos(strtoupper(utf8_decode($produto->description))),'left'$style);
  11.                     $tr->addCell($produto->unity,  'center'$style);
  12.                     $tr->addCell(number_format($produto->sale_price2',''.'),          'center'$style);
  13.                      $designer->Image('$produto->photo_path/",40,17,90,75,'png');
  14.                 }
  15. ?>


Pode ser assim ? Terei como controlar também altura das colunas com $tr->addCell ?

NR

Acho que assim não funcionaria, pois cada classe(TPDFDesigner e TTableWriterPDF) cria uma instância diferente da FPDF.
A altura da célula é calculada automaticamente pela TTableWriterPDF com base no tamanho da fonte.

Acredito ser mais simples gerar esse relatório usando diretamente a FPDF.
AR

Nataniel, consegui colocar a imagem também, criei os controles de posição das etiquetas na mão e ficou como eu precisava.
Obrigado.

  1. <?php
  2.                    $tr = new  TPDFDesigner;
  3.                     $tr->Image($produto->photo_path,$somaH$somaV 12,150,0);
  4.                     $tr->Text($somaH$somaV 180,'Codigo:'.$produto->codigo);
  5.                     $tr->Text($somaH$somaV 190,$mfunc->removeracentos(strtoupper(utf8_decode($produto->description))));
  6.                     $tr->Text($somaH$somaV 200,$produto->unity.' - '.$produto->sale_price);
  7. ?>
WP

Não seria o caso de usar este exemplo??

www.adianti.com.br/framework_files/tutor/index.php?class=ProductCata
AR

Posso gerar um PDF com esse exemplo ? Como e
AR

Como seria ?