Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Preencher um TCombo, com base no valor selecionado em um TDBUniq Bom dia... Amigos estou com um formulário onde digito o cliente, e quero que seja apresentado as lojas referentes a esse cliente selecionado. na combo. Anexo há tabela com o relacionamento. Abaixo segue o código completo, eu tentei escrever um código mas não retorna nada, fico agradecido desde já pela ajuda. ...
RF
Preencher um TCombo, com base no valor selecionado em um TDBUniq  
Bom dia...

Amigos estou com um formulário onde digito o cliente, e quero que seja apresentado as lojas referentes a esse cliente selecionado. na combo.
Anexo há tabela com o relacionamento.
Abaixo segue o código completo, eu tentei escrever um código mas não retorna nada, fico agradecido desde já pela ajuda.
  1. <?php
  2. /**
  3.  * digitacao_solicitacao_de_carga Master/Detail
  4.  * @author  <your name here>
  5.  */
  6. class digitacao_solicitacao_de_carga extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     
  11.     /**
  12.      * Page constructor
  13.      */
  14.     public function __construct()
  15.     {
  16.         parent::__construct();
  17.         
  18.         // creates the form
  19.         $this->form = new BootstrapFormBuilder('form_solicitacao_de_carga');
  20.         $this->form->setFormTitle('Solicitação de carga');
  21.         $this->form->setFieldSizes('100%');
  22.         
  23.         // master fields
  24.         $id = new TEntry('id');
  25.         $status_carga = new TEntry('status_carga');
  26.         $servico = new TEntry('servico');
  27.         $data_cadastro = new TDate('data_cadastro');
  28.         $unidade_devolucao = new TEntry('unidade_devolucao');
  29.         $unidade_coleta = new TEntry('unidade_coleta');
  30.         $uf_origem = new TEntry('uf_origem');
  31.         $cidade_origem = new TEntry('cidade_origem');
  32.         $uf_destino = new TEntry('uf_destino');
  33.         $cidade_destino = new TEntry('cidade_destino');
  34.         $prazo_entrega = new TEntry('prazo_entrega');
  35.         $unidade_id                     = new TDBCombo       ('unidade_id','banco','unidade','id','razao_social');
  36.         $cliente_id                     = new TDBUniqueSearch('cliente_id','banco','cliente','id','razao_social');//TEntry('cliente_id');
  37.         $loja_id                        = new TCombo('loja_id');//TDBCombo       ('loja_id',   'banco','loja',   'id','nome_fantasia');//TEntry('loja_id');
  38.         $remetente_cnpj = new TEntry('remetente_cnpj');
  39.         $remetente_ie = new TEntry('remetente_ie');
  40.         $remetente_rz_social = new TEntry('remetente_rz_social');
  41.         $remetente_cep = new TEntry('remetente_cep');
  42.         $remetente_uf = new TEntry('remetente_uf');
  43.         $remetente_cidade = new TEntry('remetente_cidade');
  44.         $remetente_endereco = new TEntry('remetente_endereco');
  45.         $remetente_numero = new TEntry('remetente_numero');
  46.         $remetente_bairro = new TEntry('remetente_bairro');
  47.         $remetente_complemento = new TEntry('remetente_complemento');
  48.         $remetente_telefone = new TEntry('remetente_telefone');
  49.         $remetente_email = new TEntry('remetente_email');
  50.         $destinatario_cnpj = new TEntry('destinatario_cnpj');
  51.         $destinatario_ie = new TEntry('destinatario_ie');
  52.         $destinatario_rz_social = new TEntry('destinatario_rz_social');
  53.         $destinatario_cep = new TEntry('destinatario_cep');
  54.         $destinatario_uf = new TEntry('destinatario_uf');
  55.         $destinatario_id                = new TDBCombo('destinatario_id','banco','destinatario','id','cnpj_cpf'); //TEntry('destinatario_id');
  56.         $destinatario_cidade = new TEntry('destinatario_cidade');
  57.         $destinatario_endereco = new TEntry('destinatario_endereco');
  58.         $destinatario_numero = new TEntry('destinatario_numero');
  59.         $destinatario_bairro = new TEntry('destinatario_bairro');
  60.         $destinatario_completo = new TEntry('destinatario_completo');
  61.         $destinatario_telefone = new TEntry('destinatario_telefone');
  62.         $destinatario_email = new TEntry('destinatario_email');
  63.         $expedior_cnpj = new TEntry('expedior_cnpj');
  64.         $expedior_ie = new TEntry('expedior_ie');
  65.         $expedior_rz_social = new TEntry('expedior_rz_social');
  66.         $expedior_cep = new TEntry('expedior_cep');
  67.         $expedior_uf = new TEntry('expedior_uf');
  68.         $expedior_cidade = new TEntry('expedior_cidade');
  69.         $expedior_endereco = new TEntry('expedior_endereco');
  70.         $expedior_numero = new TEntry('expedior_numero');
  71.         $expedior_bairro = new TEntry('expedior_bairro');
  72.         $expedior_complemento = new TEntry('expedior_complemento');
  73.         $expedior_telefone = new TEntry('expedior_telefone');
  74.         $expedior_email = new TEntry('expedior_email');
  75.         $tomador_cnpj = new TEntry('tomador_cnpj');
  76.         $tomador_ie = new TEntry('tomador_ie');
  77.         $tomador_rz_social = new TEntry('tomador_rz_social');
  78.         $tomador_cep = new TEntry('tomador_cep');
  79.         $tomador_uf = new TEntry('tomador_uf');
  80.         $tomador_cidade = new TEntry('tomador_cidade');
  81.         $tomador_endereco = new TEntry('tomador_endereco');
  82.         $tomador_numero = new TEntry('tomador_numero');
  83.         $tomador_bairro = new TEntry('tomador_bairro');
  84.         $tomador_complemento = new TEntry('tomador_complemento');
  85.         $tomador_telefone = new TEntry('tomador_telefone');
  86.         $tomador_email = new TEntry('tomador_email');
  87.         $tipo_de_documento         = new TCombo('tipo_de_documento');//TEntry
  88.         $valor_rs_total            = new TEntry('valor_rs_total');
  89.         $volume_total              = new TEntry('volume_total');
  90.         $peso_total                = new TEntry('peso_total');
  91.         $cubagem_total             = new TEntry('cubagem_total');
  92.         $peso_cubado_total         = new TEntry('peso_cubado_total');
  93.         $peso_taxado               = new TEntry('peso_taxado');
  94.         // detail fields
  95.         $detail_id = new THidden('detail_id');
  96.         $detail_nota_fiscal = new TEntry('detail_nota_fiscal');
  97.         $detail_serie_nota_fiscal = new TEntry('detail_serie_nota_fiscal');
  98.         $detail_danfe = new TEntry('detail_danfe');
  99.         $detail_emissao = new TDate('detail_emissao');
  100.         $detail_valor = new TEntry('detail_valor');
  101.         $detail_pedido = new TEntry('detail_pedido');
  102.         $detail_entrega = new TEntry('detail_entrega');
  103.         $detail_carga = new TEntry('detail_carga');
  104.         $detail_volumes = new TEntry('detail_volumes');
  105.         $detail_peso_informado = new TEntry('detail_peso_informado');
  106.         //$detail_peso_medido = new TEntry('detail_peso_medido');
  107.         $detail_fator_cubagem = new TEntry('detail_fator_cubagem');
  108.         $detail_comprimento = new TEntry('detail_comprimento');
  109.         $detail_largura = new TEntry('detail_largura');
  110.         $detail_altura = new TEntry('detail_altura');
  111.         $detail_cubagem = new TEntry('detail_cubagem');
  112.         $detail_peso_taxado = new TEntry('detail_peso_taxado');
  113.         //$detail_itens_notas_fiscais_carga_id = new TEntry('detail_itens_notas_fiscais_carga_id');
  114.         if (!empty($id))
  115.         {
  116.             $id->setEditable(FALSE);
  117.         }
  118.         
  119.         //Mascara da data
  120.         $data_cadastro  ->setMask('dd/mm/yyyy');
  121.         $detail_emissao ->setMask('dd/mm/yyyy');
  122.         
  123.         // Busca as informações e preenche os campos da loja
  124.         $loja_id          ->setChangeAction(new TAction([$this,'buscaDadosLoja']));
  125.         
  126.         $combo_tipodoc = array();
  127.         $combo_tipodoc ['NF-e']          = 'NF-e';
  128.         $combo_tipodoc ['Declaração']    = 'Declaração';
  129.         $tipo_de_documento -> addItems($combo_tipodoc);
  130.         $tipo_de_documento->setValue('NF-e');// default value
  131.        
  132.         //******************************       
  133.         $cliente_action = new TAction(array($this'onChangeAction'));
  134.         $cliente_id->setChangeAction($cliente_action);
  135.         
  136.         
  137.         // master fields
  138.         // Primeira Aba
  139.         $this->form->appendPage('Dados da nota');
  140.         $row $this->form->addFields( [ new TLabel('Número da solicitação'),   $id ],
  141.                                        [ new TLabel('Unidade'),                 $unidade_id ], 
  142.                                        [ new TLabel('Status'),                  $status_carga ],
  143.                                        [ new TLabel('Data de digitação'),       $data_cadastro ] );
  144.         $row->layout = ['col-sm-3''col-sm-3','col-sm-3','col-sm-3' ];
  145.         // Campos das unidades
  146.         $this->form->addContent( ['<h4>Dados das unidades</h4><hr>'] );
  147.         $row $this->form->addFields( [ new TLabel('Cliente'),                $cliente_id ],
  148.                                        [ new TLabel('Loja'),                   $loja_id ],
  149.                                        [ new TLabel('Serviço'),                $servico ]);
  150.         $row->layout = ['col-sm-4''col-sm-4','col-sm-4' ];
  151.         $row $this->form->addFields( [ new TLabel('Unidade de devolução'),   $unidade_devolucao ],
  152.                                        [ new TLabel('Unidade de coleta'),      $unidade_coleta ],
  153.                                        [ new TLabel('Prazo de entrega'),       $prazo_entrega 
  154.                                        );
  155.         $row->layout = ['col-sm-4''col-sm-4','col-sm-4' ];
  156.         // Campos de origem e destino
  157.         $this->form->addContent( ['<h4>Origem e destino da carga</h4><hr>'] );
  158.         $row $this->form->addFields( [ new TLabel('UF origem'),              $uf_origem],
  159.                                        [ new TLabel('Cidade origem'),          $cidade_origem ],
  160.                                        [ new TLabel('UF destino'),             $uf_destino],
  161.                                        [ new TLabel('Cidade destino'),         $cidade_destino] );
  162.         $row->layout = ['col-sm-2''col-sm-4','col-sm-2''col-sm-4' ];
  163.         
  164.         // CAMPOS DAS NOTAS FISCAIS - APRESENTAÇÃO EM TELA
  165.         $this->form->addContent( ['<h4>Dados da Nota Fiscal</h4><hr>'] );
  166.         $this->form->addFields( [$detail_id] );     
  167.         
  168.         $row $this->form->addFields( [ new TLabel('Tipo de documento'),  $tipo_de_documento ], 
  169.                                        [ new TLabel('Número do documento'),$detail_nota_fiscal ],
  170.                                        [ new TLabel('Série'),              $detail_serie_nota_fiscal ],
  171.                                        [ new TLabel('Número da DANFE'),    $detail_danfe 
  172.                                        );
  173.         $row->layout = ['col-sm-3''col-sm-3','col-sm-3','col-sm-3' ];
  174.         
  175.         
  176.        // $this->form->addFields( [new TLabel('Tipo De Documento')], [$tipo_de_documento] );
  177.         
  178.         $row $this->form->addFields( [ new TLabel('Emissão - DANFE'),        $detail_emissao],
  179.                                        [ new TLabel('Valor'),                  $detail_valor ],
  180.                                        [ new TLabel('Volume'),                 $detail_volumes],
  181.                                        [ new TLabel('Peso'),                   $detail_peso_informado] );
  182.         $row->layout = ['col-sm-3''col-sm-3','col-sm-3''col-sm-3' ];
  183.         
  184.         $row $this->form->addFields( [ new TLabel('Comprimento'),      $detail_comprimento ],
  185.                                        [ new TLabel('Largura'),          $detail_largura ],
  186.                                        [ new TLabel('Altura'),           $detail_altura 
  187.                                        );
  188.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  189.         
  190.         $row $this->form->addFields( [ new TLabel('Fator cubagem'),    $detail_fator_cubagem ],
  191.                                        [ new TLabel('Cubagem'),          $detail_cubagem ],
  192.                                        [ new TLabel('Peso Taxado'),      $detail_peso_taxado 
  193.                                        );
  194.         $row->layout = ['col-sm-4''col-sm-4','col-sm-4' ];
  195.         
  196.         $row $this->form->addFields( [ new TLabel('Pedido'),    $detail_pedido ],
  197.                                        [ new TLabel('Entrega'),   $detail_entrega ],
  198.                                        [ new TLabel('Carga'),     $detail_carga 
  199.                                        );
  200.         $row->layout = ['col-sm-4''col-sm-4','col-sm-4' ];
  201.         
  202.         //$this->form->addFields( [new TLabel('Peso Medido')], [$detail_peso_medido] );                
  203.         //$this->form->addFields( [new TLabel('Itens Notas Fiscais Carga Id')], [$detail_itens_notas_fiscais_carga_id] );
  204.         $add TButton::create('add', [$this'onSaveDetail'], 'Register''fa:save');
  205.         $this->form->addFields( [], [$add] )->style 'background: whitesmoke; padding: 5px; margin: 1px;';
  206.         
  207.         $this->detail_list = new BootstrapDatagridWrapper(new TQuickGrid);
  208.         $this->detail_list->style "min-width: 700px; width:100%;margin-bottom: 10px";
  209.         $this->detail_list->setId('solicitacao_de_carga_list');
  210.         
  211.         // items
  212.         $this->detail_list->addQuickColumn('N.F''nota_fiscal''left'100);
  213.         $this->detail_list->addQuickColumn('Série''serie_nota_fiscal''left'100);
  214.         //$this->detail_list->addQuickColumn('Danfe', 'danfe', 'left', 100);
  215.         //$this->detail_list->addQuickColumn('Emissao', 'emissao', 'left', 100);
  216.         $this->detail_list->addQuickColumn('Valor''valor''left'100);
  217.         //$this->detail_list->addQuickColumn('Pedido', 'pedido', 'left', 100);
  218.         //$this->detail_list->addQuickColumn('Entrega', 'entrega', 'left', 100);
  219.         //$this->detail_list->addQuickColumn('Carga', 'carga', 'left', 100);
  220.         $this->detail_list->addQuickColumn('Volumes''volumes''left'100);
  221.         $this->detail_list->addQuickColumn('Peso''peso_informado''left'100);
  222.         //$this->detail_list->addQuickColumn('Peso Medido', 'peso_medido', 'left', 100);
  223.         $this->detail_list->addQuickColumn('Fator Cubagem''fator_cubagem''left'100);
  224.         //$this->detail_list->addQuickColumn('Comprimento', 'comprimento', 'left', 100);
  225.         //$this->detail_list->addQuickColumn('Largura', 'largura', 'left', 100);
  226.         //$this->detail_list->addQuickColumn('Altura', 'altura', 'left', 100);
  227.         $this->detail_list->addQuickColumn('Cubagem''cubagem''left'100);
  228.         $this->detail_list->addQuickColumn('Peso Taxado''peso_taxado''left'100);
  229.         //$this->detail_list->addQuickColumn('Itens Notas Fiscais Carga Id', 'itens_notas_fiscais_carga_id', 'left', 100);
  230.         // detail actions
  231.         $this->detail_list->addQuickAction'Edit',   new TDataGridAction([$this'onEditDetail']),   'id''fa:edit blue');
  232.         $this->detail_list->addQuickAction'Delete', new TDataGridAction([$this'onDeleteDetail']), 'id''fa:trash red');
  233.         $this->detail_list->createModel();
  234.         
  235.         $panel = new TPanelGroup;
  236.         $panel->add($this->detail_list);
  237.         $panel->getBody()->style 'overflow-x:auto';
  238.         $this->form->addContent( [$panel] );
  239.         
  240.         // Campos que apresentam o total da(s) nota(s)
  241.         $this->form->addContent( ['<h4>Valor total das  notas</h4><hr>'] );
  242.         $row $this->form->addFields( [ new TLabel('Total R$'),               $valor_rs_total],
  243.                                        [ new TLabel('Total de volume'),        $volume_total ],
  244.                                        [ new TLabel('Total de peso'),          $peso_total],
  245.                                        [ new TLabel('Cubagem'),                $cubagem_total ],
  246.                                        [ new TLabel('Peso cubado'),            $peso_cubado_total],
  247.                                        [ new TLabel('Peso taxado'),            $peso_taxado] );
  248.         $row->layout = ['col-sm-2''col-sm-2','col-sm-2''col-sm-2','col-sm-2''col-sm-2' ];
  249.           
  250.         // Segunda Aba
  251.         $this->form->appendPage('Remetente');       
  252.         $row $this->form->addFields( [ new TLabel('CNPJ'),                     $remetente_cnpj ],
  253.                                        [ new TLabel('Inscrição Estadual'),       $remetente_ie ],
  254.                                        [ new TLabel('Razão Social'),             $remetente_rz_social 
  255.                                        );
  256.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  257.         $row $this->form->addFields( [ new TLabel('CEP'),                      $remetente_cep ],
  258.                                        [ new TLabel('UF'),                       $remetente_uf ],
  259.                                        [ new TLabel('Cidade'),                   $remetente_cidade 
  260.                                        );
  261.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  262.         $row $this->form->addFields( [ new TLabel('Endereço'),                 $remetente_endereco ],
  263.                                        [ new TLabel('Número'),                   $remetente_numero 
  264.                                        );
  265.         $row->layout = ['col-sm-8''col-sm-4' ];
  266.         $row $this->form->addFields( [ new TLabel('Bairro'),                   $remetente_bairro],
  267.                                        [ new TLabel('Complemento'),              $remetente_complemento 
  268.                                        );
  269.         $row->layout = ['col-sm-4''col-sm-8' ];
  270.         $row $this->form->addFields( [ new TLabel('Telefone'),                 $remetente_telefone],
  271.                                        [ new TLabel('E-mail'),                   $remetente_email 
  272.                                        );
  273.         $row->layout = ['col-sm-4''col-sm-8' ];
  274.         // Terceira Aba
  275.         $this->form->appendPage('Destinatário');  
  276.         $row $this->form->addFields( [ new TLabel('CNPJ'),                     $destinatario_id], //$destinatario_cnpj ],
  277.                                        [ new TLabel('Inscrição Estadual'),       $destinatario_ie ],
  278.                                        [ new TLabel('Razão Social'),             $destinatario_rz_social 
  279.                                        );
  280.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  281.         $row $this->form->addFields( [ new TLabel('CEP'),                      $destinatario_cep ],
  282.                                        [ new TLabel('UF'),                       $destinatario_uf ],
  283.                                        [ new TLabel('Cidade'),                   $destinatario_cidade 
  284.                                        );
  285.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  286.         $row $this->form->addFields( [ new TLabel('Endereço'),                 $destinatario_endereco ],
  287.                                        [ new TLabel('Número'),                   $destinatario_numero 
  288.                                        );
  289.         $row->layout = ['col-sm-8''col-sm-4' ];
  290.         $row $this->form->addFields( [ new TLabel('Bairro'),                   $destinatario_bairro],
  291.                                        [ new TLabel('Complemento'),              $destinatario_completo 
  292.                                        );
  293.         $row->layout = ['col-sm-4''col-sm-8' ];
  294.         $row $this->form->addFields( [ new TLabel('Telefone'),                 $destinatario_telefone],
  295.                                        [ new TLabel('E-mail'),                   $destinatario_email 
  296.                                        );
  297.         $row->layout = ['col-sm-4''col-sm-8' ];
  298.         // Quarta Aba
  299.         $this->form->appendPage('Expedidor');  
  300.         $row $this->form->addFields( [ new TLabel('CNPJ'),                     $expedior_cnpj ],
  301.                                        [ new TLabel('Inscrição Estadual.'),      $expedior_ie ],
  302.                                        [ new TLabel('Razão Social'),             $expedior_rz_social 
  303.                                        );
  304.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  305.         $row $this->form->addFields( [ new TLabel('CEP'),                      $expedior_cep ],
  306.                                        [ new TLabel('UF'),                       $expedior_uf ],
  307.                                        [ new TLabel('Cidade'),                   $expedior_cidade 
  308.                                        );
  309.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  310.         $row $this->form->addFields( [ new TLabel('Endereço'),                 $expedior_endereco ],
  311.                                        [ new TLabel('Número'),                   $expedior_numero 
  312.                                        );
  313.         $row->layout = ['col-sm-8''col-sm-4' ];
  314.         $row $this->form->addFields( [ new TLabel('Bairro'),                   $expedior_bairro],
  315.                                        [ new TLabel('Complemento'),              $expedior_complemento
  316.                                        );
  317.         $row->layout = ['col-sm-4''col-sm-8' ];
  318.         $row $this->form->addFields( [ new TLabel('Telefone'),                 $expedior_telefone],
  319.                                        [ new TLabel('E-mail'),                   $expedior_email 
  320.                                        );
  321.         $row->layout = ['col-sm-4''col-sm-8' ];
  322.         
  323.         // Quinta Aba
  324.         $this->form->appendPage('Tomador');
  325.         //$this->form->appendPage('Expedidor');  
  326.         $row $this->form->addFields( [ new TLabel('CNPJ'),                     $tomador_cnpj ],
  327.                                        [ new TLabel('Inscrição Estadual.'),      $tomador_ie ],
  328.                                        [ new TLabel('Razão Social'),             $tomador_rz_social 
  329.                                        );
  330.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  331.         $row $this->form->addFields( [ new TLabel('CEP'),                      $tomador_cep ],
  332.                                        [ new TLabel('UF'),                       $tomador_uf ],
  333.                                        [ new TLabel('Cidade'),                   $tomador_cidade 
  334.                                        );
  335.         $row->layout = ['col-sm-3''col-sm-3','col-sm-6' ];
  336.         $row $this->form->addFields( [ new TLabel('Endereço'),                 $tomador_endereco ],
  337.                                        [ new TLabel('Número'),                   $tomador_numero 
  338.                                        );
  339.         $row->layout = ['col-sm-8''col-sm-4' ];
  340.         $row $this->form->addFields( [ new TLabel('Bairro'),                   $tomador_bairro],
  341.                                        [ new TLabel('Complemento'),              $tomador_complemento
  342.                                        );
  343.         $row->layout = ['col-sm-4''col-sm-8' ];
  344.         $row $this->form->addFields( [ new TLabel('Telefone'),                 $tomador_telefone],
  345.                                        [ new TLabel('E-mail'),                   $tomador_email 
  346.                                        );
  347.         $row->layout = ['col-sm-4''col-sm-8' ];
  348.         
  349.         $btn $this->form->addAction_t('Save'),  new TAction([$this'onSave']), 'fa:save');
  350.         $btn->class 'btn btn-sm btn-primary';
  351.         $this->form->addAction_t('Clear'), new TAction([$this'onClear']), 'fa:eraser red');
  352.         
  353.         // create the page container
  354.         $container = new TVBox;
  355.         $container->style 'width: 90%';
  356.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  357.         $container->add($this->form);
  358.         parent::add($container);
  359.     }
  360.     
  361.     
  362.     /**
  363.      * Clear form
  364.      * @param $param URL parameters
  365.      */
  366.     public function onClear($param)
  367.     {
  368.         $this->form->clear(TRUE);
  369.         TSession::setValue(__CLASS__.'_items', array());
  370.         $this->onReload$param );
  371.     }
  372.     
  373.     /**
  374.      * Busca os dados da loja
  375.      */
  376.     static function buscaDadosLoja$params )
  377.     {
  378.         if( !empty($params['loja_id']) )
  379.         {
  380.             try
  381.             {
  382.                 TTransaction::open('banco');
  383.                              // MODEL
  384.                 $loja      = new loja($params['loja_id']);
  385.                 $campos_model = new StdClass;
  386.                 $campos_model ->servico                $loja->razao_social
  387.                 $campos_model ->uf_origem              $loja->uf;
  388.                 $campos_model ->cidade_origem          $loja->cidade;
  389.                 // Remetente, expedidor e toamador
  390.                 $campos_model ->remetente_rz_social    $loja->razao_social// campo do form  = model->campo na model
  391.                 $campos_model ->expedior_rz_social     $loja->razao_social;
  392.                 $campos_model ->tomador_rz_social      $loja->razao_social;
  393.                 $campos_model ->remetente_cnpj         $loja->cnpj;
  394.                 $campos_model ->expedior_cnpj          $loja->cnpj;
  395.                 $campos_model ->tomador_cnpj           $loja->cnpj;
  396.                 $campos_model ->remetente_ie           $loja->ie;
  397.                 $campos_model ->expedior_ie            $loja->ie;   
  398.                 $campos_model ->tomador_ie             $loja->ie;
  399.                 $campos_model ->remetente_cep          $loja->cep;
  400.                 $campos_model ->expedior_cep           $loja->cep;
  401.                 $campos_model ->tomador_cep            $loja->cep;
  402.                 $campos_model ->remetente_uf           $loja->uf;
  403.                 $campos_model ->expedior_uf            $loja->uf;
  404.                 $campos_model ->tomador_uf             $loja->uf;
  405.                 $campos_model ->remetente_cidade       $loja->cidade;
  406.                 $campos_model ->expedior_cidade        $loja->cidade;
  407.                 $campos_model ->tomador_cidade         $loja->cidade;
  408.                 $campos_model ->remetente_endereco     $loja->endereco;
  409.                 $campos_model ->expedior_endereco      $loja->endereco;
  410.                 $campos_model ->tomador_endereco       $loja->endereco;
  411.                 $campos_model ->remetente_numero       $loja->numero;
  412.                 $campos_model ->expedior_numero        $loja->numero;
  413.                 $campos_model ->tomador_numero         $loja->numero;
  414.                 $campos_model ->remetente_bairro       $loja->bairro;
  415.                 $campos_model ->expedior_bairro        $loja->bairro;
  416.                 $campos_model ->tomador_bairro         $loja->bairro;
  417.                 $campos_model ->remetente_complemento  $loja->complemento;
  418.                 $campos_model ->expedior_complemento   $loja->complemento;
  419.                 $campos_model ->tomador_complemento    $loja->complemento;
  420.                 $campos_model ->remetente_telefone     $loja->telefone;
  421.                 $campos_model ->expedior_telefone      $loja->telefone;
  422.                 $campos_model ->tomador_telefone       $loja->telefone;
  423.                 $campos_model ->remetente_email        $loja->email;
  424.                 $campos_model ->expedior_email         $loja->email;
  425.                 $campos_model ->tomador_email          $loja->email;
  426.        
  427.                 TForm::sendData('form_solicitacao_de_carga'$campos_model);
  428.                 TTransaction::close();
  429.             }
  430.             catch (Exception $e// in case of exception
  431.             {
  432.                 new TMessage('error'$e->getMessage());
  433.                 TTransaction::rollback();
  434.             }
  435.         }
  436.     }
  437.     
  438.     public static function onChangeAction($param)
  439.     {
  440.         try
  441.         {           
  442.             $object = new StdClass;           
  443.             $object->iduf $param['cliente_id'];
  444.             $clienteloja = new Cliente;
  445.             $cs $clienteloja->loja($object->id);
  446.               
  447.             $item = array();
  448.             foreach($cs as $c)
  449.             {
  450.                 $item[$clienteloja] = $c['loja_id'];
  451.             }
  452.                            
  453.             TCombo::reload('form_solicitacao_de_carga''loja_id'$item);
  454.         }
  455.         catch (Exception $e)
  456.         {
  457.             new TMessage('error',$e->getMessage());
  458.         }
  459.         
  460.     }
  461.     
  462.     /**
  463.      * Save an item from form to session list
  464.      * @param $param URL parameters
  465.      */
  466.     public function onSaveDetail$param )
  467.     {
  468.         try
  469.         {
  470.             TTransaction::open('banco');
  471.             $data $this->form->getData();
  472.             
  473.             /** validation sample
  474.             if (empty($data->fieldX))
  475.             {
  476.                 throw new Exception('The field fieldX is required');
  477.             }
  478.             **/
  479.             
  480.             $items TSession::getValue(__CLASS__.'_items');
  481.             $key = empty($data->detail_id) ? 'X'.mt_rand(10000000001999999999) : $data->detail_id;
  482.             
  483.             $items$key ] = array();
  484.             $items$key ]['id'] = $key;
  485.             $items$key ]['nota_fiscal'] = $data->detail_nota_fiscal;
  486.             $items$key ]['serie_nota_fiscal'] = $data->detail_serie_nota_fiscal;
  487.             $items$key ]['danfe'] = $data->detail_danfe;
  488.             $items$key ]['emissao'] = $data->detail_emissao;
  489.             $items$key ]['valor'] = $data->detail_valor;
  490.             $items$key ]['pedido'] = $data->detail_pedido;
  491.             $items$key ]['entrega'] = $data->detail_entrega;
  492.             $items$key ]['carga'] = $data->detail_carga;
  493.             $items$key ]['volumes'] = $data->detail_volumes;
  494.             $items$key ]['peso_informado'] = $data->detail_peso_informado;
  495.             //$items[ $key ]['peso_medido'] = $data->detail_peso_medido;
  496.             $items$key ]['fator_cubagem'] = $data->detail_fator_cubagem;
  497.             $items$key ]['comprimento'] = $data->detail_comprimento;
  498.             $items$key ]['largura'] = $data->detail_largura;
  499.             $items$key ]['altura'] = $data->detail_altura;
  500.             $items$key ]['cubagem'] = $data->detail_cubagem;
  501.             $items$key ]['peso_taxado'] = $data->detail_peso_taxado;
  502.             //$items[ $key ]['itens_notas_fiscais_carga_id'] = $data->detail_itens_notas_fiscais_carga_id;
  503.             
  504.             TSession::setValue(__CLASS__.'_items'$items);
  505.             
  506.             // clear detail form fields
  507.             $data->detail_id '';
  508.             $data->detail_nota_fiscal '';
  509.             $data->detail_serie_nota_fiscal '';
  510.             $data->detail_danfe '';
  511.             $data->detail_emissao '';
  512.             $data->detail_valor '';
  513.             $data->detail_pedido '';
  514.             $data->detail_entrega '';
  515.             $data->detail_carga '';
  516.             $data->detail_volumes '';
  517.             $data->detail_peso_informado '';
  518.             //$data->detail_peso_medido = '';
  519.             $data->detail_fator_cubagem '';
  520.             $data->detail_comprimento '';
  521.             $data->detail_largura '';
  522.             $data->detail_altura '';
  523.             $data->detail_cubagem '';
  524.             $data->detail_peso_taxado '';
  525.             //$data->detail_itens_notas_fiscais_carga_id = '';
  526.             
  527.             TTransaction::close();
  528.             $this->form->setData($data);
  529.             
  530.             $this->onReload$param ); // reload the items
  531.         }
  532.         catch (Exception $e)
  533.         {
  534.             $this->form->setData$this->form->getData());
  535.             new TMessage('error'$e->getMessage());
  536.         }
  537.     }
  538.     
  539.     /**
  540.      * Load an item from session list to detail form
  541.      * @param $param URL parameters
  542.      */
  543.     public static function onEditDetail$param )
  544.     {
  545.         // read session items
  546.         $items TSession::getValue(__CLASS__.'_items');
  547.         
  548.         // get the session item
  549.         $item $items$param['key'] ];
  550.         
  551.         $data = new stdClass;
  552.         $data->detail_id $item['id'];
  553.         $data->detail_nota_fiscal $item['nota_fiscal'];
  554.         $data->detail_serie_nota_fiscal $item['serie_nota_fiscal'];
  555.         $data->detail_danfe $item['danfe'];
  556.         $data->detail_emissao $item['emissao'];
  557.         $data->detail_valor $item['valor'];
  558.         $data->detail_pedido $item['pedido'];
  559.         $data->detail_entrega $item['entrega'];
  560.         $data->detail_carga $item['carga'];
  561.         $data->detail_volumes $item['volumes'];
  562.         $data->detail_peso_informado $item['peso_informado'];
  563.         //$data->detail_peso_medido = $item['peso_medido'];
  564.         $data->detail_fator_cubagem $item['fator_cubagem'];
  565.         $data->detail_comprimento $item['comprimento'];
  566.         $data->detail_largura $item['largura'];
  567.         $data->detail_altura $item['altura'];
  568.         $data->detail_cubagem $item['cubagem'];
  569.         $data->detail_peso_taxado $item['peso_taxado'];
  570.         //$data->detail_itens_notas_fiscais_carga_id = $item['itens_notas_fiscais_carga_id'];
  571.         
  572.         // fill detail fields
  573.         TForm::sendData'form_solicitacao_de_carga'$data );
  574.     }
  575.     
  576.     /**
  577.      * Delete an item from session list
  578.      * @param $param URL parameters
  579.      */
  580.     public static function onDeleteDetail$param )
  581.     {
  582.         // reset items
  583.         $data = new stdClass;
  584.             $data->detail_nota_fiscal '';
  585.             $data->detail_serie_nota_fiscal '';
  586.             $data->detail_danfe '';
  587.             $data->detail_emissao '';
  588.             $data->detail_valor '';
  589.             $data->detail_pedido '';
  590.             $data->detail_entrega '';
  591.             $data->detail_carga '';
  592.             $data->detail_volumes '';
  593.             $data->detail_peso_informado '';
  594.            // $data->detail_peso_medido = '';
  595.             $data->detail_fator_cubagem '';
  596.             $data->detail_comprimento '';
  597.             $data->detail_largura '';
  598.             $data->detail_altura '';
  599.             $data->detail_cubagem '';
  600.             $data->detail_peso_taxado '';
  601.             //$data->detail_itens_notas_fiscais_carga_id = '';
  602.         
  603.         // clear form data
  604.         TForm::sendData('form_solicitacao_de_carga'$data );
  605.         
  606.         // read session items
  607.         $items TSession::getValue(__CLASS__.'_items');
  608.         
  609.         // get detail id
  610.         $detail_id $param['key'];
  611.         
  612.         // delete the item from session
  613.         unset($items$detail_id ] );
  614.         
  615.         // rewrite session items
  616.         TSession::setValue(__CLASS__.'_items'$items);
  617.         
  618.         // delete item from screen
  619.         TScript::create("ttable_remove_row_by_id('solicitacao_de_carga_list', '{$detail_id}')");
  620.     }
  621.     
  622.     /**
  623.      * Load the items list from session
  624.      * @param $param URL parameters
  625.      */
  626.     public function onReload($param)
  627.     {
  628.         // read session items
  629.         $items TSession::getValue(__CLASS__.'_items');
  630.         
  631.         $this->detail_list->clear(); // clear detail list
  632.         
  633.         if ($items)
  634.         {
  635.             foreach ($items as $list_item)
  636.             {
  637.                 $item = (object) $list_item;
  638.                 
  639.                 $row $this->detail_list->addItem$item );
  640.                 $row->id $list_item['id'];
  641.             }
  642.         }
  643.         
  644.         $this->loaded TRUE;
  645.     }
  646.     
  647.     /**
  648.      * Load Master/Detail data from database to form/session
  649.      */
  650.     public function onEdit($param)
  651.     {
  652.         try
  653.         {
  654.             TTransaction::open('banco');
  655.             
  656.             if (isset($param['key']))
  657.             {
  658.                 $key $param['key'];
  659.                 
  660.                 $object = new solicitacao_de_carga($key);
  661.                 $items  notas_fiscais_carga::where('solicitacao_de_carga_id''='$key)->load();
  662.                 
  663.                 $session_items = array();
  664.                 foreach( $items as $item )
  665.                 {
  666.                     $item_key $item->id;
  667.                     $session_items[$item_key] = $item->toArray();
  668.                     $session_items[$item_key]['id'] = $item->id;
  669.                     $session_items[$item_key]['nota_fiscal'] = $item->nota_fiscal;
  670.                     $session_items[$item_key]['serie_nota_fiscal'] = $item->serie_nota_fiscal;
  671.                     $session_items[$item_key]['danfe'] = $item->danfe;
  672.                     $session_items[$item_key]['emissao'] = $item->emissao;
  673.                     $session_items[$item_key]['valor'] = $item->valor;
  674.                     $session_items[$item_key]['pedido'] = $item->pedido;
  675.                     $session_items[$item_key]['entrega'] = $item->entrega;
  676.                     $session_items[$item_key]['carga'] = $item->carga;
  677.                     $session_items[$item_key]['volumes'] = $item->volumes;
  678.                     $session_items[$item_key]['peso_informado'] = $item->peso_informado;
  679.                     //$session_items[$item_key]['peso_medido'] = $item->peso_medido;
  680.                     $session_items[$item_key]['fator_cubagem'] = $item->fator_cubagem;
  681.                     $session_items[$item_key]['comprimento'] = $item->comprimento;
  682.                     $session_items[$item_key]['largura'] = $item->largura;
  683.                     $session_items[$item_key]['altura'] = $item->altura;
  684.                     $session_items[$item_key]['cubagem'] = $item->cubagem;
  685.                     $session_items[$item_key]['peso_taxado'] = $item->peso_taxado;
  686.                     //$session_items[$item_key]['itens_notas_fiscais_carga_id'] = $item->itens_notas_fiscais_carga_id;
  687.                 }
  688.                 TSession::setValue(__CLASS__.'_items'$session_items);
  689.                 
  690.                 $this->form->setData($object); // fill the form with the active record data
  691.                 $this->onReload$param ); // reload items list
  692.                 TTransaction::close(); // close transaction
  693.             }
  694.             else
  695.             {
  696.                 $this->form->clear(TRUE);
  697.                 TSession::setValue(__CLASS__.'_items'null);
  698.                 $this->onReload$param );
  699.             }
  700.         }
  701.         catch (Exception $e// in case of exception
  702.         {
  703.             new TMessage('error'$e->getMessage());
  704.             TTransaction::rollback();
  705.         }
  706.     }
  707.     
  708.     /**
  709.      * Save the Master/Detail data from form/session to database
  710.      */
  711.     public function onSave()
  712.     {
  713.         try
  714.         {
  715.             // open a transaction with database
  716.             TTransaction::open('banco');
  717.             
  718.             $data $this->form->getData();
  719.             $master = new solicitacao_de_carga;
  720.             $master->fromArray( (array) $data);
  721.             $this->form->validate(); // form validation
  722.             
  723.             $master->store(); // save master object
  724.             // delete details
  725.             $old_items notas_fiscais_carga::where('solicitacao_de_carga_id''='$master->id)->load();
  726.             
  727.             $keep_items = array();
  728.             
  729.             // get session items
  730.             $items TSession::getValue(__CLASS__.'_items');
  731.             
  732.             if( $items )
  733.             {
  734.                 foreach( $items as $item )
  735.                 {
  736.                     if (substr($item['id'],0,1) == 'X' // new record
  737.                     {
  738.                         $detail = new notas_fiscais_carga;
  739.                     }
  740.                     else
  741.                     {
  742.                         $detail notas_fiscais_carga::find($item['id']);
  743.                     }
  744.                     $detail->nota_fiscal  $item['nota_fiscal'];
  745.                     $detail->serie_nota_fiscal  $item['serie_nota_fiscal'];
  746.                     $detail->danfe  $item['danfe'];
  747.                     $detail->emissao  $item['emissao'];
  748.                     $detail->valor  $item['valor'];
  749.                     $detail->pedido  $item['pedido'];
  750.                     $detail->entrega  $item['entrega'];
  751.                     $detail->carga  $item['carga'];
  752.                     $detail->volumes  $item['volumes'];
  753.                     $detail->peso_informado  $item['peso_informado'];
  754.                     //$detail->peso_medido  = $item['peso_medido'];
  755.                     $detail->fator_cubagem  $item['fator_cubagem'];
  756.                     $detail->comprimento  $item['comprimento'];
  757.                     $detail->largura  $item['largura'];
  758.                     $detail->altura  $item['altura'];
  759.                     $detail->cubagem  $item['cubagem'];
  760.                     $detail->peso_taxado  $item['peso_taxado'];
  761.                     //$detail->itens_notas_fiscais_carga_id  = $item['itens_notas_fiscais_carga_id'];
  762.                     $detail->solicitacao_de_carga_id $master->id;
  763.                     $detail->store();
  764.                     
  765.                     $keep_items[] = $detail->id;
  766.                 }
  767.             }
  768.             
  769.             if ($old_items)
  770.             {
  771.                 foreach ($old_items as $old_item)
  772.                 {
  773.                     if (!in_array$old_item->id$keep_items))
  774.                     {
  775.                         $old_item->delete();
  776.                     }
  777.                 }
  778.             }
  779.             TTransaction::close(); // close the transaction
  780.             
  781.             // reload form and session items
  782.             $this->onEdit(array('key'=>$master->id));
  783.             
  784.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  785.         }
  786.         catch (Exception $e// in case of exception
  787.         {
  788.             new TMessage('error'$e->getMessage());
  789.             $this->form->setData$this->form->getData() ); // keep form data
  790.             TTransaction::rollback();
  791.         }
  792.     }
  793.     
  794.     /**
  795.      * Show the page
  796.      */
  797.     public function show()
  798.     {
  799.         // check if the datagrid is already loaded
  800.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  801.         {
  802.             $this->onReloadfunc_get_arg(0) );
  803.         }
  804.         parent::show();
  805.     }
  806. }

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


