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 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 (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. * Class constructor
  16. * Creates the page, the form and the listing
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. // creates the form
  22. $this->form = new BootstrapFormBuilder('form_Vendas');
  23. $this->form->setFormTitle('Vendas');
  24. // create the form fields
  25. $id = new TEntry('id');
  26. $data_venda = new TEntry('data_venda');
  27. // add the fields
  28. $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  29. $this->form->addFields( [ new TLabel('Data Venda') ], [ $data_venda ] );
  30. // set sizes
  31. $id->setSize('100%');
  32. $data_venda->setSize('100%');
  33. // keep the form filled during navigation with session data
  34. $this->form->setData( TSession::getValue('Vendas_filter_data') );
  35. // add the search form actions
  36. $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
  37. $btn->class = 'btn btn-sm btn-primary';
  38. $this->form->addActionLink(_t('New'), new TAction(['VendasForm', 'onEdit']), 'fa:plus green');
  39. // creates a Datagrid
  40. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  41. $this->datagrid->style = 'width: 100%';
  42. $this->datagrid->datatable = 'true';
  43. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  44. // creates the datagrid columns
  45. $column_id = new TDataGridColumn('id', 'Id', 'right');
  46. $column_data_venda = new TDataGridColumn('data_venda', 'Data Venda', 'left');
  47. $column_qtde_itens = new TDataGridColumn('qtde_itens', 'Qtde Itens', 'left');
  48. $column_total_vendas = new TDataGridColumn('total_vendas', 'Total Vendas', 'left');
  49. // add the columns to the DataGrid
  50. $this->datagrid->addColumn($column_id);
  51. $this->datagrid->addColumn($column_data_venda);
  52. $this->datagrid->addColumn($column_qtde_itens);
  53. $this->datagrid->addColumn($column_total_vendas);
  54. // create EDIT action
  55. $action_edit = new TDataGridAction(['VendasForm', 'onEdit']);
  56. //$action_edit->setUseButton(TRUE);
  57. //$action_edit->setButtonClass('btn btn-default');
  58. $action_edit->setLabel(_t('Edit'));
  59. $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  60. $action_edit->setField('id');
  61. $this->datagrid->addAction($action_edit);
  62. // create DELETE action
  63. $action_del = new TDataGridAction(array($this, 'onDelete'));
  64. //$action_del->setUseButton(TRUE);
  65. //$action_del->setButtonClass('btn btn-default');
  66. $action_del->setLabel(_t('Delete'));
  67. $action_del->setImage('fa:trash-o red fa-lg');
  68. $action_del->setField('id');
  69. $this->datagrid->addAction($action_del);
  70. // create the datagrid model
  71. $this->datagrid->createModel();
  72. // creates the page navigation
  73. $this->pageNavigation = new TPageNavigation;
  74. $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
  75. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  76. // vertical box container
  77. $container = new TVBox;
  78. $container->style = 'width: 90%';
  79. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  80. $container->add($this->form);
  81. $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
  82. parent::add($container);
  83. }
  84. /**
  85. * Inline record editing
  86. * @param $param Array containing:
  87. * key: object ID value
  88. * field name: object attribute to be updated
  89. * value: new attribute content
  90. */
  91. public function onInlineEdit($param)
  92. {
  93. try
  94. {
  95. // get the parameter $key
  96. $field = $param['field'];
  97. $key = $param['key'];
  98. $value = $param['value'];
  99. TTransaction::open('estoque'); // open a transaction with database
  100. $object = new Vendas($key); // instantiates the Active Record
  101. $object->{$field} = $value;
  102. $object->store(); // update the object in the database
  103. TTransaction::close(); // close the transaction
  104. $this->onReload($param); // reload the listing
  105. new TMessage('info', "Record Updated");
  106. }
  107. catch (Exception $e) // in case of exception
  108. {
  109. new TMessage('error', $e->getMessage()); // shows the exception error message
  110. TTransaction::rollback(); // undo all pending operations
  111. }
  112. }
  113. /**
  114. * Register the filter in the session
  115. */
  116. public function onSearch()
  117. {
  118. // get the search form data
  119. $data = $this->form->getData();
  120. // clear session filters
  121. TSession::setValue('VendasLista_filter_id', NULL);
  122. TSession::setValue('VendasLista_filter_data_venda', NULL);
  123. if (isset($data->id) AND ($data->id)) {
  124. $filter = new TFilter('id', '=', "$data->id"); // create the filter
  125. TSession::setValue('VendasLista_filter_id', $filter); // stores the filter in the session
  126. }
  127. if (isset($data->data_venda) AND ($data->data_venda)) {
  128. $filter = new TFilter('data_venda', '=', "$data->data_venda"); // create the filter
  129. TSession::setValue('VendasLista_filter_data_venda', $filter); // stores the filter in the session
  130. }
  131. // fill the form with data again
  132. $this->form->setData($data);
  133. // keep the search data in the session
  134. TSession::setValue('Vendas_filter_data', $data);
  135. $param = array();
  136. $param['offset'] =0;
  137. $param['first_page']=1;
  138. $this->onReload($param);
  139. }
  140. /**
  141. * Load the datagrid with data
  142. */
  143. public function onReload($param = NULL)
  144. {
  145. try
  146. {
  147. // open a transaction with database 'estoque'
  148. TTransaction::open('estoque');
  149. // creates a repository for Vendas
  150. $repository = new TRepository('Vendas');
  151. $limit = 10;
  152. // creates a criteria
  153. $criteria = new TCriteria;
  154. // default order
  155. if (empty($param['order']))
  156. {
  157. $param['order'] = 'id';
  158. $param['direction'] = 'asc';
  159. }
  160. $criteria->setProperties($param); // order, offset
  161. $criteria->setProperty('limit', $limit);
  162. if (TSession::getValue('VendasLista_filter_id')) {
  163. $criteria->add(TSession::getValue('VendasLista_filter_id')); // add the session filter
  164. }
  165. if (TSession::getValue('VendasLista_filter_data_venda')) {
  166. $criteria->add(TSession::getValue('VendasLista_filter_data_venda')); // add the session filter
  167. }
  168. // load the objects according to criteria
  169. $objects = $repository->load($criteria, FALSE);
  170. if (is_callable($this->transformCallback))
  171. {
  172. call_user_func($this->transformCallback, $objects, $param);
  173. }
  174. $this->datagrid->clear();
  175. if ($objects)
  176. {
  177. // iterate the collection of active records
  178. foreach ($objects as $object)
  179. {
  180. // add the object inside the datagrid
  181. $this->datagrid->addItem($object);
  182. }
  183. }
  184. // reset the criteria for record count
  185. $criteria->resetProperties();
  186. $count= $repository->count($criteria);
  187. $this->pageNavigation->setCount($count); // count of records
  188. $this->pageNavigation->setProperties($param); // order, page
  189. $this->pageNavigation->setLimit($limit); // limit
  190. // close the transaction
  191. TTransaction::close();
  192. $this->loaded = true;
  193. }
  194. catch (Exception $e) // in case of exception
  195. {
  196. // shows the exception error message
  197. new TMessage('error', $e->getMessage());
  198. // undo all pending operations
  199. TTransaction::rollback();
  200. }
  201. }
  202. /**
  203. * Ask before deletion
  204. */
  205. public static function onDelete($param)
  206. {
  207. // define the delete action
  208. $action = new TAction([__CLASS__, 'Delete']);
  209. $action->setParameters($param); // pass the key parameter ahead
  210. // shows a dialog to the user
  211. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  212. }
  213. /**
  214. * Delete a record
  215. */
  216. public static function Delete($param)
  217. {
  218. try
  219. {
  220. $key=$param['key']; // get the parameter $key
  221. TTransaction::open('estoque'); // open a transaction with database
  222. $object = new Vendas($key, FALSE); // instantiates the Active Record
  223. $object->delete(); // deletes the object from the database
  224. TTransaction::close(); // close the transaction
  225. $pos_action = new TAction([__CLASS__, 'onReload']);
  226. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  227. }
  228. catch (Exception $e) // in case of exception
  229. {
  230. new TMessage('error', $e->getMessage()); // shows the exception error message
  231. TTransaction::rollback(); // undo all pending operations
  232. }
  233. }
  234. /**
  235. * method show()
  236. * Shows the page
  237. */
  238. public function show()
  239. {
  240. // check if the datagrid is already loaded
  241. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  242. {
  243. if (func_num_args() > 0)
  244. {
  245. $this->onReload( func_get_arg(0) );
  246. }
  247. else
  248. {
  249. $this->onReload();
  250. }
  251. }
  252. parent::show();
  253. }
  254. }
  255. </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. * Page constructor
  12. */
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. // creates the form
  17. $this->form = new BootstrapFormBuilder('form_Vendas');
  18. $this->form->setFormTitle('Vendas');
  19. // master fields
  20. $id = new TEntry('id');
  21. $data_venda = new TDate('data_venda');
  22. $qtde_itens = new TEntry('qtde_itens');
  23. $total_vendas = new TEntry('total_vendas');
  24. // detail fields
  25. $detail_id = new THidden('detail_id');
  26. $detail_produtos_id = new TDBUniqueSearch('detail_produtos_id', 'estoque', 'Produtos', 'id', 'nome');
  27. $detail_qtde = new TEntry('detail_qtde');
  28. $detail_total_item = new TEntry('detail_total_item');
  29. $detail_preco = new TEntry('detail_preco');
  30. if (!empty($id))
  31. {
  32. $id->setEditable(FALSE);
  33. }
  34. // master fields
  35. $this->form->addFields( [new TLabel('Id')], [$id] );
  36. $this->form->addFields( [new TLabel('Data Venda')], [$data_venda] );
  37. $this->form->addFields( [new TLabel('Qtde Itens')], [$qtde_itens] );
  38. $this->form->addFields( [new TLabel('Total Vendas')], [$total_vendas] );
  39. // detail fields
  40. $this->form->addContent( ['<h4>Details</h4><hr>'] );
  41. $this->form->addFields( [$detail_id] );
  42. $this->form->addFields( [new TLabel('Produtos Id')], [$detail_produtos_id] );
  43. $this->form->addFields( [new TLabel('Qtde')], [$detail_qtde] );
  44. $this->form->addFields( [new TLabel('Total Item')], [$detail_total_item] );
  45. $this->form->addFields( [new TLabel('Preco')], [$detail_preco] );
  46. $add = TButton::create('add', [$this, 'onSaveDetail'], 'Register', 'fa:save');
  47. $this->form->addFields( [], [$add] )->style = 'background: whitesmoke; padding: 5px; margin: 1px;';
  48. $this->detail_list = new BootstrapDatagridWrapper(new TQuickGrid);
  49. $this->detail_list->style = "min-width: 700px; width:100%;margin-bottom: 10px";
  50. $this->detail_list->setId('Vendas_list');
  51. // items
  52. $this->detail_list->addQuickColumn('Produtos Id', 'produtos_id', 'left', 100);
  53. $this->detail_list->addQuickColumn('Qtde', 'qtde', 'left', 100);
  54. $this->detail_list->addQuickColumn('Total Item', 'total_item', 'left', 100);
  55. $this->detail_list->addQuickColumn('Preco', 'preco', 'left', 100);
  56. // detail actions
  57. $this->detail_list->addQuickAction( 'Edit', new TDataGridAction([$this, 'onEditDetail']), 'id', 'fa:edit blue');
  58. $this->detail_list->addQuickAction( 'Delete', new TDataGridAction([$this, 'onDeleteDetail']), 'id', 'fa:trash red');
  59. $this->detail_list->createModel();
  60. $panel = new TPanelGroup;
  61. $panel->add($this->detail_list);
  62. $panel->getBody()->style = 'overflow-x:auto';
  63. $this->form->addContent( [$panel] );
  64. $btn = $this->form->addAction( _t('Save'), new TAction([$this, 'onSave']), 'fa:save');
  65. $btn->class = 'btn btn-sm btn-primary';
  66. $this->form->addAction( _t('Clear'), new TAction([$this, 'onClear']), 'fa:eraser red');
  67. // create the page container
  68. $container = new TVBox;
  69. $container->style = 'width: 90%';
  70. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  71. $container->add($this->form);
  72. parent::add($container);
  73. }
  74. /**
  75. * Clear form
  76. * @param $param URL parameters
  77. */
  78. public function onClear($param)
  79. {
  80. $this->form->clear(TRUE);
  81. TSession::setValue(__CLASS__.'_items', array());
  82. $this->onReload( $param );
  83. }
  84. /**
  85. * Save an item from form to session list
  86. * @param $param URL parameters
  87. */
  88. public function onSaveDetail( $param )
  89. {
  90. try
  91. {
  92. TTransaction::open('estoque');
  93. $data = $this->form->getData();
  94. /** validation sample
  95. if (empty($data->fieldX))
  96. {
  97. throw new Exception('The field fieldX is required');
  98. }
  99. **/
  100. $items = TSession::getValue(__CLASS__.'_items');
  101. $key = empty($data->detail_id) ? 'X'.mt_rand(1000000000, 1999999999) : $data->detail_id;
  102. $items[ $key ] = array();
  103. $items[ $key ]['id'] = $key;
  104. $items[ $key ]['produtos_id'] = $data->detail_produtos_id;
  105. $items[ $key ]['qtde'] = $data->detail_qtde;
  106. $items[ $key ]['total_item'] = $data->detail_total_item;
  107. $items[ $key ]['preco'] = $data->detail_preco;
  108. TSession::setValue(__CLASS__.'_items', $items);
  109. // clear detail form fields
  110. $data->detail_id = '';
  111. $data->detail_produtos_id = '';
  112. $data->detail_qtde = '';
  113. $data->detail_total_item = '';
  114. $data->detail_preco = '';
  115. TTransaction::close();
  116. $this->form->setData($data);
  117. $this->onReload( $param ); // reload the items
  118. }
  119. catch (Exception $e)
  120. {
  121. $this->form->setData( $this->form->getData());
  122. new TMessage('error', $e->getMessage());
  123. }
  124. }
  125. /**
  126. * Load an item from session list to detail form
  127. * @param $param URL parameters
  128. */
  129. public static function onEditDetail( $param )
  130. {
  131. // read session items
  132. $items = TSession::getValue(__CLASS__.'_items');
  133. // get the session item
  134. $item = $items[ $param['key'] ];
  135. $data = new stdClass;
  136. $data->detail_id = $item['id'];
  137. $data->detail_produtos_id = $item['produtos_id'];
  138. $data->detail_qtde = $item['qtde'];
  139. $data->detail_total_item = $item['total_item'];
  140. $data->detail_preco = $item['preco'];
  141. // fill detail fields
  142. TForm::sendData( 'form_Vendas', $data );
  143. }
  144. /**
  145. * Delete an item from session list
  146. * @param $param URL parameters
  147. */
  148. public static function onDeleteDetail( $param )
  149. {
  150. // reset items
  151. $data = new stdClass;
  152. $data->detail_produtos_id = '';
  153. $data->detail_qtde = '';
  154. $data->detail_total_item = '';
  155. $data->detail_preco = '';
  156. // clear form data
  157. TForm::sendData('form_Vendas', $data );
  158. // read session items
  159. $items = TSession::getValue(__CLASS__.'_items');
  160. // get detail id
  161. $detail_id = $param['key'];
  162. // delete the item from session
  163. unset($items[ $detail_id ] );
  164. // rewrite session items
  165. TSession::setValue(__CLASS__.'_items', $items);
  166. // delete item from screen
  167. TScript::create("ttable_remove_row_by_id('Vendas_list', '{$detail_id}')");
  168. }
  169. /**
  170. * Load the items list from session
  171. * @param $param URL parameters
  172. */
  173. public function onReload($param)
  174. {
  175. // read session items
  176. $items = TSession::getValue(__CLASS__.'_items');
  177. $this->detail_list->clear(); // clear detail list
  178. if ($items)
  179. {
  180. foreach ($items as $list_item)
  181. {
  182. $item = (object) $list_item;
  183. $row = $this->detail_list->addItem( $item );
  184. $row->id = $list_item['id'];
  185. }
  186. }
  187. $this->loaded = TRUE;
  188. }
  189. /**
  190. * Load Master/Detail data from database to form/session
  191. */
  192. public function onEdit($param)
  193. {
  194. try
  195. {
  196. TTransaction::open('estoque');
  197. if (isset($param['key']))
  198. {
  199. $key = $param['key'];
  200. $object = new Vendas($key);
  201. $items = ItendVenda::where('vendas_id', '=', $key)->load();
  202. $session_items = array();
  203. foreach( $items as $item )
  204. {
  205. $item_key = $item->id;
  206. $session_items[$item_key] = $item->toArray();
  207. $session_items[$item_key]['id'] = $item->id;
  208. $session_items[$item_key]['produtos_id'] = $item->produtos_id;
  209. $session_items[$item_key]['qtde'] = $item->qtde;
  210. $session_items[$item_key]['total_item'] = $item->total_item;
  211. $session_items[$item_key]['preco'] = $item->preco;
  212. }
  213. TSession::setValue(__CLASS__.'_items', $session_items);
  214. $this->form->setData($object); // fill the form with the active record data
  215. $this->onReload( $param ); // reload items list
  216. TTransaction::close(); // close transaction
  217. }
  218. else
  219. {
  220. $this->form->clear(TRUE);
  221. TSession::setValue(__CLASS__.'_items', null);
  222. $this->onReload( $param );
  223. }
  224. }
  225. catch (Exception $e) // in case of exception
  226. {
  227. new TMessage('error', $e->getMessage());
  228. TTransaction::rollback();
  229. }
  230. }
  231. /**
  232. * Save the Master/Detail data from form/session to database
  233. */
  234. public function onSave()
  235. {
  236. try
  237. {
  238. // open a transaction with database
  239. TTransaction::open('estoque');
  240. $data = $this->form->getData();
  241. $master = new Vendas;
  242. $master->fromArray( (array) $data);
  243. $this->form->validate(); // form validation
  244. $master->store(); // save master object
  245. // delete details
  246. $old_items = ItendVenda::where('vendas_id', '=', $master->id)->load();
  247. $keep_items = array();
  248. // get session items
  249. $items = TSession::getValue(__CLASS__.'_items');
  250. if( $items )
  251. {
  252. foreach( $items as $item )
  253. {
  254. if (substr($item['id'],0,1) == 'X' ) // new record
  255. {
  256. $detail = new ItendVenda;
  257. }
  258. else
  259. {
  260. $detail = ItendVenda::find($item['id']);
  261. }
  262. $detail->produtos_id = $item['produtos_id'];
  263. $detail->qtde = $item['qtde'];
  264. $detail->total_item = $item['total_item'];
  265. $detail->preco = $item['preco'];
  266. $detail->vendas_id = $master->id;
  267. $detail->store();
  268. $keep_items[] = $detail->id;
  269. }
  270. }
  271. if ($old_items)
  272. {
  273. foreach ($old_items as $old_item)
  274. {
  275. if (!in_array( $old_item->id, $keep_items))
  276. {
  277. $old_item->delete();
  278. }
  279. }
  280. }
  281. TTransaction::close(); // close the transaction
  282. // reload form and session items
  283. $this->onEdit(array('key'=>$master->id));
  284. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  285. }
  286. catch (Exception $e) // in case of exception
  287. {
  288. new TMessage('error', $e->getMessage());
  289. $this->form->setData( $this->form->getData() ); // keep form data
  290. TTransaction::rollback();
  291. }
  292. }
  293. /**
  294. * Show the page
  295. */
  296. public function show()
  297. {
  298. // check if the datagrid is already loaded
  299. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  300. {
  301. $this->onReload( func_get_arg(0) );
  302. }
  303. parent::show();
  304. }
  305. }
  306. </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. $designer->Cell( 62, 10, $item->codigo, 1, 0, 'C');
  9. $designer->Cell( 62, 10, $item->descricao, 1, 0, 'C');
  10. ...
  11. $designer->Ln(10);
  12. }
  13. ?>
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. * Class constructor
  16. * Creates the page, the form and the listing
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. // creates the form
  22. $this->form = new BootstrapFormBuilder('form_Vendas');
  23. $this->form->setFormTitle('Vendas');
  24. // create the form fields
  25. $id = new TEntry('id');
  26. $data_venda = new TEntry('data_venda');
  27. // add the fields
  28. $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  29. $this->form->addFields( [ new TLabel('Data Venda') ], [ $data_venda ] );
  30. // set sizes
  31. $id->setSize('100%');
  32. $data_venda->setSize('100%');
  33. // keep the form filled during navigation with session data
  34. $this->form->setData( TSession::getValue('Vendas_filter_data') );
  35. // add the search form actions
  36. $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
  37. $btn->class = 'btn btn-sm btn-primary';
  38. $this->form->addActionLink(_t('New'), new TAction(['VendasForm', 'onEdit']), 'fa:plus green');
  39. // creates a Datagrid
  40. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  41. $this->datagrid->style = 'width: 100%';
  42. $this->datagrid->datatable = 'true';
  43. // $this->datagrid->enablePopover('Popover', 'Hi <b> Paulo Silva </b>');
  44. // creates the datagrid columns
  45. $column_id = new TDataGridColumn('id', 'Id', 'right');
  46. $column_data_venda = new TDataGridColumn('data_venda', 'Data Venda', 'left');
  47. $column_qtde_itens = new TDataGridColumn('qtde_itens', 'Qtde Itens', 'left');
  48. $column_total_vendas = new TDataGridColumn('total_vendas', 'Total Vendas', 'left');
  49. // add the columns to the DataGrid
  50. $this->datagrid->addColumn($column_id);
  51. $this->datagrid->addColumn($column_data_venda);
  52. $this->datagrid->addColumn($column_qtde_itens);
  53. $this->datagrid->addColumn($column_total_vendas);
  54. // create EDIT action
  55. $action_edit = new TDataGridAction(['VendasForm', 'onEdit']);
  56. //$action_edit->setUseButton(TRUE);
  57. //$action_edit->setButtonClass('btn btn-default');
  58. $action_edit->setLabel(_t('Edit'));
  59. $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  60. $action_edit->setField('id');
  61. $this->datagrid->addAction($action_edit);
  62. // create DELETE action
  63. $action_del = new TDataGridAction(array($this, 'onDelete'));
  64. //$action_del->setUseButton(TRUE);
  65. //$action_del->setButtonClass('btn btn-default');
  66. $action_del->setLabel(_t('Delete'));
  67. $action_del->setImage('fa:trash-o red fa-lg');
  68. $action_del->setField('id');
  69. $this->datagrid->addAction($action_del);
  70. // create the datagrid model
  71. $this->datagrid->createModel();
  72. // creates the page navigation
  73. $this->pageNavigation = new TPageNavigation;
  74. $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
  75. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  76. // vertical box container
  77. $container = new TVBox;
  78. $container->style = 'width: 90%';
  79. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  80. $container->add($this->form);
  81. $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
  82. parent::add($container);
  83. }
  84. /**
  85. * Inline record editing
  86. * @param $param Array containing:
  87. * key: object ID value
  88. * field name: object attribute to be updated
  89. * value: new attribute content
  90. */
  91. public function onInlineEdit($param)
  92. {
  93. try
  94. {
  95. // get the parameter $key
  96. $field = $param['field'];
  97. $key = $param['key'];
  98. $value = $param['value'];
  99. TTransaction::open('estoque'); // open a transaction with database
  100. $object = new Vendas($key); // instantiates the Active Record
  101. $object->{$field} = $value;
  102. $object->store(); // update the object in the database
  103. TTransaction::close(); // close the transaction
  104. $this->onReload($param); // reload the listing
  105. new TMessage('info', "Record Updated");
  106. }
  107. catch (Exception $e) // in case of exception
  108. {
  109. new TMessage('error', $e->getMessage()); // shows the exception error message
  110. TTransaction::rollback(); // undo all pending operations
  111. }
  112. }
  113. /**
  114. * Register the filter in the session
  115. */
  116. public function onSearch()
  117. {
  118. // get the search form data
  119. $data = $this->form->getData();
  120. // clear session filters
  121. TSession::setValue('VendasLista_filter_id', NULL);
  122. TSession::setValue('VendasLista_filter_data_venda', NULL);
  123. if (isset($data->id) AND ($data->id)) {
  124. $filter = new TFilter('id', '=', "$data->id"); // create the filter
  125. TSession::setValue('VendasLista_filter_id', $filter); // stores the filter in the session
  126. }
  127. if (isset($data->data_venda) AND ($data->data_venda)) {
  128. $filter = new TFilter('data_venda', '=', "$data->data_venda"); // create the filter
  129. TSession::setValue('VendasLista_filter_data_venda', $filter); // stores the filter in the session
  130. }
  131. // fill the form with data again
  132. $this->form->setData($data);
  133. // keep the search data in the session
  134. TSession::setValue('Vendas_filter_data', $data);
  135. $param = array();
  136. $param['offset'] =0;
  137. $param['first_page']=1;
  138. $this->onReload($param);
  139. }
  140. /**
  141. * Load the datagrid with data
  142. */
  143. public function onReload($param = NULL)
  144. {
  145. try
  146. {
  147. // open a transaction with database 'estoque'
  148. TTransaction::open('estoque');
  149. // creates a repository for Vendas
  150. $repository = new TRepository('Vendas');
  151. $limit = 10;
  152. // creates a criteria
  153. $criteria = new TCriteria;
  154. // default order
  155. if (empty($param['order']))
  156. {
  157. $param['order'] = 'id';
  158. $param['direction'] = 'asc';
  159. }
  160. $criteria->setProperties($param); // order, offset
  161. $criteria->setProperty('limit', $limit);
  162. if (TSession::getValue('VendasLista_filter_id')) {
  163. $criteria->add(TSession::getValue('VendasLista_filter_id')); // add the session filter
  164. }
  165. if (TSession::getValue('VendasLista_filter_data_venda')) {
  166. $criteria->add(TSession::getValue('VendasLista_filter_data_venda')); // add the session filter
  167. }
  168. // load the objects according to criteria
  169. $objects = $repository->load($criteria, FALSE);
  170. if (is_callable($this->transformCallback))
  171. {
  172. call_user_func($this->transformCallback, $objects, $param);
  173. }
  174. $this->datagrid->clear();
  175. if ($objects)
  176. {
  177. // iterate the collection of active records
  178. foreach ($objects as $object)
  179. {
  180. // add the object inside the datagrid
  181. $this->datagrid->addItem($object);
  182. }
  183. }
  184. // reset the criteria for record count
  185. $criteria->resetProperties();
  186. $count= $repository->count($criteria);
  187. $this->pageNavigation->setCount($count); // count of records
  188. $this->pageNavigation->setProperties($param); // order, page
  189. $this->pageNavigation->setLimit($limit); // limit
  190. // close the transaction
  191. TTransaction::close();
  192. $this->loaded = true;
  193. }
  194. catch (Exception $e) // in case of exception
  195. {
  196. // shows the exception error message
  197. new TMessage('error', $e->getMessage());
  198. // undo all pending operations
  199. TTransaction::rollback();
  200. }
  201. }
  202. /**
  203. * Ask before deletion
  204. */
  205. public static function onDelete($param)
  206. {
  207. // define the delete action
  208. $action = new TAction([__CLASS__, 'Delete']);
  209. $action->setParameters($param); // pass the key parameter ahead
  210. // shows a dialog to the user
  211. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  212. }
  213. /**
  214. * Delete a record
  215. */
  216. public static function Delete($param)
  217. {
  218. try
  219. {
  220. $key=$param['key']; // get the parameter $key
  221. TTransaction::open('estoque'); // open a transaction with database
  222. $object = new Vendas($key, FALSE); // instantiates the Active Record
  223. $object->delete(); // deletes the object from the database
  224. TTransaction::close(); // close the transaction
  225. $pos_action = new TAction([__CLASS__, 'onReload']);
  226. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  227. }
  228. catch (Exception $e) // in case of exception
  229. {
  230. new TMessage('error', $e->getMessage()); // shows the exception error message
  231. TTransaction::rollback(); // undo all pending operations
  232. }
  233. }
  234. /**
  235. * method show()
  236. * Shows the page
  237. */
  238. public function show()
  239. {
  240. // check if the datagrid is already loaded
  241. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  242. {
  243. if (func_num_args() > 0)
  244. {
  245. $this->onReload( func_get_arg(0) );
  246. }
  247. else
  248. {
  249. $this->onReload();
  250. }
  251. }
  252. parent::show();
  253. }
  254. }</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. {
  13. $object = new Vendas($param['id']);
  14. $designer = new TPDFDesigner;
  15. $designer->fromXml('app/reports/nfe.pdf.xml');
  16. $designer->generate();
  17. }
  18. ?>

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. $designer->SetFont('Arial', 'B', 8);
  19. $designer->setFontColorRGB( '#4C4491' );
  20. $designer->writeAtAnchor('for_ie', '23234234234');
  21. $designer->writeAtAnchor('for_cnpj', '001.111.222.0001/00');
  22. $designer->writeAtAnchor('nome', utf8_decode('Cliente demonstração da silva'));
  23. $designer->writeAtAnchor('endereco', utf8_decode('Rua das demonstrações'));
  24. $designer->writeAtAnchor('bairro', 'Centro');
  25. $designer->writeAtAnchor('municipio', 'Cidade teste');
  26. $file = 'app/output/nfe.pdf';
  27. if (!file_exists($file) OR is_writable($file))
  28. {
  29. $designer->save($file);
  30. //parent::openFile($file);
  31. $window = TWindow::create(_t('Designed PDF NFE'), 0.8, 0.8);
  32. $object = new TElement('object');
  33. $object->data = $file;
  34. $object->type = 'application/pdf';
  35. $object->style = "width: 100%; height:calc(100% - 10px)";
  36. $window->add($object);
  37. $window->show();
  38. }
  39. else
  40. {
  41. throw new Exception(_t('Permission denied') . ': ' . $file);
  42. }
  43. }
  44. ?>
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. // load all customers
  7. $repository = new TRepository('Recibos');
  8. $criteria = new TCriteria;
  9. $Recibos = $repository->load($criteria);
  10. $data = $this->form->getData('Recibos');
  11. $this->form->validate();
  12. $object = new RecibosList($param['key']);
  13. $designer = new TPDFDesigner;
  14. $designer->fromXml('app/reports/recibo.pdf.xml');
  15. $designer->generate();
  16. $designer->SetFont('Arial', 'B', 8);
  17. $designer->setFontColorRGB( '#4C4491' );
  18. $designer->writeAtAnchor('pagador', $object->nome);
  19. $designer->writeAtAnchor('valorreal', $object->valor);
  20. $designer->writeAtAnchor('referente', $object->refere);
  21. $file = 'app/output/recibo.pdf';
  22. if (!file_exists($file) OR is_writable($file))
  23. {
  24. $designer->save($file);
  25. //parent::openFile($file);
  26. $window = TWindow::create(_t('Designed PDF RECIBO'), 0.8, 0.8);
  27. $object = new TElement('object');
  28. $object->data = $file;
  29. $object->type = 'application/pdf';
  30. $object->style = "width: 100%; height:calc(100% - 10px)";
  31. $window->add($object);
  32. $window->show();
  33. }
  34. else
  35. {
  36. throw new Exception(_t('Permission denied') . ': ' . $file);
  37. }
  38. TTransaction::close();
  39. } //fim do onPrintNota
  40. ?>
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. ?>