Conheça as melhorias da versão 8.0, 8.1, 8.2!
Clique aqui para saber mais
ajuda com TFrame Boa noite estou fazendo um mestre/detalhe, e queria colocar mais um TFrame, so que esta fazendo assim conforme a imagem duplicando e código ...
RS
ajuda com TFrame  
Boa noite

estou fazendo um mestre/detalhe, e queria colocar mais um TFrame, so que esta fazendo assim conforme a imagem
duplicando


e código

 
  1. <?php
 
  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 $formFields;
  10. protected $detail_list;
  11. // use Adianti\Base\AdiantiStandardFormTrait; // Standard form methods
  12. /**
  13. * Page constructor
  14. */
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. // creates the form
  19. // $this->setDatabase('scomcomercio');
  20. $this->form = new TForm('form_Vendas');
  21. $this->form->class = 'tform'; // CSS class
  22. $this->form->style = 'max-width:90%'; // style
  23. parent::include_css('app/resources/custom-frame.css');
  24. $table_master = new TTable;
  25. $table_master->width = '100%';
  26. $table_master->addRowSet( new TLabel('Venda'), '', '')->class = 'tformtitle';
  27. // add a table inside form
  28. $table_general = new TTable;
  29. $table_detail = new TTable;
  30. $table_final = new TTable;
  31. $table_general-> width = '100%';
  32. $table_detail-> width = '100%';
  33. $table_final-> width = '100%';
  34. $frame_general = new TFrame;
  35. $frame_general->setLegend('Dados da Venda');
  36. $frame_general->style = 'background:whiteSmoke';
  37. $frame_general->add($table_general);
  38. $table_master->addRow()->addCell( $frame_general )->colspan=2;
  39. $row = $table_master->addRow();
  40. $row->addCell( $table_detail );
  41. $this->form->add($table_master);
  42. // master fields
  43. $Id = new TEntry('Id');
  44. $emissao = new TDate('emissao');
  45. $id_cliente = new ">TDBSeekButton('id_cliente','scomcomercio', $this->form->getName(), 'Clientes', 'cli_nome','id_cliente', 'cli_nome');
  46. $cli_nome = new TEntry('cli_nome');
  47. $id_vendedor = new ">TDBSeekButton('id_vendedor','scomcomercio', $this->form->getName(), 'Vendedores', 'ven_nome','id_vendedor', 'ven_nome');
  48. $ven_nome = new TEntry('ven_nome');
  49. $id_prazo = new TDBCombo('id_prazo','scomcomercio','Prazos','Id','prazo_nome');
  50. //$custo_tipo = new TDBCombo('custo_tipo','conpusis','CustosTipo','id','nome');
  51. //$db_combo = new TDBCombo('db_combo', 'samples', 'Category', 'id', '{name} ({id})');
  52. $p_desconto = new TEntry('p_desconto');
  53. $vlr_ajuste = new TEntry('vlr_ajuste');
  54. $valor_total = new TEntry('valor_total');
  55. $cli_nome->setEditable(FALSE);
  56. $cli_nome->setSize(400);
  57. $id_cliente->setSize(60);
  58. $ven_nome->setEditable(FALSE);
  59. $ven_nome->setSize(300);
  60. $id_vendedor->setSize(50);
  61. $id_prazo->setSize(400);
  62. //$id_prazo->enableSearch();
  63. $emissao->setSize(90);
  64. // $emissao->setValue(Date('Y-m-d'));
  65. if (!empty($Id))
  66. {
  67. $Id->setEditable(FALSE);
  68. }
  69. // detail fields
  70. $detail_Id = new THidden('detail_Id');
  71. $detail_iten_quantidade = new TEntry('detail_iten_quantidade');
  72. $detail_id_produto = new TEntry('detail_id_produto');
  73. $detail_preco_venda = new TEntry('detail_preco_venda');
  74. $detail_p_desconto = new TEntry('detail_p_desconto');
  75. $detail_iten_total = new TEntry('detail_iten_total');
  76. /** samples
  77. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  78. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  79. $fieldX->setSize( 100, 40 ); // set size
  80. **/
  81. // master
  82. //$this->form->setFieldsByRow(2);
  83. $table_general->addRowSet( new TLabel('Numero'), $Id );
  84. $table_general->addRowSet( new TLabel('Data'), $emissao );
  85. $table_general->addRowSet( new TLabel('Cliente') , array($id_cliente ,$label_nomecli = new TLabel('Nome'), $cli_nome));
  86. $table_general->addRowSet( new TLabel('Vendedor'), array($id_vendedor,$label_nomeven = new TLabel('Nome'), $ven_nome));
  87. $table_general->addRowSet( new TLabel('Prazo'), $id_prazo );
  88. $emissao->setMask('dd/mm/yyyy',TRUE);
  89. $emissao->setDatabaseMask('yyyy/mm/dd');
  90. // detail
  91. $frame_details = new TFrame();
  92. $frame_details->setLegend('Itens da Venda');
  93. $row = $table_detail->addRow();
  94. $row->addCell($frame_details);
  95. $btn_save_detail = new TButton('btn_save_detail');
  96. $btn_save_detail->setAction(new TAction(array($this, 'onSaveDetail')), 'Register');
  97. $btn_save_detail->setImage('fa:save');
  98. $table_details = new TTable;
  99. $frame_details->add($table_details);
  100. $table_details->addRowSet( '', $detail_Id );
  101. $table_details->addRowSet( new TLabel('Quantidade'), $detail_iten_quantidade );
  102. $table_details->addRowSet( new TLabel('Produto'), $detail_id_produto );
  103. $table_details->addRowSet( new TLabel('Preço de Venda'), $detail_preco_venda );
  104. $table_details->addRowSet( new TLabel('%Desconto'), $detail_p_desconto );
  105. $table_details->addRowSet( new TLabel('Total'), $detail_iten_total );
  106. $table_details->addRowSet( $btn_save_detail );
  107. $this->detail_list = new TQuickGrid;
  108. $this->detail_list->setHeight( 175 );
  109. $this->detail_list->makeScrollable();
  110. $this->detail_list->disableDefaultClick();
  111. $this->detail_list->addQuickColumn('', 'edit', 'left', 50);
  112. $this->detail_list->addQuickColumn('', 'delete', 'left', 50);
  113. // items
  114. $this->detail_list->addQuickColumn('Quantidade', 'iten_quantidade', 'left', 100);
  115. $this->detail_list->addQuickColumn('Produto', 'produtos->pro_descricao', 'left', 50);
  116. $this->detail_list->addQuickColumn('Preço de Venda', 'preco_venda', 'left', 100);
  117. $this->detail_list->addQuickColumn('%Desconto', 'p_desconto', 'left', 100);
  118. $this->detail_list->addQuickColumn('Total', 'iten_total', 'left', 100);
  119. $this->detail_list->createModel();
  120. $row = $table_detail->addRow();
  121. $row->addCell($this->detail_list);
  122. $frame_final = new TFrame;
  123. $frame_final->setLegend('Final');
  124. $frame_final->style = 'background:whiteSmoke';
  125. $frame_final->add($table_final);
  126. $table_master->addRow()->addCell( $frame_final )->colspan=1;
  127. $row = $table_master->addRow();
  128. $row->addCell( $table_final );
  129. $table_final->addRowSet( new TLabel('%Desconto'), $p_desconto );
  130. $table_final->addRowSet( new TLabel('Ajuste'), $vlr_ajuste );
  131. $table_final->addRowSet( new TLabel('TOTAL VENDA'), $valor_total );
  132. // create an action button (save)
  133. $save_button=new TButton('save');
  134. $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
  135. $save_button->setImage('ico_save.png');
  136. // create an new button (edit with no parameters)
  137. $new_button=new TButton('new');
  138. $new_button->setAction(new TAction(array($this, 'onClear')), _t('New'));
  139. $new_button->setImage('ico_new.png');
  140. // define form fields
  141. $this->formFields = array($Id,$emissao,$id_cliente,$id_vendedor,$id_prazo,$p_desconto,$vlr_ajuste,$valor_total,$detail_iten_quantidade,$detail_id_produto,$detail_preco_venda,$detail_p_desconto,$detail_iten_total);
  142. $this->formFields[] = $btn_save_detail;
  143. $this->formFields[] = $save_button;
  144. $this->formFields[] = $new_button;
  145. $this->formFields[] = $detail_Id;
  146. $this->form->setFields( $this->formFields );
  147. $table_master->addRowSet( array($save_button, $new_button), '', '')->class = 'tformaction'; // CSS class
  148. // create the page container
  149. $container = new TVBox;
  150. $container->style = 'width: 100%';
  151. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  152. $container->add($this->form);
  153. parent::add($container);
  154. }
  155. /**
  156. * Clear form
  157. * @param $param URL parameters
  158. */
  159. public function onClear($param)
  160. {
  161. $this->form->clear(TRUE);
  162. TSession::setValue(__CLASS__.'_items', array());
  163. $this->onReload( $param );
  164. }
  165. /**
  166. * Save an item from form to session list
  167. * @param $param URL parameters
  168. */
  169. public function onSaveDetail( $param )
  170. {
  171. try
  172. {
  173. TTransaction::open('scomcomercio');
  174. $data = $this->form->getData();
  175. /** validation sample
  176. if (! $data->fieldX)
  177. throw new Exception('The field fieldX is required');
  178. **/
  179. $items = TSession::getValue(__CLASS__.'_items');
  180. $key = empty($data->detail_Id) ? 'X'.mt_rand(1000000000, 1999999999) : $data->detail_Id;
  181. $items[ $key ] = array();
  182. $items[ $key ]['Id'] = $key;
  183. $items[ $key ]['iten_quantidade'] = $data->detail_iten_quantidade;
  184. $items[ $key ]['id_produto'] = $data->detail_id_produto;
  185. $items[ $key ]['preco_venda'] = $data->detail_preco_venda;
  186. $items[ $key ]['p_desconto'] = $data->detail_p_desconto;
  187. $items[ $key ]['iten_total'] = $data->detail_iten_total;
  188. TSession::setValue(__CLASS__.'_items', $items);
  189. // clear detail form fields
  190. $data->detail_Id = '';
  191. $data->detail_iten_quantidade = '';
  192. $data->detail_id_produto = '';
  193. $data->detail_preco_venda = '';
  194. $data->detail_p_desconto = '';
  195. $data->detail_iten_total = '';
  196. TTransaction::close();
  197. $this->form->setData($data);
  198. $this->onReload( $param ); // reload the items
  199. }
  200. catch (Exception $e)
  201. {
  202. $this->form->setData( $this->form->getData());
  203. new TMessage('error', $e->getMessage());
  204. }
  205. }
  206. /**
  207. * Load an item from session list to detail form
  208. * @param $param URL parameters
  209. */
  210. public function onEditDetail( $param )
  211. {
  212. $data = $this->form->getData();
  213. // read session items
  214. $items = TSession::getValue(__CLASS__.'_items');
  215. // get the session item
  216. $item = $items[ $param['item_key'] ];
  217. $data->detail_Id = $item['Id'];
  218. $data->detail_iten_quantidade = $item['iten_quantidade'];
  219. $data->detail_id_produto = $item['id_produto'];
  220. $data->detail_preco_venda = $item['preco_venda'];
  221. $data->detail_p_desconto = $item['p_desconto'];
  222. $data->detail_iten_total = $item['iten_total'];
  223. // fill detail fields
  224. $this->form->setData( $data );
  225. $this->onReload( $param );
  226. }
  227. /**
  228. * Delete an item from session list
  229. * @param $param URL parameters
  230. */
  231. public function onDeleteDetail( $param )
  232. {
  233. $data = $this->form->getData();
  234. // reset items
  235. $data->detail_iten_quantidade = '';
  236. $data->detail_id_produto = '';
  237. $data->detail_preco_venda = '';
  238. $data->detail_p_desconto = '';
  239. $data->detail_iten_total = '';
  240. // clear form data
  241. $this->form->setData( $data );
  242. // read session items
  243. $items = TSession::getValue(__CLASS__.'_items');
  244. // delete the item from session
  245. unset($items[ $param['item_key'] ] );
  246. TSession::setValue(__CLASS__.'_items', $items);
  247. // reload items
  248. $this->onReload( $param );
  249. }
  250. /**
  251. * Load the items list from session
  252. * @param $param URL parameters
  253. */
  254. public function onReload($param)
  255. {
  256. // read session items
  257. $items = TSession::getValue(__CLASS__.'_items');
  258. $this->detail_list->clear(); // clear detail list
  259. $data = $this->form->getData();
  260. if ($items)
  261. {
  262. $cont = 1;
  263. foreach ($items as $list_item_key => $list_item)
  264. {
  265. $item_name = 'prod_' . $cont++;
  266. $item = new StdClass;
  267. // create action buttons
  268. $action_del = new TAction(array($this, 'onDeleteDetail'));
  269. $action_del->setParameter('item_key', $list_item_key);
  270. $action_edi = new TAction(array($this, 'onEditDetail'));
  271. $action_edi->setParameter('item_key', $list_item_key);
  272. $button_del = new TButton('delete_detail'.$cont);
  273. $button_del->class = 'btn btn-default btn-sm';
  274. $button_del->setAction( $action_del, '' );
  275. $button_del->setImage('fa:trash-o red fa-lg');
  276. $button_edi = new TButton('edit_detail'.$cont);
  277. $button_edi->class = 'btn btn-default btn-sm';
  278. $button_edi->setAction( $action_edi, '' );
  279. $button_edi->setImage('fa:edit blue fa-lg');
  280. $item->edit = $button_edi;
  281. $item->delete = $button_del;
  282. $this->formFields[ $item_name.'_edit' ] = $item->edit;
  283. $this->formFields[ $item_name.'_delete' ] = $item->delete;
  284. // items
  285. $item->Id = $list_item['Id'];
  286. $item->iten_quantidade = $list_item['iten_quantidade'];
  287. $item->id_produto = $list_item['id_produto'];
  288. $item->preco_venda = $list_item['preco_venda'];
  289. $item->p_desconto = $list_item['p_desconto'];
  290. $item->iten_total = $list_item['iten_total'];
  291. $row = $this->detail_list->addItem( $item );
  292. $row->onmouseover='';
  293. $row->onmouseout='';
  294. }
  295. $this->form->setFields( $this->formFields );
  296. }
  297. $this->loaded = TRUE;
  298. }
  299. /**
  300. * Load Master/Detail data from database to form/session
  301. */
  302. public function onEdit($param)
  303. {
  304. try
  305. {
  306. TTransaction::open('scomcomercio');
  307. if (isset($param['key']))
  308. {
  309. $key = $param['key'];
  310. $object = new Vendas($key);
  311. $items = ItensVenda::where('id_venda', '=', $key)->load();
  312. $session_items = array();
  313. foreach( $items as $item )
  314. {
  315. $item_key = $item->Id;
  316. $session_items[$item_key] = $item->toArray();
  317. $session_items[$item_key]['Id'] = $item->Id;
  318. $session_items[$item_key]['iten_quantidade'] = $item->iten_quantidade;
  319. $session_items[$item_key]['id_produto'] = $item->id_produto;
  320. $session_items[$item_key]['preco_venda'] = $item->preco_venda;
  321. $session_items[$item_key]['p_desconto'] = $item->p_desconto;
  322. $session_items[$item_key]['iten_total'] = $item->iten_total;
  323. }
  324. TSession::setValue(__CLASS__.'_items', $session_items);
  325. $this->form->setData($object); // fill the form with the active record data
  326. $this->onReload( $param ); // reload items list
  327. TTransaction::close(); // close transaction
  328. }
  329. else
  330. {
  331. $this->form->clear(TRUE);
  332. TSession::setValue(__CLASS__.'_items', null);
  333. $this->onReload( $param );
  334. }
  335. }
  336. catch (Exception $e) // in case of exception
  337. {
  338. new TMessage('error', $e->getMessage());
  339. TTransaction::rollback();
  340. }
  341. }
  342. /**
  343. * Save the Master/Detail data from form/session to database
  344. */
  345. public function onSave()
  346. {
  347. try
  348. {
  349. // open a transaction with database
  350. TTransaction::open('scomcomercio');
  351. $data = $this->form->getData();
  352. $master = new Vendas;
  353. $master->fromArray( (array) $data);
  354. $this->form->validate(); // form validation
  355. $master->store(); // save master object
  356. // delete details
  357. $old_items = ItensVenda::where('id_venda', '=', $master->Id)->load();
  358. $keep_items = array();
  359. // get session items
  360. $items = TSession::getValue(__CLASS__.'_items');
  361. if( $items )
  362. {
  363. foreach( $items as $item )
  364. {
  365. if (substr($item['Id'],0,1) == 'X' ) // new record
  366. {
  367. $detail = new ItensVenda;
  368. }
  369. else
  370. {
  371. $detail = ItensVenda::find($item['Id']);
  372. }
  373. $detail->iten_quantidade = $item['iten_quantidade'];
  374. $detail->id_produto = $item['id_produto'];
  375. $detail->preco_venda = $item['preco_venda'];
  376. $detail->p_desconto = $item['p_desconto'];
  377. $detail->iten_total = $item['iten_total'];
  378. $detail->id_venda = $master->Id;
  379. $detail->store();
  380. $keep_items[] = $detail->Id;
  381. }
  382. }
  383. if ($old_items)
  384. {
  385. foreach ($old_items as $old_item)
  386. {
  387. if (!in_array( $old_item->Id, $keep_items))
  388. {
  389. $old_item->delete();
  390. }
  391. }
  392. }
  393. TTransaction::close(); // close the transaction
  394. // reload form and session items
  395. $this->onEdit(array('key'=>$master->Id));
  396. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  397. }
  398. catch (Exception $e) // in case of exception
  399. {
  400. new TMessage('error', $e->getMessage());
  401. $this->form->setData( $this->form->getData() ); // keep form data
  402. TTransaction::rollback();
  403. }
  404. }
  405. /**
  406. * Show the page
  407. */
  408. public function show()
  409. {
  410. // check if the datagrid is already loaded
  411. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  412. {
  413. $this->onReload( func_get_arg(0) );
  414. }
  415. parent::show();
  416. }
  417. }
  418. ?>

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


NR

Você está adicionando a table_final a 2 containers diferentes:
 
  1. <?php
  2. $frame_final->add($table_final); // primeira vez
  3. $table_master->addRow()->addCell( $frame_final )->colspan=1;
  4. $row = $table_master->addRow();
  5. //$row->addCell( $table_final ); // segunda vez, comente essa linha
  6. ?>
RS

Obrigado Nataniel, show de bola