AR
Relação em forma de Etiqueta
- <?php
- /**
- * Tabular report
- *
- * @version 1.0
- * @package
- * @subpackage
- * @author
- * @copyright
- * @license http://www.adianti.com.br/framework-license
- */
- //http://fontawesome.io/icons/#web-application
- class Catalogo1ReportView extends TPage
- {
- private $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TForm('form_ReportPedido_adm');
- $this->form->class = 'tform'; // CSS class
- // creates a table
- $table = new TTable;
- $table-> width = '100%';
- // add the table inside the form
- $this->form->add($table);
- // create the form fields
- $id = new TDBCombo('id','catalogo','Product','id','description_codprod');
- $description = new TEntry('description');
- $codprod_inic = new TEntry('codprod_inic');
- $codprod_fim = new TEntry('codprod_fim');
- // define the sizes
- $id->setSize(300);
- $codprod_inic->setMask('999999');
- $codprod_fim->setMask('999999');
- $codprod_inic->setSize(80);
- $codprod_fim->setSize(80);
- $output_type = new TRadioGroup('output_type');
- $options = array('html' => 'HTML', 'pdf' => 'PDF', 'rtf' => 'RTF');
- $output_type->addItems($options);
- $output_type->setValue('pdf');
- $output_type->setLayout('horizontal');
- // add a row for the field name
- $row = $table->addRowSet(new TLabel('Filtro : Consulta de Produtos'), '');
- $row->class = 'tformtitle'; // CSS class
- // add the fields into the table
- $table->addRowSet(new TLabel('Produto'. ':'), $id);
- $table->addRowSet(new TLabel('Produto Inic :'), array($codprod_inic, new TLabel('Produto Final:'), $codprod_fim));
- $table->addRowSet(new TLabel('Output' . ': '), $output_type);
- // create an action button (save)
- $save_button=new TButton('generate');
- $save_button->setAction(new TAction(array($this, 'onGenerate')), 'Imprime');
- $save_button->setImage('fa: fa-print blue');
- // add a row for the form action
- $row = $table->addRowSet($save_button, '');
- $row->class = 'tformaction';
- // define wich are the form fields
- // $this->form->setFields(array($memb_nome,$classeebd_id,$classe_nome,$profissao_id,$statusmembro_id,$memb_ativo,$output_type,$save_button));
- $this->form->setFields(array($id,$codprod_inic,$codprod_fim,$description,$output_type,$save_button));
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * method onGenerate()
- * Executed whenever the user clicks at the generate button
- */
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('catalogo');
- // get the form data into an active record Customer
- $object = $this->form->getData();
- $mfunc= new Functerceiro();
- $repository = new TRepository('Product');
- $criteria = new TCriteria;
- if ($object->id)
- {
- $criteria->add(new TFilter('id', '=', "{$object->id}"));
- }
- if ($object->description)
- {
- // $criteria->add(new TFilter('description', '=', "{$object->description}"));
- $criteria->add(new TFilter('sem_acento(description)', 'ilike', $mfunc->removeracentos(strtoupper(utf8_decode("%{$object->description}%")))));
- }
- if ($object->codprod_inic)
- {
- $criteria->add(new TFilter('codigo', '>=', "$object->codprod_inic"));
- }
- if ($object->codprod_fim)
- {
- $criteria->add(new TFilter('codigo', '<=', "$object->codprod_fim"));
- }
- $count= $repository->count($criteria);
- $Produtos = $repository->load($criteria);
- $format = $object->output_type;
- if ($Produtos)
- {
- $widths = array(40, 180, 20, 60);
- switch ($format)
- {
- case 'html':
- $tr = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $tr = new TTableWriterPDF($widths);
- break;
- case 'rtf':
- if (!class_exists('PHPRtfLite_Autoloader'))
- {
- PHPRtfLite::registerAutoloader();
- }
- $tr = new TTableWriterRTF($widths);
- break;
- }
- // create the document styles
- $tr->addStyle('title', 'Arial', '8', 'BI', '#252526', '#F1F1F1');
- $tr->addStyle('datap', 'Arial', '8', '', '#000000', '#869FBB');
- $tr->addStyle('datai', 'Arial', '8', '', '#000000', '#ffffff');
- $tr->addStyle('header', 'Times', '16', 'BI', '#F1F1F1', '#252526');
- $tr->addStyle('footer', 'Times', '12', 'BI', '#2B2B2B', '#F5F5F5');
- // add a header row
- $tr->addRow();
- $tr->addCell('Relação de Produtos', 'center', 'header', 4);
- // add titles row
- $tr->addRow();
- $tr->addCell('Produto(s) na consulta '.$count , 'center', 'title',4);
- $tr->addRow();
- $tr->addCell('Codigo', 'center', 'title');
- $tr->addCell('Descrição', 'center', 'title');
- $tr->addCell('Un', 'center', 'title');
- $tr->addCell('Preço', 'left', 'title');
- // $tr->addCell('Foto', 'center', 'title');
- // controls the background filling
- $colour= FALSE;
- // data rows
- foreach ($Produtos as $produto)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- // $tr->addCell($produto->id, 'center', $style);
- $tr->addCell($produto->codigo, 'center', $style);
- $tr->addCell($mfunc->removeracentos(strtoupper(utf8_decode($produto->description))),'left', $style);
- $tr->addCell(number_format($produto->unity, 2, ',', '.'), 'center', $style);
- $tr->addCell($produto->sale_price, 'center', $style);
- // $tr->addCell($produto->photo_path, 'center', $style);
- $colour = !$colour;
- }
- // footer row
- $tr->addRow();
- $tr->addCell(date('d-m-Y h:i:s'), 'center', 'footer', 4);
- // stores the file
- if (!file_exists("app/output/tabular.{$format}") OR is_writable("app/output/tabular.{$format}"))
- {
- $tr->save("app/output/tabular.{$format}");
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . "app/output/tabular.{$format}");
- }
- parent::openFile("app/output/tabular.{$format}");
- // shows the success message
- new TMessage('info', 'Report generated. Please, enable popups in the browser (just in the web).');
- }
- else
- {
- new TMessage('error', 'No records found');
- }
- // fill the form with the active record data
- $this->form->setData($object);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
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.
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...
Obrigado Nataniel. Posso instanciar TPDFDesigner junto com TTableWriterPdf para inserir imagens ?
Ex:
Pode ser assim ? Terei como controlar também altura das colunas com $tr->addCell ?
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.
Nataniel, consegui colocar a imagem também, criei os controles de posição das etiquetas na mão e ficou como eu precisava.
Obrigado.
Não seria o caso de usar este exemplo??
www.adianti.com.br/framework_files/tutor/index.php?class=ProductCata
Posso gerar um PDF com esse exemplo ? Como e
Como seria ?