Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Imprimir Nota Gerada Pelo PDF Designer por meio de uma Listagem Pessoal, a situação é a seguinte, tenho o Adianti Studio Pro, e gostaria de após gerar minha LISTAGEM de NOTAS, quero inserir uma ação que, ao clicar nesse botão, eu imprima(gere) a Nota chamando o arquivo nfe.pdf.xml. Mas vejam o detalhe. Eu gostaria de gerar por meio de minha listagem gerada pelo Adianti Studio Pro. Um exemplo é, nessa lista: www.adianti.com.br/framework_files/tutor/in...
PS
Imprimir Nota Gerada Pelo PDF Designer por meio de uma Listagem  
Pessoal, a situação é a seguinte, tenho o Adianti Studio Pro, e gostaria de após gerar minha LISTAGEM de NOTAS, quero inserir uma ação que, ao clicar nesse botão, eu imprima(gere) a Nota chamando o arquivo nfe.pdf.xml. Mas vejam o detalhe. Eu gostaria de gerar por meio de minha listagem gerada pelo Adianti Studio Pro.
Um exemplo é, nessa lista: www.adianti.com.br/framework_files/tutor/index.php?class=SaleList
Quero criar uma ação colocando um botão para gerar a NOTA de acordo com a venda selecionada.

Desde já agradeço a todos.

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


NR

Paulo, qual é exatamente sua dúvida? Já conseguiu gerar a ação na listagem e falta só instanciar a classe PDFDesigner?

Segue mais ou menos a estrutura de código necessária:
  1. <?php
  2. public function onPrintNota($param)
  3. {
  4.          ...
  5.          $object = new SeuModel($param['key']);
  6.          ...
  7.          $designer = new TPDFDesigner;
  8.          $designer->fromXml('app/reports/nfe.pdf.xml');
  9.          $designer->generate();
  10.          ...
  11. }
  12. ?>
PS

