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


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.

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 (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. $style = $colour ? 'datap' : 'datai';
  7. $tr->addRow();
  8. $tr->addCell($produto->codigo, 'center', $style);
  9. $tr->addCell($mfunc->removeracentos(strtoupper(utf8_decode($produto->description))),'left', $style);
  10. $tr->addCell($produto->unity, 'center', $style);
  11. $tr->addCell(number_format($produto->sale_price, 2, ',', '.'), 'center', $style);
  12. $designer->Image('$produto->photo_path/",40,17,90,75,'png');
  13. }
  14. ?>


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 ?