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
estou fazendo um mestre/detalhe, e queria colocar mais um TFrame, so que esta fazendo assim conforme a imagem
duplicando
e código
- <?php
- <?php
- /**
- * VendasForm Master/Detail
- * @author <your name here>
- */
- class VendasForm extends TPage
- {
- protected $form; // form
- protected $formFields;
- protected $detail_list;
- // use Adianti\Base\AdiantiStandardFormTrait; // Standard form methods
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- // $this->setDatabase('scomcomercio');
- $this->form = new TForm('form_Vendas');
- $this->form->class = 'tform'; // CSS class
- $this->form->style = 'max-width:90%'; // style
- parent::include_css('app/resources/custom-frame.css');
- $table_master = new TTable;
- $table_master->width = '100%';
- $table_master->addRowSet( new TLabel('Venda'), '', '')->class = 'tformtitle';
- // add a table inside form
- $table_general = new TTable;
- $table_detail = new TTable;
- $table_final = new TTable;
- $table_general-> width = '100%';
- $table_detail-> width = '100%';
- $table_final-> width = '100%';
- $frame_general = new TFrame;
- $frame_general->setLegend('Dados da Venda');
- $frame_general->style = 'background:whiteSmoke';
- $frame_general->add($table_general);
- $table_master->addRow()->addCell( $frame_general )->colspan=2;
- $row = $table_master->addRow();
- $row->addCell( $table_detail );
- $this->form->add($table_master);
- // master fields
- $Id = new TEntry('Id');
- $emissao = new TDate('emissao');
- $id_cliente = new ">TDBSeekButton('id_cliente','scomcomercio', $this->form->getName(), 'Clientes', 'cli_nome','id_cliente', 'cli_nome');
- $cli_nome = new TEntry('cli_nome');
- $id_vendedor = new ">TDBSeekButton('id_vendedor','scomcomercio', $this->form->getName(), 'Vendedores', 'ven_nome','id_vendedor', 'ven_nome');
- $ven_nome = new TEntry('ven_nome');
- $id_prazo = new TDBCombo('id_prazo','scomcomercio','Prazos','Id','prazo_nome');
- //$custo_tipo = new TDBCombo('custo_tipo','conpusis','CustosTipo','id','nome');
- //$db_combo = new TDBCombo('db_combo', 'samples', 'Category', 'id', '{name} ({id})');
- $p_desconto = new TEntry('p_desconto');
- $vlr_ajuste = new TEntry('vlr_ajuste');
- $valor_total = new TEntry('valor_total');
- $cli_nome->setEditable(FALSE);
- $cli_nome->setSize(400);
- $id_cliente->setSize(60);
- $ven_nome->setEditable(FALSE);
- $ven_nome->setSize(300);
- $id_vendedor->setSize(50);
- $id_prazo->setSize(400);
- //$id_prazo->enableSearch();
- $emissao->setSize(90);
- // $emissao->setValue(Date('Y-m-d'));
- if (!empty($Id))
- {
- $Id->setEditable(FALSE);
- }
- // detail fields
- $detail_Id = new THidden('detail_Id');
- $detail_iten_quantidade = new TEntry('detail_iten_quantidade');
- $detail_id_produto = new TEntry('detail_id_produto');
- $detail_preco_venda = new TEntry('detail_preco_venda');
- $detail_p_desconto = new TEntry('detail_p_desconto');
- $detail_iten_total = new TEntry('detail_iten_total');
- /** samples
- $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( 100, 40 ); // set size
- **/
- // master
- //$this->form->setFieldsByRow(2);
- $table_general->addRowSet( new TLabel('Numero'), $Id );
- $table_general->addRowSet( new TLabel('Data'), $emissao );
- $table_general->addRowSet( new TLabel('Cliente') , array($id_cliente ,$label_nomecli = new TLabel('Nome'), $cli_nome));
- $table_general->addRowSet( new TLabel('Vendedor'), array($id_vendedor,$label_nomeven = new TLabel('Nome'), $ven_nome));
- $table_general->addRowSet( new TLabel('Prazo'), $id_prazo );
- $emissao->setMask('dd/mm/yyyy',TRUE);
- $emissao->setDatabaseMask('yyyy/mm/dd');
- // detail
- $frame_details = new TFrame();
- $frame_details->setLegend('Itens da Venda');
- $row = $table_detail->addRow();
- $row->addCell($frame_details);
- $btn_save_detail = new TButton('btn_save_detail');
- $btn_save_detail->setAction(new TAction(array($this, 'onSaveDetail')), 'Register');
- $btn_save_detail->setImage('fa:save');
- $table_details = new TTable;
- $frame_details->add($table_details);
- $table_details->addRowSet( '', $detail_Id );
- $table_details->addRowSet( new TLabel('Quantidade'), $detail_iten_quantidade );
- $table_details->addRowSet( new TLabel('Produto'), $detail_id_produto );
- $table_details->addRowSet( new TLabel('Preço de Venda'), $detail_preco_venda );
- $table_details->addRowSet( new TLabel('%Desconto'), $detail_p_desconto );
- $table_details->addRowSet( new TLabel('Total'), $detail_iten_total );
- $table_details->addRowSet( $btn_save_detail );
- $this->detail_list = new TQuickGrid;
- $this->detail_list->setHeight( 175 );
- $this->detail_list->makeScrollable();
- $this->detail_list->disableDefaultClick();
- $this->detail_list->addQuickColumn('', 'edit', 'left', 50);
- $this->detail_list->addQuickColumn('', 'delete', 'left', 50);
- // items
- $this->detail_list->addQuickColumn('Quantidade', 'iten_quantidade', 'left', 100);
- $this->detail_list->addQuickColumn('Produto', 'produtos->pro_descricao', 'left', 50);
- $this->detail_list->addQuickColumn('Preço de Venda', 'preco_venda', 'left', 100);
- $this->detail_list->addQuickColumn('%Desconto', 'p_desconto', 'left', 100);
- $this->detail_list->addQuickColumn('Total', 'iten_total', 'left', 100);
- $this->detail_list->createModel();
- $row = $table_detail->addRow();
- $row->addCell($this->detail_list);
- $frame_final = new TFrame;
- $frame_final->setLegend('Final');
- $frame_final->style = 'background:whiteSmoke';
- $frame_final->add($table_final);
- $table_master->addRow()->addCell( $frame_final )->colspan=1;
- $row = $table_master->addRow();
- $row->addCell( $table_final );
- $table_final->addRowSet( new TLabel('%Desconto'), $p_desconto );
- $table_final->addRowSet( new TLabel('Ajuste'), $vlr_ajuste );
- $table_final->addRowSet( new TLabel('TOTAL VENDA'), $valor_total );
- // create an action button (save)
- $save_button=new TButton('save');
- $save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
- $save_button->setImage('ico_save.png');
- // create an new button (edit with no parameters)
- $new_button=new TButton('new');
- $new_button->setAction(new TAction(array($this, 'onClear')), _t('New'));
- $new_button->setImage('ico_new.png');
- // define form fields
- $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);
- $this->formFields[] = $btn_save_detail;
- $this->formFields[] = $save_button;
- $this->formFields[] = $new_button;
- $this->formFields[] = $detail_Id;
- $this->form->setFields( $this->formFields );
- $table_master->addRowSet( array($save_button, $new_button), '', '')->class = 'tformaction'; // CSS class
- // create the page container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Clear form
- * @param $param URL parameters
- */
- public function onClear($param)
- {
- $this->form->clear(TRUE);
- TSession::setValue(__CLASS__.'_items', array());
- $this->onReload( $param );
- }
- /**
- * Save an item from form to session list
- * @param $param URL parameters
- */
- public function onSaveDetail( $param )
- {
- try
- {
- TTransaction::open('scomcomercio');
- $data = $this->form->getData();
- /** validation sample
- if (! $data->fieldX)
- throw new Exception('The field fieldX is required');
- **/
- $items = TSession::getValue(__CLASS__.'_items');
- $key = empty($data->detail_Id) ? 'X'.mt_rand(1000000000, 1999999999) : $data->detail_Id;
- $items[ $key ] = array();
- $items[ $key ]['Id'] = $key;
- $items[ $key ]['iten_quantidade'] = $data->detail_iten_quantidade;
- $items[ $key ]['id_produto'] = $data->detail_id_produto;
- $items[ $key ]['preco_venda'] = $data->detail_preco_venda;
- $items[ $key ]['p_desconto'] = $data->detail_p_desconto;
- $items[ $key ]['iten_total'] = $data->detail_iten_total;
- TSession::setValue(__CLASS__.'_items', $items);
- // clear detail form fields
- $data->detail_Id = '';
- $data->detail_iten_quantidade = '';
- $data->detail_id_produto = '';
- $data->detail_preco_venda = '';
- $data->detail_p_desconto = '';
- $data->detail_iten_total = '';
- TTransaction::close();
- $this->form->setData($data);
- $this->onReload( $param ); // reload the items
- }
- catch (Exception $e)
- {
- $this->form->setData( $this->form->getData());
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Load an item from session list to detail form
- * @param $param URL parameters
- */
- public function onEditDetail( $param )
- {
- $data = $this->form->getData();
- // read session items
- $items = TSession::getValue(__CLASS__.'_items');
- // get the session item
- $item = $items[ $param['item_key'] ];
- $data->detail_Id = $item['Id'];
- $data->detail_iten_quantidade = $item['iten_quantidade'];
- $data->detail_id_produto = $item['id_produto'];
- $data->detail_preco_venda = $item['preco_venda'];
- $data->detail_p_desconto = $item['p_desconto'];
- $data->detail_iten_total = $item['iten_total'];
- // fill detail fields
- $this->form->setData( $data );
- $this->onReload( $param );
- }
- /**
- * Delete an item from session list
- * @param $param URL parameters
- */
- public function onDeleteDetail( $param )
- {
- $data = $this->form->getData();
- // reset items
- $data->detail_iten_quantidade = '';
- $data->detail_id_produto = '';
- $data->detail_preco_venda = '';
- $data->detail_p_desconto = '';
- $data->detail_iten_total = '';
- // clear form data
- $this->form->setData( $data );
- // read session items
- $items = TSession::getValue(__CLASS__.'_items');
- // delete the item from session
- unset($items[ $param['item_key'] ] );
- TSession::setValue(__CLASS__.'_items', $items);
- // reload items
- $this->onReload( $param );
- }
- /**
- * Load the items list from session
- * @param $param URL parameters
- */
- public function onReload($param)
- {
- // read session items
- $items = TSession::getValue(__CLASS__.'_items');
- $this->detail_list->clear(); // clear detail list
- $data = $this->form->getData();
- if ($items)
- {
- $cont = 1;
- foreach ($items as $list_item_key => $list_item)
- {
- $item_name = 'prod_' . $cont++;
- $item = new StdClass;
- // create action buttons
- $action_del = new TAction(array($this, 'onDeleteDetail'));
- $action_del->setParameter('item_key', $list_item_key);
- $action_edi = new TAction(array($this, 'onEditDetail'));
- $action_edi->setParameter('item_key', $list_item_key);
- $button_del = new TButton('delete_detail'.$cont);
- $button_del->class = 'btn btn-default btn-sm';
- $button_del->setAction( $action_del, '' );
- $button_del->setImage('fa:trash-o red fa-lg');
- $button_edi = new TButton('edit_detail'.$cont);
- $button_edi->class = 'btn btn-default btn-sm';
- $button_edi->setAction( $action_edi, '' );
- $button_edi->setImage('fa:edit blue fa-lg');
- $item->edit = $button_edi;
- $item->delete = $button_del;
- $this->formFields[ $item_name.'_edit' ] = $item->edit;
- $this->formFields[ $item_name.'_delete' ] = $item->delete;
- // items
- $item->Id = $list_item['Id'];
- $item->iten_quantidade = $list_item['iten_quantidade'];
- $item->id_produto = $list_item['id_produto'];
- $item->preco_venda = $list_item['preco_venda'];
- $item->p_desconto = $list_item['p_desconto'];
- $item->iten_total = $list_item['iten_total'];
- $row = $this->detail_list->addItem( $item );
- $row->onmouseover='';
- $row->onmouseout='';
- }
- $this->form->setFields( $this->formFields );
- }
- $this->loaded = TRUE;
- }
- /**
- * Load Master/Detail data from database to form/session
- */
- public function onEdit($param)
- {
- try
- {
- TTransaction::open('scomcomercio');
- if (isset($param['key']))
- {
- $key = $param['key'];
- $object = new Vendas($key);
- $items = ItensVenda::where('id_venda', '=', $key)->load();
- $session_items = array();
- foreach( $items as $item )
- {
- $item_key = $item->Id;
- $session_items[$item_key] = $item->toArray();
- $session_items[$item_key]['Id'] = $item->Id;
- $session_items[$item_key]['iten_quantidade'] = $item->iten_quantidade;
- $session_items[$item_key]['id_produto'] = $item->id_produto;
- $session_items[$item_key]['preco_venda'] = $item->preco_venda;
- $session_items[$item_key]['p_desconto'] = $item->p_desconto;
- $session_items[$item_key]['iten_total'] = $item->iten_total;
- }
- TSession::setValue(__CLASS__.'_items', $session_items);
- $this->form->setData($object); // fill the form with the active record data
- $this->onReload( $param ); // reload items list
- TTransaction::close(); // close transaction
- }
- else
- {
- $this->form->clear(TRUE);
- TSession::setValue(__CLASS__.'_items', null);
- $this->onReload( $param );
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * Save the Master/Detail data from form/session to database
- */
- public function onSave()
- {
- try
- {
- // open a transaction with database
- TTransaction::open('scomcomercio');
- $data = $this->form->getData();
- $master = new Vendas;
- $master->fromArray( (array) $data);
- $this->form->validate(); // form validation
- $master->store(); // save master object
- // delete details
- $old_items = ItensVenda::where('id_venda', '=', $master->Id)->load();
- $keep_items = array();
- // get session items
- $items = TSession::getValue(__CLASS__.'_items');
- if( $items )
- {
- foreach( $items as $item )
- {
- if (substr($item['Id'],0,1) == 'X' ) // new record
- {
- $detail = new ItensVenda;
- }
- else
- {
- $detail = ItensVenda::find($item['Id']);
- }
- $detail->iten_quantidade = $item['iten_quantidade'];
- $detail->id_produto = $item['id_produto'];
- $detail->preco_venda = $item['preco_venda'];
- $detail->p_desconto = $item['p_desconto'];
- $detail->iten_total = $item['iten_total'];
- $detail->id_venda = $master->Id;
- $detail->store();
- $keep_items[] = $detail->Id;
- }
- }
- if ($old_items)
- {
- foreach ($old_items as $old_item)
- {
- if (!in_array( $old_item->Id, $keep_items))
- {
- $old_item->delete();
- }
- }
- }
- TTransaction::close(); // close the transaction
- // reload form and session items
- $this->onEdit(array('key'=>$master->Id));
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback();
- }
- }
- /**
- * Show the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
- ?>
Você está adicionando a table_final a 2 containers diferentes:
Obrigado Nataniel, show de bola