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

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


NR

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

Obrigado Nataniel, show de bola