Minha dúvida é a seguinte:
Tenho essa Listagem de Vendas, nela tem os itens da venda que posso editar em um formulário mestre detalhe certo. O que quero é colocar um botão na listagem, igual o botão Editar que, ao clicar nesse botão eu imprima a nota 'app/reports/nfe.pdf.xml' e seus respectivos itens dessa venda selecionada. Segue o código da minha listagem:

  1. <?php
  2. /**
  3.  * VendasLista Listing
  4.  * @author  <your name here>
  5.  */
  6. class VendasLista extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_Vendas');
  25.         $this->form->setFormTitle('Vendas');
  26.         
  27.         // create the form fields
  28.         $id = new TEntry('id');
  29.         $data_venda = new TEntry('data_venda');
  30.         // add the fields
  31.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  32.         $this->form->addFields( [ new TLabel('Data Venda') ], [ $data_venda ] );
  33.         // set sizes
  34.         $id->setSize('100%');
  35.         $data_venda->setSize('100%');
  36.         
  37.         // keep the form filled during navigation with session data
  38.         $this->form->setDataTSession::getValue('Vendas_filter_data') );
  39.         
  40.         // add the search form actions
  41.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  42.         $btn->class 'btn btn-sm btn-primary';
  43.         $this->form->addActionLink(_t('New'), new TAction(['VendasForm''onEdit']), 'fa:plus green');
  44.         
  45.         // creates a Datagrid
  46.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  47.         $this->datagrid->style 'width: 100%';
  48.         $this->datagrid->datatable 'true';
  49.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  50.         
  51.         // creates the datagrid columns
  52.         $column_id = new TDataGridColumn('id''Id''right');
  53.         $column_data_venda = new TDataGridColumn('data_venda''Data Venda''left');
  54.         $column_qtde_itens = new TDataGridColumn('qtde_itens''Qtde Itens''left');
  55.         $column_total_vendas = new TDataGridColumn('total_vendas''Total Vendas''left');
  56.         // add the columns to the DataGrid
  57.         $this->datagrid->addColumn($column_id);
  58.         $this->datagrid->addColumn($column_data_venda);
  59.         $this->datagrid->addColumn($column_qtde_itens);
  60.         $this->datagrid->addColumn($column_total_vendas);
  61.         
  62.         // create EDIT action
  63.         $action_edit = new TDataGridAction(['VendasForm''onEdit']);
  64.         //$action_edit->setUseButton(TRUE);
  65.         //$action_edit->setButtonClass('btn btn-default');
  66.         $action_edit->setLabel(_t('Edit'));
  67.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  68.         $action_edit->setField('id');
  69.         $this->datagrid->addAction($action_edit);
  70.         
  71.         // create DELETE action
  72.         $action_del = new TDataGridAction(array($this'onDelete'));
  73.         //$action_del->setUseButton(TRUE);
  74.         //$action_del->setButtonClass('btn btn-default');
  75.         $action_del->setLabel(_t('Delete'));
  76.         $action_del->setImage('fa:trash-o red fa-lg');
  77.         $action_del->setField('id');
  78.         $this->datagrid->addAction($action_del);
  79.         
  80.         // create the datagrid model
  81.         $this->datagrid->createModel();
  82.         
  83.         // creates the page navigation
  84.         $this->pageNavigation = new TPageNavigation;
  85.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  86.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  87.         
  88.         // vertical box container
  89.         $container = new TVBox;
  90.         $container->style 'width: 90%';
  91.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  92.         $container->add($this->form);
  93.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  94.         
  95.         parent::add($container);
  96.     }
  97.     
  98.     /**
  99.      * Inline record editing
  100.      * @param $param Array containing:
  101.      *              key: object ID value
  102.      *              field name: object attribute to be updated
  103.      *              value: new attribute content 
  104.      */
  105.     public function onInlineEdit($param)
  106.     {
  107.         try
  108.         {
  109.             // get the parameter $key
  110.             $field $param['field'];
  111.             $key   $param['key'];
  112.             $value $param['value'];
  113.             
  114.             TTransaction::open('estoque'); // open a transaction with database
  115.             $object = new Vendas($key); // instantiates the Active Record
  116.             $object->{$field} = $value;
  117.             $object->store(); // update the object in the database
  118.             TTransaction::close(); // close the transaction
  119.             
  120.             $this->onReload($param); // reload the listing
  121.             new TMessage('info'"Record Updated");
  122.         }
  123.         catch (Exception $e// in case of exception
  124.         {
  125.             new TMessage('error'$e->getMessage()); // shows the exception error message
  126.             TTransaction::rollback(); // undo all pending operations
  127.         }
  128.     }
  129.     
  130.     /**
  131.      * Register the filter in the session
  132.      */
  133.     public function onSearch()
  134.     {
  135.         // get the search form data
  136.         $data $this->form->getData();
  137.         
  138.         // clear session filters
  139.         TSession::setValue('VendasLista_filter_id',   NULL);
  140.         TSession::setValue('VendasLista_filter_data_venda',   NULL);
  141.         if (isset($data->id) AND ($data->id)) {
  142.             $filter = new TFilter('id''='"$data->id"); // create the filter
  143.             TSession::setValue('VendasLista_filter_id',   $filter); // stores the filter in the session
  144.         }
  145.         if (isset($data->data_venda) AND ($data->data_venda)) {
  146.             $filter = new TFilter('data_venda''='"$data->data_venda"); // create the filter
  147.             TSession::setValue('VendasLista_filter_data_venda',   $filter); // stores the filter in the session
  148.         }
  149.         
  150.         // fill the form with data again
  151.         $this->form->setData($data);
  152.         
  153.         // keep the search data in the session
  154.         TSession::setValue('Vendas_filter_data'$data);
  155.         
  156.         $param = array();
  157.         $param['offset']    =0;
  158.         $param['first_page']=1;
  159.         $this->onReload($param);
  160.     }
  161.     
  162.     /**
  163.      * Load the datagrid with data
  164.      */
  165.     public function onReload($param NULL)
  166.     {
  167.         try
  168.         {
  169.             // open a transaction with database 'estoque'
  170.             TTransaction::open('estoque');
  171.             
  172.             // creates a repository for Vendas
  173.             $repository = new TRepository('Vendas');
  174.             $limit 10;
  175.             // creates a criteria
  176.             $criteria = new TCriteria;
  177.             
  178.             // default order
  179.             if (empty($param['order']))
  180.             {
  181.                 $param['order'] = 'id';
  182.                 $param['direction'] = 'asc';
  183.             }
  184.             $criteria->setProperties($param); // order, offset
  185.             $criteria->setProperty('limit'$limit);
  186.             
  187.             if (TSession::getValue('VendasLista_filter_id')) {
  188.                 $criteria->add(TSession::getValue('VendasLista_filter_id')); // add the session filter
  189.             }
  190.             if (TSession::getValue('VendasLista_filter_data_venda')) {
  191.                 $criteria->add(TSession::getValue('VendasLista_filter_data_venda')); // add the session filter
  192.             }
  193.             
  194.             // load the objects according to criteria
  195.             $objects $repository->load($criteriaFALSE);
  196.             
  197.             if (is_callable($this->transformCallback))
  198.             {
  199.                 call_user_func($this->transformCallback$objects$param);
  200.             }
  201.             
  202.             $this->datagrid->clear();
  203.             if ($objects)
  204.             {
  205.                 // iterate the collection of active records
  206.                 foreach ($objects as $object)
  207.                 {
  208.                     // add the object inside the datagrid
  209.                     $this->datagrid->addItem($object);
  210.                 }
  211.             }
  212.             
  213.             // reset the criteria for record count
  214.             $criteria->resetProperties();
  215.             $count$repository->count($criteria);
  216.             
  217.             $this->pageNavigation->setCount($count); // count of records
  218.             $this->pageNavigation->setProperties($param); // order, page
  219.             $this->pageNavigation->setLimit($limit); // limit
  220.             
  221.             // close the transaction
  222.             TTransaction::close();
  223.             $this->loaded true;
  224.         }
  225.         catch (Exception $e// in case of exception
  226.         {
  227.             // shows the exception error message
  228.             new TMessage('error'$e->getMessage());
  229.             // undo all pending operations
  230.             TTransaction::rollback();
  231.         }
  232.     }
  233.     
  234.     /**
  235.      * Ask before deletion
  236.      */
  237.     public static function onDelete($param)
  238.     {
  239.         // define the delete action
  240.         $action = new TAction([__CLASS__'Delete']);
  241.         $action->setParameters($param); // pass the key parameter ahead
  242.         
  243.         // shows a dialog to the user
  244.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  245.     }
  246.     
  247.     /**
  248.      * Delete a record
  249.      */
  250.     public static function Delete($param)
  251.     {
  252.         try
  253.         {
  254.             $key=$param['key']; // get the parameter $key
  255.             TTransaction::open('estoque'); // open a transaction with database
  256.             $object = new Vendas($keyFALSE); // instantiates the Active Record
  257.             $object->delete(); // deletes the object from the database
  258.             TTransaction::close(); // close the transaction
  259.             
  260.             $pos_action = new TAction([__CLASS__'onReload']);
  261.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  262.         }
  263.         catch (Exception $e// in case of exception
  264.         {
  265.             new TMessage('error'$e->getMessage()); // shows the exception error message
  266.             TTransaction::rollback(); // undo all pending operations
  267.         }
  268.     }
  269.     
  270.     
  271.     /**
  272.      * method show()
  273.      * Shows the page
  274.      */
  275.     public function show()
  276.     {
  277.         // check if the datagrid is already loaded
  278.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  279.         {
  280.             if (func_num_args() > 0)
  281.             {
  282.                 $this->onReloadfunc_get_arg(0) );
  283.             }
  284.             else
  285.             {
  286.                 $this->onReload();
  287.             }
  288.         }
  289.         parent::show();
  290.     }
  291. }
  292. </your>
PS

Segue também o código do meu formulário de Edição da venda com seus itens:

  1. <?php
  2. /**
  3.  * VendasForm Master/Detail
  4.  * @author  <your name here>
  5.  */
  6. class VendasForm extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     
  11.     /**
  12.      * Page constructor
  13.      */
  14.     public function __construct()
  15.     {
  16.         parent::__construct();
  17.         
  18.         // creates the form
  19.         $this->form = new BootstrapFormBuilder('form_Vendas');
  20.         $this->form->setFormTitle('Vendas');
  21.         
  22.         // master fields
  23.         $id = new TEntry('id');
  24.         $data_venda = new TDate('data_venda');
  25.         $qtde_itens = new TEntry('qtde_itens');
  26.         $total_vendas = new TEntry('total_vendas');
  27.         // detail fields
  28.         $detail_id = new THidden('detail_id');
  29.         $detail_produtos_id = new TDBUniqueSearch('detail_produtos_id''estoque''Produtos''id''nome');
  30.         $detail_qtde = new TEntry('detail_qtde');
  31.         $detail_total_item = new TEntry('detail_total_item');
  32.         $detail_preco = new TEntry('detail_preco');
  33.         if (!empty($id))
  34.         {
  35.             $id->setEditable(FALSE);
  36.         }
  37.         
  38.         // master fields
  39.         $this->form->addFields( [new TLabel('Id')], [$id] );
  40.         $this->form->addFields( [new TLabel('Data Venda')], [$data_venda] );
  41.         $this->form->addFields( [new TLabel('Qtde Itens')], [$qtde_itens] );
  42.         $this->form->addFields( [new TLabel('Total Vendas')], [$total_vendas] );
  43.         
  44.         // detail fields
  45.         $this->form->addContent( ['<h4>Details</h4><hr>'] );
  46.         $this->form->addFields( [$detail_id] );
  47.         
  48.         $this->form->addFields( [new TLabel('Produtos Id')], [$detail_produtos_id] );
  49.         $this->form->addFields( [new TLabel('Qtde')], [$detail_qtde] );
  50.         $this->form->addFields( [new TLabel('Total Item')], [$detail_total_item] );
  51.         $this->form->addFields( [new TLabel('Preco')], [$detail_preco] );
  52.         $add TButton::create('add', [$this'onSaveDetail'], 'Register''fa:save');
  53.         $this->form->addFields( [], [$add] )->style 'background: whitesmoke; padding: 5px; margin: 1px;';
  54.         
  55.         $this->detail_list = new BootstrapDatagridWrapper(new TQuickGrid);
  56.         $this->detail_list->style "min-width: 700px; width:100%;margin-bottom: 10px";
  57.         $this->detail_list->setId('Vendas_list');
  58.         
  59.         // items
  60.         $this->detail_list->addQuickColumn('Produtos Id''produtos_id''left'100);
  61.         $this->detail_list->addQuickColumn('Qtde''qtde''left'100);
  62.         $this->detail_list->addQuickColumn('Total Item''total_item''left'100);
  63.         $this->detail_list->addQuickColumn('Preco''preco''left'100);
  64.         // detail actions
  65.         $this->detail_list->addQuickAction'Edit',   new TDataGridAction([$this'onEditDetail']),   'id''fa:edit blue');
  66.         $this->detail_list->addQuickAction'Delete', new TDataGridAction([$this'onDeleteDetail']), 'id''fa:trash red');
  67.         $this->detail_list->createModel();
  68.         
  69.         $panel = new TPanelGroup;
  70.         $panel->add($this->detail_list);
  71.         $panel->getBody()->style 'overflow-x:auto';
  72.         $this->form->addContent( [$panel] );
  73.         $btn $this->form->addAction_t('Save'),  new TAction([$this'onSave']), 'fa:save');
  74.         $btn->class 'btn btn-sm btn-primary';
  75.         $this->form->addAction_t('Clear'), new TAction([$this'onClear']), 'fa:eraser red');
  76.         
  77.         // create the page container
  78.         $container = new TVBox;
  79.         $container->style 'width: 90%';
  80.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  81.         $container->add($this->form);
  82.         parent::add($container);
  83.     }
  84.     
  85.     
  86.     /**
  87.      * Clear form
  88.      * @param $param URL parameters
  89.      */
  90.     public function onClear($param)
  91.     {
  92.         $this->form->clear(TRUE);
  93.         TSession::setValue(__CLASS__.'_items', array());
  94.         $this->onReload$param );
  95.     }
  96.     
  97.     /**
  98.      * Save an item from form to session list
  99.      * @param $param URL parameters
  100.      */
  101.     public function onSaveDetail$param )
  102.     {
  103.         try
  104.         {
  105.             TTransaction::open('estoque');
  106.             $data $this->form->getData();
  107.             
  108.             /** validation sample
  109.             if (empty($data->fieldX))
  110.             {
  111.                 throw new Exception('The field fieldX is required');
  112.             }
  113.             **/
  114.             
  115.             $items TSession::getValue(__CLASS__.'_items');
  116.             $key = empty($data->detail_id) ? 'X'.mt_rand(10000000001999999999) : $data->detail_id;
  117.             
  118.             $items$key ] = array();
  119.             $items$key ]['id'] = $key;
  120.             $items$key ]['produtos_id'] = $data->detail_produtos_id;
  121.             $items$key ]['qtde'] = $data->detail_qtde;
  122.             $items$key ]['total_item'] = $data->detail_total_item;
  123.             $items$key ]['preco'] = $data->detail_preco;
  124.             
  125.             TSession::setValue(__CLASS__.'_items'$items);
  126.             
  127.             // clear detail form fields
  128.             $data->detail_id '';
  129.             $data->detail_produtos_id '';
  130.             $data->detail_qtde '';
  131.             $data->detail_total_item '';
  132.             $data->detail_preco '';
  133.             
  134.             TTransaction::close();
  135.             $this->form->setData($data);
  136.             
  137.             $this->onReload$param ); // reload the items
  138.         }
  139.         catch (Exception $e)
  140.         {
  141.             $this->form->setData$this->form->getData());
  142.             new TMessage('error'$e->getMessage());
  143.         }
  144.     }
  145.     
  146.     /**
  147.      * Load an item from session list to detail form
  148.      * @param $param URL parameters
  149.      */
  150.     public static function onEditDetail$param )
  151.     {
  152.         // read session items
  153.         $items TSession::getValue(__CLASS__.'_items');
  154.         
  155.         // get the session item
  156.         $item $items$param['key'] ];
  157.         
  158.         $data = new stdClass;
  159.         $data->detail_id $item['id'];
  160.         $data->detail_produtos_id $item['produtos_id'];
  161.         $data->detail_qtde $item['qtde'];
  162.         $data->detail_total_item $item['total_item'];
  163.         $data->detail_preco $item['preco'];
  164.         
  165.         // fill detail fields
  166.         TForm::sendData'form_Vendas'$data );
  167.     }
  168.     
  169.     /**
  170.      * Delete an item from session list
  171.      * @param $param URL parameters
  172.      */
  173.     public static function onDeleteDetail$param )
  174.     {
  175.         // reset items
  176.         $data = new stdClass;
  177.             $data->detail_produtos_id '';
  178.             $data->detail_qtde '';
  179.             $data->detail_total_item '';
  180.             $data->detail_preco '';
  181.         
  182.         // clear form data
  183.         TForm::sendData('form_Vendas'$data );
  184.         
  185.         // read session items
  186.         $items TSession::getValue(__CLASS__.'_items');
  187.         
  188.         // get detail id
  189.         $detail_id $param['key'];
  190.         
  191.         // delete the item from session
  192.         unset($items$detail_id ] );
  193.         
  194.         // rewrite session items
  195.         TSession::setValue(__CLASS__.'_items'$items);
  196.         
  197.         // delete item from screen
  198.         TScript::create("ttable_remove_row_by_id('Vendas_list', '{$detail_id}')");
  199.     }
  200.     
  201.     /**
  202.      * Load the items list from session
  203.      * @param $param URL parameters
  204.      */
  205.     public function onReload($param)
  206.     {
  207.         // read session items
  208.         $items TSession::getValue(__CLASS__.'_items');
  209.         
  210.         $this->detail_list->clear(); // clear detail list
  211.         
  212.         if ($items)
  213.         {
  214.             foreach ($items as $list_item)
  215.             {
  216.                 $item = (object) $list_item;
  217.                 
  218.                 $row $this->detail_list->addItem$item );
  219.                 $row->id $list_item['id'];
  220.             }
  221.         }
  222.         
  223.         $this->loaded TRUE;
  224.     }
  225.     
  226.     /**
  227.      * Load Master/Detail data from database to form/session
  228.      */
  229.     public function onEdit($param)
  230.     {
  231.         try
  232.         {
  233.             TTransaction::open('estoque');
  234.             
  235.             if (isset($param['key']))
  236.             {
  237.                 $key $param['key'];
  238.                 
  239.                 $object = new Vendas($key);
  240.                 $items  ItendVenda::where('vendas_id''='$key)->load();
  241.                 
  242.                 $session_items = array();
  243.                 foreach( $items as $item )
  244.                 {
  245.                     $item_key $item->id;
  246.                     $session_items[$item_key] = $item->toArray();
  247.                     $session_items[$item_key]['id'] = $item->id;
  248.                     $session_items[$item_key]['produtos_id'] = $item->produtos_id;
  249.                     $session_items[$item_key]['qtde'] = $item->qtde;
  250.                     $session_items[$item_key]['total_item'] = $item->total_item;
  251.                     $session_items[$item_key]['preco'] = $item->preco;
  252.                 }
  253.                 TSession::setValue(__CLASS__.'_items'$session_items);
  254.                 
  255.                 $this->form->setData($object); // fill the form with the active record data
  256.                 $this->onReload$param ); // reload items list
  257.                 TTransaction::close(); // close transaction
  258.             }
  259.             else
  260.             {
  261.                 $this->form->clear(TRUE);
  262.                 TSession::setValue(__CLASS__.'_items'null);
  263.                 $this->onReload$param );
  264.             }
  265.         }
  266.         catch (Exception $e// in case of exception
  267.         {
  268.             new TMessage('error'$e->getMessage());
  269.             TTransaction::rollback();
  270.         }
  271.     }
  272.     
  273.     /**
  274.      * Save the Master/Detail data from form/session to database
  275.      */
  276.     public function onSave()
  277.     {
  278.         try
  279.         {
  280.             // open a transaction with database
  281.             TTransaction::open('estoque');
  282.             
  283.             $data $this->form->getData();
  284.             $master = new Vendas;
  285.             $master->fromArray( (array) $data);
  286.             $this->form->validate(); // form validation
  287.             
  288.             $master->store(); // save master object
  289.             // delete details
  290.             $old_items ItendVenda::where('vendas_id''='$master->id)->load();
  291.             
  292.             $keep_items = array();
  293.             
  294.             // get session items
  295.             $items TSession::getValue(__CLASS__.'_items');
  296.             
  297.             if( $items )
  298.             {
  299.                 foreach( $items as $item )
  300.                 {
  301.                     if (substr($item['id'],0,1) == 'X' // new record
  302.                     {
  303.                         $detail = new ItendVenda;
  304.                     }
  305.                     else
  306.                     {
  307.                         $detail ItendVenda::find($item['id']);
  308.                     }
  309.                     $detail->produtos_id  $item['produtos_id'];
  310.                     $detail->qtde  $item['qtde'];
  311.                     $detail->total_item  $item['total_item'];
  312.                     $detail->preco  $item['preco'];
  313.                     $detail->vendas_id $master->id;
  314.                     $detail->store();
  315.                     
  316.                     $keep_items[] = $detail->id;
  317.                 }
  318.             }
  319.             
  320.             if ($old_items)
  321.             {
  322.                 foreach ($old_items as $old_item)
  323.                 {
  324.                     if (!in_array$old_item->id$keep_items))
  325.                     {
  326.                         $old_item->delete();
  327.                     }
  328.                 }
  329.             }
  330.             TTransaction::close(); // close the transaction
  331.             
  332.             // reload form and session items
  333.             $this->onEdit(array('key'=>$master->id));
  334.             
  335.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  336.         }
  337.         catch (Exception $e// in case of exception
  338.         {
  339.             new TMessage('error'$e->getMessage());
  340.             $this->form->setData$this->form->getData() ); // keep form data
  341.             TTransaction::rollback();
  342.         }
  343.     }
  344.     
  345.     /**
  346.      * Show the page
  347.      */
  348.     public function show()
  349.     {
  350.         // check if the datagrid is already loaded
  351.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  352.         {
  353.             $this->onReloadfunc_get_arg(0) );
  354.         }
  355.         parent::show();
  356.     }
  357. }
  358. </your>