NR

  1. <?php
  2. public static function onChangeAction($param)
  3.     {
  4.         try
  5.         {           
  6.             $cliente = new Cliente($param['cliente_id']); //primeiro passo é instanciar o cliente através do seu id($param['id'])
  7.             $lojas $cliente->getLojas(); // se vc criou a composicao entre cliente e loja, deve existir a função getLojas no model Cliente
  8.               
  9.             $item = array();
  10.             foreach($lojas as $loja)
  11.             {
  12.                 $item[$loja->id] = $loja->razao_social;
  13.             }
  14.                            
  15.             TCombo::reload('form_solicitacao_de_carga''loja_id'$item);
  16.         }
  17.         catch (Exception $e)
  18.         {
  19.             new TMessage('error',$e->getMessage());
  20.         }
  21.         
  22.     }
  23. ?>
RF

Boa noite, testei aqui mas deu um erro, não entendi o que quer dizer.

Sem transação ativa com a base de dados:AdiantiDatabaseTRecord::load cliente
NR

Antes de qualquer operação com consulta a banco de dados é preciso abrir uma transação:
  1. <?php
  2. TTransaction::open('nome_conexao');
  3. ...
  4. $cliente = new Cliente($param['cliente_id']);
  5. ...
  6. TTransaction::close();
  7. ?>
RF

Bom dia, Nataniel.
Muito obrigado, funcionou, estou pulando de alegria, rssss.

As coisas estão caminhando bem no meu projeto, tenho ainda algumas dúvidas sobre outros pontos nesse mesmo formulário, mas serão tópicos para outros posts no forum. por enquanto é isso. Valeuuuuuu.

public static function onChangeAction($params)
{
try
{
TTransaction::open('banco');

$cliente_loja = new cliente_loja($params['cliente_id']);
//primeiro passo é instanciar o cliente através do seu id($param['id'])
$lojas = $cliente_loja->getLojas();
// se vc criou a composicao entre cliente e loja, deve existir a função getLojas no model Cliente

$item = array();
foreach($lojas as $loja)
{
$item[$loja->id] = $loja->razao_social;
}

TCombo::reload('form_solicitacao_de_carga', 'loja_id', $item);

TTransaction::close();
}
catch (Exception $e)
{
new TMessage('error',$e->getMessage());
}

}