Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TNoteBook problema com abas galera to querendo montar uma maneira do usuario adcionar itens a compra, ate que de +/- certo porem quando eu adciono um item o DATAGRID não atualiza, e tambem não grava o id da venda, alguem tem uma ideia onde errei na logica ...
AS
TNoteBook problema com abas  
Fechado
galera to querendo montar uma maneira do usuario adcionar itens a compra, ate que de +/- certo porem quando eu adciono um item o DATAGRID não atualiza, e tambem não grava o id da venda, alguem tem uma ideia onde errei na logica

  1. <?php
  2. class VendasCompleto extends TPage{
  3.     
  4.     protected $form;
  5.     protected  $value;
  6.     protected $itens;
  7.     public static 667 0;
  8.     protected $lista;
  9.     
  10.     protected   $note;
  11.             function __construct() {
  12.         parent::__construct();
  13.         
  14.       
  15.         
  16.         $this->form = new TForm('VendasCompleta');
  17.        
  18.         $this->itens = new TQuickGrid();
  19.         $this->itens->setHeight(400);
  20.         
  21.         // lista de itens
  22.           $this->itens->addQuickColumn('Produto''produto''left'40);
  23.      $this->itens->addQuickColumn('Quantidade''qtd''right'40);
  24.      $this->itens->addQuickColumn('Preco''preco''right'40);
  25.      $this->itens->addQuickColumn('Total''tota''right'40);
  26.      
  27.         $this->itens->addQuickAction('Delete', new TDataGridAction(array($this'onDelete')), 'id''ico_delete.png');
  28.         
  29.         $this->itens->createModel();
  30.         
  31.       
  32.           $this->note = new TNotebook(800,300);
  33.         $tableP1 = new TTable();
  34.         
  35.         
  36.            
  37.         667 = new THidden('id');
  38.         
  39.         $dataf = new TDate('dataVencimento');
  40.         
  41.         $qtd = new TEntry('qtd');
  42.         $qtd->setMask('999');
  43.        
  44.       //    $qtd->setExitAction($action3);
  45.           
  46.         
  47.         $valor = new TEntry('valor');
  48.         $valor->setNumericMask(2'.''');
  49.         $valor->setMaxLength(9);
  50.         $valor->setEditable(FALSE);
  51.         
  52. $filter = array(new TFilter('cargos_id','=',10));
  53.       $funcionario = new TDBFCombo('funcionarios_id''mysql''Funcionarios','id''nome','nome',$filter);
  54.     
  55.         
  56.       
  57.       // cliente
  58.        $cliente_id = new TSeekButton('cliente_id');
  59.         $cliente = new TEntry('cliente');
  60.         $cliente->setEditable(FALSE);
  61.         $seek = new TStandardSeek();
  62.         
  63.         $action = new TAction(array($seek,'onSetup'));
  64.         $action->setParameter('database''mysql');
  65.         $action->setParameter('parent','VendasCompleta');
  66.         $action->setParameter('model','Cliente');
  67.         $action->setParameter('display_field','razaoSocial');
  68.         $action->setParameter('receive_key','cliente_id');
  69.         $action->setParameter('receive_field','cliente');
  70.         
  71.           $cliente_id->setAction($action);
  72.         
  73.         //produto
  74.      
  75.       $produto = new TEntry('produto');
  76.       $produto->setEditable(FALSE);
  77.       $produto_id = new TSeekButton('produto_id');
  78.      
  79.       
  80.         $action = new TAction(array($seek,'onSetup'));
  81.         $action->setParameter('database''mysql');
  82.         $action->setParameter('parent','VendasCompleta');
  83.         $action->setParameter('model','Produto');
  84.         $action->setParameter('display_field','nome');
  85.         $action->setParameter('receive_key','produto_id');
  86.         $action->setParameter('receive_field','produto');
  87.         
  88.           $produto_id->setAction($action);
  89.           
  90.       $addcart = new TButton('addcart');
  91.       
  92.       $addcart->setAction(new TAction(array($this,'addProdutos')), 'Add Item');
  93.     
  94.         
  95.           $pagamento = new TDBCombo('pagamento_id','mysql','Parcelas','id','tipo');
  96.        //   $pagamento->setChangeAction(new TAction(array($this,'parcelar')));
  97.         $nparcelas = new TEntry('maximo');
  98.         $juros = new TEntry('juros');
  99.        
  100.        
  101.         $nparcelas->setEditable(FALSE);
  102.         $juros->setEditable(FALSE);
  103.        
  104.      
  105.        $parcelas = new TEntry('parcelas');
  106.         $parcelas->setMask('99');
  107.     //    $parcelas->setExitAction(new TAction(array($this,'calcular')));
  108.       
  109.         $vparcela = new TEntry('vparcela');
  110.         $vparcela->setNumericMask(2'.'',');
  111.         $vparcela->setMaxLength(6);
  112.         $vparcela->setEditable(FALSE);
  113.         
  114.          $vtotal = new TEntry('vtotal');
  115.         $vtotal->setNumericMask(2'.'',');
  116.         $vtotal->setMaxLength(6);
  117.         $vtotal->setEditable(FALSE);
  118.         
  119.        
  120.        $label = new TLabel('Data Pagamento');
  121.       $row =  $tableP1->addRow();
  122.       
  123.       $row->addCell($label);
  124.       $cell $row->addCell($dataf);
  125.      $cell->colspan 2;
  126.       
  127.        $row =  $tableP1->addRow();
  128.        $label = new TLabel('Cod Cliente');
  129.        $row->addCell($label);
  130.        $row->addCell($cliente_id);
  131.        
  132.        $label = new TLabel('Cliente');
  133.        $row->addCell($label);
  134.        $row->addCell($cliente);
  135.        
  136.         $row =  $tableP1->addRow();
  137.      
  138.        $label = new TLabel('Cod Produto');
  139.        $row->addCell($label);
  140.        $row->addCell($produto_id);
  141.        
  142.        $label = new TLabel('Produto');
  143.        $row->addCell($label);
  144.        $row->addCell($produto);
  145.        $row->addCell($addcart);
  146.        
  147.       $row =  $tableP1->addRow();
  148.           $label = new TLabel('Quantidade');
  149.        $row->addCell($label);
  150.       $row->addCell($qtd);
  151.       
  152.    
  153.       
  154.       
  155.       
  156.    
  157.       $row $tableP1->addRow();
  158.     
  159.       
  160.          $label = new TLabel('Forma de Pagamento');
  161.        $row->addCell($label);
  162.    $row->addCell($pagamento);
  163.    
  164.     $row $tableP1->addRow();
  165.           $label = new TLabel('Parcelas');
  166.        $row->addCell($label);
  167.    $row->addCell($parcelas);
  168.    
  169.     $row $tableP1->addRow();
  170.        $label = new TLabel('Juros');
  171.        $row->addCell($label);
  172.    $row->addCell($juros);
  173.    
  174.    
  175.        $label = new TLabel('Valor Parcela');
  176.        $row->addCell($label);
  177.    $row->addCell($vparcela);
  178.    
  179.    
  180.        $row=$tableP1->addRow();
  181.        
  182.          $label = new TLabel('Valor Total');
  183.        $row->addCell($label);
  184.       $row->addCell($valor);
  185.       
  186.    
  187.        $label = new TLabel('Valor Final');
  188.        $row->addCell($label);
  189.    $row->addCell($vtotal);
  190.    
  191.    
  192.    
  193.    $row $tableP1->addRow();
  194.    $calcular = new TButton('gerar');
  195.    
  196.    $calcular->setAction(new TAction(array($this,'calcular')),'Calcular');
  197.     $save = new TButton('salvar');
  198.    
  199.    $save->setAction(new TAction(array($this,'onSave')),'gravar');
  200. $save->setImage('ico_save.png');
  201.    
  202.    $row->addCell($calcular);
  203.    $row->addCell($save);
  204.       
  205.     
  206.       
  207.       
  208.       $this->form->add($tableP1);
  209.   
  210.                 
  211.      $this->form->setFields(array($addcart,$produto_id,
  212.          $cliente_id,$vparcela,
  213.          $vtotal,$parcelas,$pagamento,$qtd,$dataf,$cliente,
  214.          $produto,$calcular,$juros,$valor,$save)); 
  215.      
  216.      $this->note->appendPage('Dados Cliente'$this->form);
  217.       $this->note->appendPage('Lista de produtos',  $this->itens );
  218.       
  219.       
  220.      
  221.       parent::add($this->note);
  222.     }
  223.     
  224.     function onEdit($param NULL){
  225.              $dados $this->form->getData();
  226.              
  227.              if(empty($this->id)){
  228.                  
  229.                $this->lastId();
  230.              
  231.              }
  232.                 try {
  233.            
  234.              TTransaction::open('mysql');
  235.              
  236.         
  237.           
  238.           
  239.           
  240.           if(isset($param['key'])){   
  241.              $venda = new Receber($param['key']);
  242.           
  243.             $dados->dataVencimento $venda->dataVencimento ;
  244.             $dados->produto_id $venda->produto_id ;
  245.             $dados->vendedor_id =  $venda->vendedor_id ;
  246.             $dados->cliente_id $venda->cliente_id   ;
  247.             $dados->vparcela $venda->vparcela ;
  248.             $dados->vtotal =  $venda->vtotal ;
  249.             $dados->pagamento_id $venda->pagamento_id ;
  250.              
  251.           }else{
  252.               
  253.                
  254.                  $venda = new Receber(self::667);
  255.           
  256.             $dados->dataVencimento $venda->dataVencimento ;
  257.             $dados->produto_id $venda->produto_id ;
  258.             $dados->vendedor_id =  $venda->vendedor_id ;
  259.             $dados->cliente_id $venda->cliente_id   ;
  260.             $dados->vparcela $venda->vparcela ;
  261.             $dados->vtotal =  $venda->vtotal ;
  262.             $dados->pagamento_id $venda->pagamento_id ;
  263.           }
  264.              
  265.         
  266.   
  267.                  TForm::sendData('VendasCompleta'$dados);
  268.              TTransaction::close();
  269.        } catch (Exception $ex) {
  270.            
  271.            new TMessage('error'$ex->getMessage());
  272.            TTransaction::rollback();
  273.            
  274.        }
  275.     }
  276.     
  277.       public function calcular()
  278.     {
  279.            
  280.           
  281.              TTransaction::open('mysql');
  282.              
  283.             $dados $this->form->getData();
  284.             
  285.             
  286.        
  287.       
  288.       
  289.         $juros +  $dados->juros /100;
  290.         $vjuros pow($juros$dados->parcelas);
  291.         
  292.       $dados->vtotal =round(( $dados->valor $vjuros),2);
  293.       $dados->vparcela round(( $dados->vtotal /  $dados->parcelas),2);
  294.       
  295.       $par = new Parcelas($dados->pagamento_id);
  296.   
  297.         
  298. $dados->maximo $par->maximo;
  299. $dados->juros $par->juros;
  300.         TForm::sendData('VendasCompleta'$dados);
  301.         
  302.        TTransaction::close();
  303.     
  304.     }
  305.     
  306.    
  307.    function addProdutos(){
  308.        
  309.           
  310.              TTransaction::open('mysql');
  311.              
  312.              $dados $this->form->getData();
  313.              
  314. $produto = new Produto($dados->produto_id);
  315. $venda = new ItensVenda();
  316. $venda->venda_id self::667 ;
  317. $venda->produto_id $produto->id;
  318. $venda->qtd $dados->qtd;
  319. $venda->preco $produto->preco;
  320. $venda->total = ( $dados->qtd $produto->preco);
  321.         
  322. $venda->store();
  323.  $dados->valor += ($produto->preco $dados->qtd); 
  324.  
  325.               TForm::sendData('VendasCompleta'$dados);
  326.               
  327.              TTransaction::close();
  328.              
  329.            
  330.        
  331.    }
  332.    
  333.    function onDelete($param){
  334.        
  335.    }
  336.            function onReload($param NULL){
  337.                
  338.       
  339.              
  340. $venda = new Receber(self::667);
  341.  
  342.  foreach ($venda as $key ) {
  343.      
  344. $item = new StdClass();
  345. $item->id $key->venda->venda_id;
  346. $item->produto $key->venda->produto->nome;
  347. $item->qtd $key->venda->qtd;
  348. $item->preco $key->venda->preco;
  349. $item->total $key->venda->total ;
  350.  $this->itens->addItem($item);
  351.  }
  352.             
  353.             
  354.        
  355.    }
  356.    
  357.   
  358.     
  359.    function onSave(){
  360.        
  361.        $dados $this->form->getData();
  362.        
  363.        try {
  364.            
  365.              TTransaction::open('mysql');
  366.              
  367.              $venda = new Receber();
  368.              $venda->id $this->id;
  369.              $venda->dataVencimento $dados->dataVencimento ;
  370.     
  371.              $venda->vendedor_id $dados->vendedor_id;
  372.              $venda->cliente_id  $dados->cliente_id ;
  373.              $venda->vparcela $dados->vparcela;
  374.              $venda->vtotal $dados->vtotal;
  375.              $venda->pagamento_id $dados->pagamento_id;
  376.              
  377.              $venda->store();
  378.              
  379.              new TMessage('seccess''Venda Realizada com Exito');
  380.                  TForm::sendData('VendasCompleta'$dados);
  381.              TTransaction::close();
  382.        } catch (Exception $ex) {
  383.            
  384.            new TMessage('error'$ex->getMessage());
  385.            TTransaction::rollback();
  386.            
  387.        }
  388.    }
  389.    
  390.    
  391.    function lastId(){
  392.            TTransaction::open('mysql');
  393.         $novo = new Receber();
  394.             $novo->store();
  395.             
  396.     $repo = new TRepository('Receber');
  397.     
  398.     $criteria = new TCriteria();
  399.  $criteria->setProperty('order''id');
  400. $criteria->setProperty('direction','DESC'); 
  401. $criteria->setProperty('limit''1');
  402.  $produtos $repo->load($criteria);
  403.  foreach ($produtos as $p){
  404.  
  405.      self::667 $p->id;
  406.  }
  407.  
  408.  TTransaction::close();
  409.    }
  410. }

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


PD

Oi Alexandre,

O onReload() não é executado em nenhum ponto... Nem ao menos no show().

abs,
Pablo