NR

Veja a função da minha primeira resposta. É isso que você precisa. Instanciar o objeto através do parâmetro "key" e depois chamar a PDFDesigner
PS

Sim, mas eu preciso preencher os dados da nota com minhas informações de vendas. Como procedo então?
NR

Para os itens da venda você provavelmente terá que criar uma âncora, conforme exemplo abaixo:
www.adianti.com.br/framework_files/tutor/index.php?class=PDFDesignNF

  1. <?php
  2. $object = new SeuModel($param['key']);
  3. $itens $object->getItens();
  4. $designer->gotoAnchorXY('details'); // posicionar no x e y da ancora
  5. foreach ($itens as $item)
  6. {
  7.        $designer->gotoAnchorX('details'); // posicionar somente no x da ancora, pois o y sera modificado apos cada item
  8.        
  9.        $designer->Cell6210$item->codigo10'C');       
  10.        $designer->Cell6210$item->descricao10'C');
  11.        ...
  12.        $designer->Ln(10);
  13. }
  14. ?>
PS

Nataniel, agradeço muito pelo apoio, mas poderia colocar essa chamada dentro do meu código, estou meio enrolado. Agradeço.

  1. <?php
  2. /**
  3.  * VendasLista Listing
  4.  * @author  <your name here>
  5.  */
  6. class VendasLista extends TPage
  7. {
  8.     private $form// form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.     
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_Vendas');
  25.         $this->form->setFormTitle('Vendas');
  26.         
  27.         // create the form fields
  28.         $id = new TEntry('id');
  29.         $data_venda = new TEntry('data_venda');
  30.         // add the fields
  31.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  32.         $this->form->addFields( [ new TLabel('Data Venda') ], [ $data_venda ] );
  33.         // set sizes
  34.         $id->setSize('100%');
  35.         $data_venda->setSize('100%');
  36.         
  37.         // keep the form filled during navigation with session data
  38.         $this->form->setDataTSession::getValue('Vendas_filter_data') );
  39.         
  40.         // add the search form actions
  41.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  42.         $btn->class 'btn btn-sm btn-primary';
  43.         $this->form->addActionLink(_t('New'), new TAction(['VendasForm''onEdit']), 'fa:plus green');
  44.         
  45.         // creates a Datagrid
  46.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  47.         $this->datagrid->style 'width: 100%';
  48.         $this->datagrid->datatable 'true';
  49.         // $this->datagrid->enablePopover('Popover', 'Hi <b> Paulo Silva </b>');
  50.         
  51.         // creates the datagrid columns
  52.         $column_id = new TDataGridColumn('id''Id''right');
  53.         $column_data_venda = new TDataGridColumn('data_venda''Data Venda''left');
  54.         $column_qtde_itens = new TDataGridColumn('qtde_itens''Qtde Itens''left');
  55.         $column_total_vendas = new TDataGridColumn('total_vendas''Total Vendas''left');
  56.         // add the columns to the DataGrid
  57.         $this->datagrid->addColumn($column_id);
  58.         $this->datagrid->addColumn($column_data_venda);
  59.         $this->datagrid->addColumn($column_qtde_itens);
  60.         $this->datagrid->addColumn($column_total_vendas);
  61.         
  62.         // create EDIT action
  63.         $action_edit = new TDataGridAction(['VendasForm''onEdit']);
  64.         //$action_edit->setUseButton(TRUE);
  65.         //$action_edit->setButtonClass('btn btn-default');
  66.         $action_edit->setLabel(_t('Edit'));
  67.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  68.         $action_edit->setField('id');
  69.         $this->datagrid->addAction($action_edit);
  70.         
  71.         // create DELETE action
  72.         $action_del = new TDataGridAction(array($this'onDelete'));
  73.         //$action_del->setUseButton(TRUE);
  74.         //$action_del->setButtonClass('btn btn-default');
  75.         $action_del->setLabel(_t('Delete'));
  76.         $action_del->setImage('fa:trash-o red fa-lg');
  77.         $action_del->setField('id');
  78.         $this->datagrid->addAction($action_del);
  79.         
  80.         // create the datagrid model
  81.         $this->datagrid->createModel();
  82.         
  83.         // creates the page navigation
  84.         $this->pageNavigation = new TPageNavigation;
  85.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  86.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  87.         
  88.         // vertical box container
  89.         $container = new TVBox;
  90.         $container->style 'width: 90%';
  91.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  92.         $container->add($this->form);
  93.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  94.         
  95.         parent::add($container);
  96.     }
  97.     
  98.     /**
  99.      * Inline record editing
  100.      * @param $param Array containing:
  101.      *              key: object ID value
  102.      *              field name: object attribute to be updated
  103.      *              value: new attribute content 
  104.      */
  105.     public function onInlineEdit($param)
  106.     {
  107.         try
  108.         {
  109.             // get the parameter $key
  110.             $field $param['field'];
  111.             $key   $param['key'];
  112.             $value $param['value'];
  113.             
  114.             TTransaction::open('estoque'); // open a transaction with database
  115.             $object = new Vendas($key); // instantiates the Active Record
  116.             $object->{$field} = $value;
  117.             $object->store(); // update the object in the database
  118.             TTransaction::close(); // close the transaction
  119.             
  120.             $this->onReload($param); // reload the listing
  121.             new TMessage('info'"Record Updated");
  122.         }
  123.         catch (Exception $e// in case of exception
  124.         {
  125.             new TMessage('error'$e->getMessage()); // shows the exception error message
  126.             TTransaction::rollback(); // undo all pending operations
  127.         }
  128.     }
  129.     
  130.     /**
  131.      * Register the filter in the session
  132.      */
  133.     public function onSearch()
  134.     {
  135.         // get the search form data
  136.         $data $this->form->getData();
  137.         
  138.         // clear session filters
  139.         TSession::setValue('VendasLista_filter_id',   NULL);
  140.         TSession::setValue('VendasLista_filter_data_venda',   NULL);
  141.         if (isset($data->id) AND ($data->id)) {
  142.             $filter = new TFilter('id''='"$data->id"); // create the filter
  143.             TSession::setValue('VendasLista_filter_id',   $filter); // stores the filter in the session
  144.         }
  145.         if (isset($data->data_venda) AND ($data->data_venda)) {
  146.             $filter = new TFilter('data_venda''='"$data->data_venda"); // create the filter
  147.             TSession::setValue('VendasLista_filter_data_venda',   $filter); // stores the filter in the session
  148.         }
  149.         
  150.         // fill the form with data again
  151.         $this->form->setData($data);
  152.         
  153.         // keep the search data in the session
  154.         TSession::setValue('Vendas_filter_data'$data);
  155.         
  156.         $param = array();
  157.         $param['offset']    =0;
  158.         $param['first_page']=1;
  159.         $this->onReload($param);
  160.     }
  161.     
  162.     /**
  163.      * Load the datagrid with data
  164.      */
  165.     public function onReload($param NULL)
  166.     {
  167.         try
  168.         {
  169.             // open a transaction with database 'estoque'
  170.             TTransaction::open('estoque');
  171.             
  172.             // creates a repository for Vendas
  173.             $repository = new TRepository('Vendas');
  174.             $limit 10;
  175.             // creates a criteria
  176.             $criteria = new TCriteria;
  177.             
  178.             // default order
  179.             if (empty($param['order']))
  180.             {
  181.                 $param['order'] = 'id';
  182.                 $param['direction'] = 'asc';
  183.             }
  184.             $criteria->setProperties($param); // order, offset
  185.             $criteria->setProperty('limit'$limit);
  186.             
  187.             if (TSession::getValue('VendasLista_filter_id')) {
  188.                 $criteria->add(TSession::getValue('VendasLista_filter_id')); // add the session filter
  189.             }
  190.             if (TSession::getValue('VendasLista_filter_data_venda')) {
  191.                 $criteria->add(TSession::getValue('VendasLista_filter_data_venda')); // add the session filter
  192.             }
  193.             
  194.             // load the objects according to criteria
  195.             $objects $repository->load($criteriaFALSE);
  196.             
  197.             if (is_callable($this->transformCallback))
  198.             {
  199.                 call_user_func($this->transformCallback$objects$param);
  200.             }
  201.             
  202.             $this->datagrid->clear();
  203.             if ($objects)
  204.             {
  205.                 // iterate the collection of active records
  206.                 foreach ($objects as $object)
  207.                 {
  208.                     // add the object inside the datagrid
  209.                     $this->datagrid->addItem($object);
  210.                 }
  211.             }
  212.             
  213.             // reset the criteria for record count
  214.             $criteria->resetProperties();
  215.             $count$repository->count($criteria);
  216.             
  217.             $this->pageNavigation->setCount($count); // count of records
  218.             $this->pageNavigation->setProperties($param); // order, page
  219.             $this->pageNavigation->setLimit($limit); // limit
  220.             
  221.             // close the transaction
  222.             TTransaction::close();
  223.             $this->loaded true;
  224.         }
  225.         catch (Exception $e// in case of exception
  226.         {
  227.             // shows the exception error message
  228.             new TMessage('error'$e->getMessage());
  229.             // undo all pending operations
  230.             TTransaction::rollback();
  231.         }
  232.     }
  233.     
  234.     /**
  235.      * Ask before deletion
  236.      */
  237.     public static function onDelete($param)
  238.     {
  239.         // define the delete action
  240.         $action = new TAction([__CLASS__'Delete']);
  241.         $action->setParameters($param); // pass the key parameter ahead
  242.         
  243.         // shows a dialog to the user
  244.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  245.     }
  246.     
  247.     /**
  248.      * Delete a record
  249.      */
  250.     public static function Delete($param)
  251.     {
  252.         try
  253.         {
  254.             $key=$param['key']; // get the parameter $key
  255.             TTransaction::open('estoque'); // open a transaction with database
  256.             $object = new Vendas($keyFALSE); // instantiates the Active Record
  257.             $object->delete(); // deletes the object from the database
  258.             TTransaction::close(); // close the transaction
  259.             
  260.             $pos_action = new TAction([__CLASS__'onReload']);
  261.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  262.         }
  263.         catch (Exception $e// in case of exception
  264.         {
  265.             new TMessage('error'$e->getMessage()); // shows the exception error message
  266.             TTransaction::rollback(); // undo all pending operations
  267.         }
  268.     }
  269.     
  270.     
  271.     /**
  272.      * method show()
  273.      * Shows the page
  274.      */
  275.     public function show()
  276.     {
  277.         // check if the datagrid is already loaded
  278.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  279.         {
  280.             if (func_num_args() > 0)
  281.             {
  282.                 $this->onReloadfunc_get_arg(0) );
  283.             }
  284.             else
  285.             {
  286.                 $this->onReload();
  287.             }
  288.         }
  289.         parent::show();
  290.     }
  291. }</your>
NR

  1. <?php
  2. // construct
  3. // create PDF action
  4. $action_pdf = new TDataGridAction(array($this'onPrintNota'));
  5. ...
  6. $this->datagrid->addAction($action_edit);
  7. ...
  8. // fim construct
  9. public function onPrintNota($param)
  10. {
  11.          ...
  12.          $object = new SeuModel($param['key']);
  13.          ...
  14.          $designer = new TPDFDesigner;
  15.          $designer->fromXml('app/reports/nfe.pdf.xml');
  16.          $designer->generate();
  17.          ...
  18. }
  19. ?>
PS

Inseri os seguintes códigos, porém, sem sucesso. Pode verificar o que há de errado por gentileza.

// create EDIT action
//$action_edit = new TDataGridAction(['VendasForm', 'onEdit']);
$action_pdf = new TDataGridAction(array($this, 'onPrintNota'));
//$action_edit->setUseButton(TRUE);
//$action_edit->setButtonClass('btn btn-default');
$action_pdf->setLabel(_t('Edit'));
$action_pdf->setImage('fa:pencil-square-o blue fa-lg');
$action_pdf->setField('id');
$this->datagrid->addAction($action_pdf);


public function onPrintNota($param)
{
$object = new Vendas($param['id']);
$designer = new TPDFDesigner;
$designer->fromXml('app/reports/nfe.pdf.xml');
$designer->generate();
}
PS

  1. <?php
  2. // create EDIT action 
  3. //$action_edit = new TDataGridAction(['VendasForm', 'onEdit']); 
  4. $action_pdf = new TDataGridAction(array($this'onPrintNota')); 
  5. //$action_edit->setUseButton(TRUE); 
  6. //$action_edit->setButtonClass('btn btn-default'); 
  7. $action_pdf->setLabel(_t('Edit')); 
  8. $action_pdf->setImage('fa:pencil-square-o blue fa-lg'); 
  9. $action_pdf->setField('id'); 
  10. $this->datagrid->addAction($action_pdf); 
  11. public function onPrintNota($param
  12. $object = new Vendas($param['id']); 
  13. $designer = new TPDFDesigner
  14. $designer->fromXml('app/reports/nfe.pdf.xml'); 
  15. $designer->generate(); 
  16. ?>

PS

Poderia criar um exemplo pra mim baseado em uma tabela com o Adianti Studio ?

Eu agradeço amigo.
PS

Veja o código que digitei, consigo chamar o 'app/reports/nfe.pdf.xml', porém, como populo o ,xml com meus dados.

  1. <?php
  2.         // create EDIT action
  3.         //$action_edit = new TDataGridAction(['VendasForm', 'onEdit']);
  4.         $action_pdf = new TDataGridAction(array($this'onPrintNota'));
  5.         //$action_edit->setUseButton(TRUE);
  6.         //$action_edit->setButtonClass('btn btn-default');
  7.         $action_pdf->setLabel(_t('Edit'));
  8.         $action_pdf->setImage('fa:pencil-square-o blue fa-lg');
  9.         $action_pdf->setField('id');
  10.         $this->datagrid->addAction($action_pdf);
  11. ......
  12.     public function onPrintNota($param)
  13.     {
  14.             $object = new VendasLista($param['id']);             
  15.             $designer = new TPDFDesigner;
  16.             $designer->fromXml('app/reports/nfe.pdf.xml');
  17.             $designer->generate();
  18.             
  19.             $designer->SetFont('Arial''B'8);
  20.             $designer->setFontColorRGB'#4C4491' );
  21.             $designer->writeAtAnchor('for_ie',        '23234234234');
  22.             $designer->writeAtAnchor('for_cnpj',      '001.111.222.0001/00');
  23.             $designer->writeAtAnchor('nome',          utf8_decode('Cliente demonstração da silva'));
  24.             $designer->writeAtAnchor('endereco',      utf8_decode('Rua das demonstrações'));
  25.             $designer->writeAtAnchor('bairro',        'Centro');
  26.             $designer->writeAtAnchor('municipio',     'Cidade teste');
  27.             
  28.             
  29.             $file 'app/output/nfe.pdf';
  30.             
  31.             if (!file_exists($file) OR is_writable($file))
  32.             {
  33.                 $designer->save($file);
  34.                 //parent::openFile($file);
  35.                 
  36.                 $window TWindow::create(_t('Designed PDF NFE'), 0.80.8);
  37.                 $object = new TElement('object');
  38.                 $object->data  $file;
  39.                 $object->type  'application/pdf';
  40.                 $object->style "width: 100%; height:calc(100% - 10px)";
  41.                 $window->add($object);
  42.                 $window->show();
  43.             }
  44.             else
  45.             {
  46.                 throw new Exception(_t('Permission denied') . ': ' $file);
  47.             }
  48.              
  49.     }    
  50. ?>
PS

Pessoal boa tarde a todos...
Alguém poderia me ajudar neste tópico por gentileza...

Preciso com urgência.

Desde já agradeço.
PS

Nataniel, com esse código eu consegui carregar o PDF.

  1. <?php
  2. // construct
  3. // create PDF action
  4. $action_pdf = new TDataGridAction(array($this'onPrintNota'));
  5. ...
  6. $this->datagrid->addAction($action_edit);
  7. ...
  8. // fim construct
  9. public function onPrintNota($param)
  10. {
  11.          ...
  12.          $object = new SeuModel($param['key']);
  13.          ...
  14.          $designer = new TPDFDesigner;
  15.          $designer->fromXml('app/reports/nfe.pdf.xml');
  16.          $designer->generate();
  17.          ...
  18. }
  19. ?>


Mas como preencho as ancoras com os dados do Banco de Dados ?
NR

  1. <?php
  2. ...
  3. $object = new SeuModel($param['key']);
  4. ...
  5. $designer->writeAtAnchor('for_cnpj',    $object->nome_coluna);
  6. ?>
PS

Amigo, fiz dessa forma mas o recibo esta vindo em branco, veja o que pode estar errado no meu código por gentileza.

  1. <?php
  2.     public function onPrintRecibo()
  3.     {            
  4.             // open a transaction with database 
  5.             TTransaction::open('pedido'); 
  6.             
  7.             // load all customers 
  8.             $repository = new TRepository('Recibos'); 
  9.             $criteria = new TCriteria
  10.             $Recibos $repository->load($criteria); 
  11.             
  12.             $data $this->form->getData('Recibos'); 
  13.             $this->form->validate();     
  14.              
  15.             $object = new RecibosList($param['key']);
  16.             $designer = new TPDFDesigner;
  17.             $designer->fromXml('app/reports/recibo.pdf.xml');
  18.             $designer->generate();
  19.             
  20.             $designer->SetFont('Arial''B'8);
  21.             $designer->setFontColorRGB'#4C4491' );
  22.             $designer->writeAtAnchor('pagador',   $object->nome);
  23.             $designer->writeAtAnchor('valorreal'$object->valor);
  24.             $designer->writeAtAnchor('referente'$object->refere);                      
  25.             
  26.             $file 'app/output/recibo.pdf';
  27.             
  28.             if (!file_exists($file) OR is_writable($file))
  29.             {
  30.                 $designer->save($file);
  31.                 //parent::openFile($file);
  32.                 
  33.                 $window TWindow::create(_t('Designed PDF RECIBO'), 0.80.8);
  34.                 $object = new TElement('object');
  35.                 $object->data  $file;
  36.                 $object->type  'application/pdf';
  37.                 $object->style "width: 100%; height:calc(100% - 10px)";
  38.                 $window->add($object);
  39.                 $window->show();
  40.             }
  41.             else
  42.             {
  43.                 throw new Exception(_t('Permission denied') . ': ' $file);
  44.             }
  45.             TTransaction::close();
  46.              
  47.     } //fim do onPrintNota   
  48. ?>
PS

Veja o código da chamada...

  1. <?php
  2.         //CRIA AÇÃO DE IMPRESSÃO
  3.         $action_pdf = new TDataGridAction(array($this'onPrintRecibo'));
  4.         //$action_pdf->setUseButton(TRUE);
  5.         //$action_pdf->setButtonClass('btn btn-default');
  6.         $action_pdf->setLabel(_t('Edit'));
  7.         $action_pdf->setImage('fa:pencil-square-o blue fa-lg');
  8.         $action_pdf->setField('id');
  9.         $this->datagrid->addAction($action_pdf);
  10. ?>
NR

Você está instanciando a list invés do model:
  1. <?php
  2. //$object = new RecibosList($param['key']);
  3. $object = new Recibos($param['key']);
  4. ?>