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
- <?php
- class VendasCompleto extends TPage{
- protected $form;
- protected $value;
- protected $itens;
- public static 667 = 0;
- protected $lista;
- protected $note;
- function __construct() {
- parent::__construct();
- $this->form = new TForm('VendasCompleta');
- $this->itens = new TQuickGrid();
- $this->itens->setHeight(400);
- // lista de itens
- $this->itens->addQuickColumn('Produto', 'produto', 'left', 40);
- $this->itens->addQuickColumn('Quantidade', 'qtd', 'right', 40);
- $this->itens->addQuickColumn('Preco', 'preco', 'right', 40);
- $this->itens->addQuickColumn('Total', 'tota', 'right', 40);
- $this->itens->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'id', 'ico_delete.png');
- $this->itens->createModel();
- $this->note = new TNotebook(800,300);
- $tableP1 = new TTable();
- 667 = new THidden('id');
- $dataf = new TDate('dataVencimento');
- $qtd = new TEntry('qtd');
- $qtd->setMask('999');
- // $qtd->setExitAction($action3);
- $valor = new TEntry('valor');
- $valor->setNumericMask(2, '.', '');
- $valor->setMaxLength(9);
- $valor->setEditable(FALSE);
- $filter = array(new TFilter('cargos_id','=',10));
- $funcionario = new TDBFCombo('funcionarios_id', 'mysql', 'Funcionarios','id', 'nome','nome',$filter);
- // cliente
- $cliente_id = new TSeekButton('cliente_id');
- $cliente = new TEntry('cliente');
- $cliente->setEditable(FALSE);
- $seek = new TStandardSeek();
- $action = new TAction(array($seek,'onSetup'));
- $action->setParameter('database', 'mysql');
- $action->setParameter('parent','VendasCompleta');
- $action->setParameter('model','Cliente');
- $action->setParameter('display_field','razaoSocial');
- $action->setParameter('receive_key','cliente_id');
- $action->setParameter('receive_field','cliente');
- $cliente_id->setAction($action);
- //produto
- $produto = new TEntry('produto');
- $produto->setEditable(FALSE);
- $produto_id = new TSeekButton('produto_id');
- $action = new TAction(array($seek,'onSetup'));
- $action->setParameter('database', 'mysql');
- $action->setParameter('parent','VendasCompleta');
- $action->setParameter('model','Produto');
- $action->setParameter('display_field','nome');
- $action->setParameter('receive_key','produto_id');
- $action->setParameter('receive_field','produto');
- $produto_id->setAction($action);
- $addcart = new TButton('addcart');
- $addcart->setAction(new TAction(array($this,'addProdutos')), 'Add Item');
- $pagamento = new TDBCombo('pagamento_id','mysql','Parcelas','id','tipo');
- // $pagamento->setChangeAction(new TAction(array($this,'parcelar')));
- $nparcelas = new TEntry('maximo');
- $juros = new TEntry('juros');
- $nparcelas->setEditable(FALSE);
- $juros->setEditable(FALSE);
- $parcelas = new TEntry('parcelas');
- $parcelas->setMask('99');
- // $parcelas->setExitAction(new TAction(array($this,'calcular')));
- $vparcela = new TEntry('vparcela');
- $vparcela->setNumericMask(2, '.', ',');
- $vparcela->setMaxLength(6);
- $vparcela->setEditable(FALSE);
- $vtotal = new TEntry('vtotal');
- $vtotal->setNumericMask(2, '.', ',');
- $vtotal->setMaxLength(6);
- $vtotal->setEditable(FALSE);
- $label = new TLabel('Data Pagamento');
- $row = $tableP1->addRow();
- $row->addCell($label);
- $cell = $row->addCell($dataf);
- $cell->colspan = 2;
- $row = $tableP1->addRow();
- $label = new TLabel('Cod Cliente');
- $row->addCell($label);
- $row->addCell($cliente_id);
- $label = new TLabel('Cliente');
- $row->addCell($label);
- $row->addCell($cliente);
- $row = $tableP1->addRow();
- $label = new TLabel('Cod Produto');
- $row->addCell($label);
- $row->addCell($produto_id);
- $label = new TLabel('Produto');
- $row->addCell($label);
- $row->addCell($produto);
- $row->addCell($addcart);
- $row = $tableP1->addRow();
- $label = new TLabel('Quantidade');
- $row->addCell($label);
- $row->addCell($qtd);
- $row = $tableP1->addRow();
- $label = new TLabel('Forma de Pagamento');
- $row->addCell($label);
- $row->addCell($pagamento);
- $row = $tableP1->addRow();
- $label = new TLabel('Parcelas');
- $row->addCell($label);
- $row->addCell($parcelas);
- $row = $tableP1->addRow();
- $label = new TLabel('Juros');
- $row->addCell($label);
- $row->addCell($juros);
- $label = new TLabel('Valor Parcela');
- $row->addCell($label);
- $row->addCell($vparcela);
- $row=$tableP1->addRow();
- $label = new TLabel('Valor Total');
- $row->addCell($label);
- $row->addCell($valor);
- $label = new TLabel('Valor Final');
- $row->addCell($label);
- $row->addCell($vtotal);
- $row = $tableP1->addRow();
- $calcular = new TButton('gerar');
- $calcular->setAction(new TAction(array($this,'calcular')),'Calcular');
- $save = new TButton('salvar');
- $save->setAction(new TAction(array($this,'onSave')),'gravar');
- $save->setImage('ico_save.png');
- $row->addCell($calcular);
- $row->addCell($save);
- $this->form->add($tableP1);
- $this->form->setFields(array($addcart,$produto_id,
- $cliente_id,$vparcela,
- $vtotal,$parcelas,$pagamento,$qtd,$dataf,$cliente,
- $produto,$calcular,$juros,$valor,$save));
- $this->note->appendPage('Dados Cliente', $this->form);
- $this->note->appendPage('Lista de produtos', $this->itens );
- parent::add($this->note);
- }
- function onEdit($param = NULL){
- $dados = $this->form->getData();
- if(empty($this->id)){
- $this->lastId();
- }
- try {
- TTransaction::open('mysql');
- if(isset($param['key'])){
- $venda = new Receber($param['key']);
- $dados->dataVencimento = $venda->dataVencimento ;
- $dados->produto_id = $venda->produto_id ;
- $dados->vendedor_id = $venda->vendedor_id ;
- $dados->cliente_id = $venda->cliente_id ;
- $dados->vparcela = $venda->vparcela ;
- $dados->vtotal = $venda->vtotal ;
- $dados->pagamento_id = $venda->pagamento_id ;
- }else{
- $venda = new Receber(self::667);
- $dados->dataVencimento = $venda->dataVencimento ;
- $dados->produto_id = $venda->produto_id ;
- $dados->vendedor_id = $venda->vendedor_id ;
- $dados->cliente_id = $venda->cliente_id ;
- $dados->vparcela = $venda->vparcela ;
- $dados->vtotal = $venda->vtotal ;
- $dados->pagamento_id = $venda->pagamento_id ;
- }
- TForm::sendData('VendasCompleta', $dados);
- TTransaction::close();
- } catch (Exception $ex) {
- new TMessage('error', $ex->getMessage());
- TTransaction::rollback();
- }
- }
- public function calcular()
- {
- TTransaction::open('mysql');
- $dados = $this->form->getData();
- $juros = 1 + $dados->juros /100;
- $vjuros = pow($juros, $dados->parcelas);
- $dados->vtotal =round(( $dados->valor * $vjuros),2);
- $dados->vparcela = round(( $dados->vtotal / $dados->parcelas),2);
- $par = new Parcelas($dados->pagamento_id);
- $dados->maximo = $par->maximo;
- $dados->juros = $par->juros;
- TForm::sendData('VendasCompleta', $dados);
- TTransaction::close();
- }
- function addProdutos(){
- TTransaction::open('mysql');
- $dados = $this->form->getData();
- $produto = new Produto($dados->produto_id);
- $venda = new ItensVenda();
- $venda->venda_id = self::667 ;
- $venda->produto_id = $produto->id;
- $venda->qtd = $dados->qtd;
- $venda->preco = $produto->preco;
- $venda->total = ( $dados->qtd * $produto->preco);
- $venda->store();
- $dados->valor += ($produto->preco * $dados->qtd);
- TForm::sendData('VendasCompleta', $dados);
- TTransaction::close();
- }
- function onDelete($param){
- }
- function onReload($param = NULL){
- $venda = new Receber(self::667);
- foreach ($venda as $key ) {
- $item = new StdClass();
- $item->id = $key->venda->venda_id;
- $item->produto = $key->venda->produto->nome;
- $item->qtd = $key->venda->qtd;
- $item->preco = $key->venda->preco;
- $item->total = $key->venda->total ;
- $this->itens->addItem($item);
- }
- }
- function onSave(){
- $dados = $this->form->getData();
- try {
- TTransaction::open('mysql');
- $venda = new Receber();
- $venda->id = $this->id;
- $venda->dataVencimento = $dados->dataVencimento ;
- $venda->vendedor_id = $dados->vendedor_id;
- $venda->cliente_id = $dados->cliente_id ;
- $venda->vparcela = $dados->vparcela;
- $venda->vtotal = $dados->vtotal;
- $venda->pagamento_id = $dados->pagamento_id;
- $venda->store();
- new TMessage('seccess', 'Venda Realizada com Exito');
- TForm::sendData('VendasCompleta', $dados);
- TTransaction::close();
- } catch (Exception $ex) {
- new TMessage('error', $ex->getMessage());
- TTransaction::rollback();
- }
- }
- function lastId(){
- TTransaction::open('mysql');
- $novo = new Receber();
- $novo->store();
- $repo = new TRepository('Receber');
- $criteria = new TCriteria();
- $criteria->setProperty('order', 'id');
- $criteria->setProperty('direction','DESC');
- $criteria->setProperty('limit', '1');
- $produtos = $repo->load($criteria);
- foreach ($produtos as $p){
- self::667 = $p->id;
- }
- TTransaction::close();
- }
- }
Oi Alexandre,
O onReload() não é executado em nenhum ponto... Nem ao menos no show().
abs,
Pablo