AS
carregar dados e TMultField
Fechado
boa tarde pessoal sei que ja tem um topico com esse titulo, aute segui ele porem não consegui resolver o problema, fiz a parte de salvar normal porem para editar não estou conseguindo colocar os dados no mult field
segue a minha model
formulario, onde o edit não vai por nada
segue a minha model
- <?php
- class Receber extends TRecord{
- const TABLENAME = "tblContasReceber";
- const PRIMARYKEY = "id";
- const IDPOLICY = "max";
- private $vendedor;
- private $cliente;
- private $produtos;
- private $listProdutos;
- function get_cliente(){
- if(empty($this->cliente)){
- $this->cliente = new Cliente($this->cliente_id);
- }
- return $this->cliente->razaoSocial;
- }
- function set_produtos($produto){
- $this->produtos = $produto;
- }
- function get_produtos(){
- if(empty($this->produtos)){
- $this->produtos[] = new ItensVenda($this->id);
- }
- return $this->produtos;
- }
- function get_vendedor(){
- if(empty($this->vendedor)){
- $this->vendedor = new Funcionarios($this->vendedor_id);
- }
- return $this->vendedor->nome;
- }
- public function store() {
- parent::store();
- foreach ($this->produtos as $itens){
- $itenVenda = new ItensVenda();
- $produto = new Servicos($itens->idProduto);
- $itenVenda->produto_id = $itens->idProduto;
- $itenVenda->qtd = $itens->qtd;
- $itenVenda->venda_id = $this->id;
- $itenVenda->total = $produto->preco * $itens->qtd;
- $itenVenda->store();
- }
- }
- }
- ?>
formulario, onde o edit não vai por nada
- <?php
- class VendasCompleto extends TPage{
- protected $form;
- protected $multfild;
- protected $note;
- function __construct() {
- parent::__construct();
- User::checaLogin('convidado');
- $this->form = new TForm('VendasCompleta');
- $this->note = new TNotebook(800,300);
- $pg1 = new TTable();
- 692 = new THidden('id');
- $dataVencimento = new TDate('dataVencimento');
- $vendedorId = new TSeekButton('vendedor_id');
- $vendedor_nome = new TEntry('vendedor');
- $cliente_id = new TSeekButton('cliente_id');
- $cliente_nome = new TEntry('cliente_nome');
- $vparcelas = new TEntry('vparcelas');
- $vtotal = new TEntry('vtotal');
- $pagamento_id = new TDBCombo('pagamento_id', 'mysql', 'Parcelas','id','tipo');
- $parcelas = new TEntry('parcelas');
- $calcular = new TButton('btnCalc');
- $this->multfild = new TMultiField('produtos');
- // editaveis
- $vparcelas->setEditable(FALSE);
- $vtotal->setEditable(FALSE);
- $cliente_nome->setEditable(FALSE);
- $vendedor_nome->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_nome');
- $cliente_id->setAction($action);
- $seek2 = new TStandardSeek();
- $action2 = new TAction(array($seek2,'onSetup'));
- $action2->setParameter('database', 'mysql');
- $action2->setParameter('parent','VendasCompleta');
- $action2->setParameter('model','Funcionarios');
- $action2->setParameter('display_field','funcionario');
- $action2->setParameter('receive_key','vendedor_id');
- $action2->setParameter('receive_field','vendedor');
- $vendedorId->setAction($action2);
- $row = $pg1->addRow();
- $row->addCell(new TLabel('Data Vencimento: '));
- $row->addCell($dataVencimento);
- $row = $pg1->addRow();
- $row->addCell(new TLabel('cod Vendedor'));
- $row->addCell($vendedorId);
- $row->addCell($vendedor_nome);
- $row = $pg1->addRow();
- $row->addCell(new TLabel('cod Cliente'));
- $row->addCell($cliente_id);
- $row->addCell($cliente_nome);
- $row = $pg1->addRow();
- $row->addCell(new TLabel('Parcelas: '));
- $row->addCell($parcelas);
- $row->addCell(new TLabel('Valor Parcelas'));
- $row->addCell($vparcelas);
- $row = $pg1->addRow();
- $row->addCell(new TLabel('Forma PGTO'));
- $row->addCell($pagamento_id);
- $row->addCell(new TLabel('Total'));
- $row->addCell($vtotal);
- $btnSalvar = new TButton('salvar');
- $btnSalvar->setAction(new TAction(array($this,'onSave')),'Fechar Venda');
- $btnSalvar->setImage('ico_save.png');
- $calcular->setAction(new TAction(array($this,'calcular')),'Calcular');
- $row = $pg1->addRow();
- $row->addCell($calcular);
- $row->addCell($btnSalvar);
- $produto = new TEntry('nomeProduto');
- $produto->setEditable(FALSE);
- $cod_produto = new TSeekButton('idProduto');
- $qtd = new TEntry('qtd');
- $seek3 = new TStandardSeek();
- $action3 = new TAction(array($seek2,'onSetup'));
- $action3->setParameter('database', 'mysql');
- $action3->setParameter('parent','VendasCompleta');
- $action3->setParameter('model','Servicos');
- $action3->setParameter('display_field','nome');
- $action3->setParameter('receive_key','produtos_idProduto');
- $action3->setParameter('receive_field','produtos_nomeProduto');
- $cod_produto->setAction($action3);
- $this->multfild->setClass('ItensVenda');
- $this->multfild->addField('produto_id', 'Codigo', $cod_produto,200);
- $this->multfild->addField('produto', 'Produto', $produto, 300);
- $this->multfild->addField('qtd', 'Quantidade', $qtd, 50);
- $this->note->appendPage('Dados Basicos', $pg1);
- $this->note->appendPage('Dados Produtos', $this->multfild);
- $this->form->setFields(array(692,$dataVencimento,$vendedorId,$vendedor_nome
- ,$cliente_id,$cliente_nome,$vparcelas,$vtotal,
- $pagamento_id,$parcelas,$calcular,$this->multfild,$btnSalvar));
- $this->form->add($this->note);
- parent::add($this->form);
- }
- function calcular($param){
- try{
- $obj = $this->form->getData();
- $valorTotal = 0;
- TTransaction::open('mysql');
- foreach ($obj->produtos as $p){
- $produto = new Servicos($p->idProduto);
- $valorTotal = $produto->preco * $p->qtd;
- }
- $pagamento = new Parcelas($obj->pagamento_id);
- $obj->vtotal = round( $this->calcParcelaJuros($valorTotal, $obj->parcelas, $pagamento->juros),2);
- $obj->vparcelas = round(($this->calcParcelaJuros($valorTotal, $obj->parcelas, $pagamento->juros)/$obj->parcelas),2);
- $this->form->setData($obj);
- // TForm::sendData('VendasCompleta', $obj);
- TTransaction::close();
- } catch (Exception $e){
- new TMessage('info', $e->getMessage());
- TTransaction::rollback();
- }
- }
- function calcParcelaJuros($valor,$parcelas,$taxa){
- $taxa = $taxa / 100;
- $valParcela = $valor * pow((1 + $taxa), $parcelas);
- return $valParcela;
- }
- function onSave()
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('mysql');
- $this->form->validate();
- // read the form data and instantiates an Active Record
- $customer = $this->form->getData();
- $venda = new Receber();
- // add the contact to the customer
- $venda->vendedor_id = $customer->vendedor_id;
- $venda->cliente_id = $customer->cliente_id;
- $venda->dataVencimento = $customer->dataVencimento;
- $venda->dataVenda = date('Y-m-d');
- $venda->vparcela = $customer->vparcelas;
- $venda->vtotal = $customer->vtotal;
- $venda->pagamento_id = $customer->pagamento_id;
- $venda->parcelas = $customer->parcelas;
- $venda->produtos = $customer->produtos;
- $venda->dataVenda = date('Y-d-m');
- // stores the object in the database
- $venda->store();
- $this->form->setData($customer);
- // shows the success message
- new TMessage('info', 'Venda Efetuada com susseso');
- TTransaction::close(); // close the transaction
- TApplication::executeMethod('VendasView');
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b>' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- function onEdit($param){
- try
- {
- if(isset($param['key'])){
- // open a transaction with database 'samples'
- TTransaction::open('mysql');
- $this->form->validate($param['key']);
- // read the form data and instantiates an Active Record
- $venda = new Receber($param['key']);
- $obj = new stdClass();
- $produto_list = array();
- if ($venda->produtos)
- {
- foreach ($venda->produtos as $produto)
- {
- // add the contact to the customer
- $produto_list[] = $produto->id;
- }
- }
- $obj->vendedor_id = $venda->vendedor_id;
- $obj->vendedor = $venda->vendedor;
- $obj->cliente_id = $venda->cliente_id;
- $obj->cliente_nome = $venda->cliente;
- $obj->dataVencimento = $venda->dataVencimento;
- $obj->vparcelas = $venda->vparcela;
- $obj->vtotal = $venda->vtotal;
- $obj->pagamento_id = $venda->pagamento_id;
- $obj->parcelas = $venda->parcelas;
- $obj->produtos = $produto_list;
- // stores the object in the database
- $this->form->setData($obj);
- TTransaction::close(); // close the transaction
- }else{
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b>' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- so falta o multfield ai o edite fica completo
galera consegui, vlw
Alexandre,
Poste sua solução, só para ficar registrado ;-)
Será que a solução foi essa?
www.adianti.com.br/forum/pt/view_695?nao-consigo-pegar-os-dados-do-t
abs,
Pablo
então pablo hoje ue fui ver isso, estava com o mesmo problema , vim ver , descobri que não postei a resposta
resolvi isso da seguinte maneira, sempre que usar um TSeekButton com TMultField, no retorno do TSeek qtemque ter o prefix o nome do tmultfield
ex:
abraços