Bloqueio de campos Boa tarde... Tenho o formulário de cotação no meu projeto e gostaria que alguns campos ficassem desabilitados (setEditable(false)) conforme o valor dentro do campo Status, por exemplo: Se o registro selecionado tiver com Status = Aprovado, os campos de calculo do frete não podem estar habilitados, pois o usuário poderia alterar o valor de uma cotação que já foi aprovada. Segue anexo tela...
RF
Bloqueio de campos  
Fechado
Boa tarde...
Tenho o formulário de cotação no meu projeto e gostaria que alguns campos ficassem desabilitados (setEditable(false)) conforme o valor dentro do campo Status, por exemplo: Se o registro selecionado tiver com Status = Aprovado, os campos de calculo do frete não podem estar habilitados, pois o usuário poderia alterar o valor de uma cotação que já foi aprovada.
Segue anexo tela e código do formulário:
 
  1. <?php
  2. class CotacaoForm extends TPage
  3. {
  4. private $form; // form
  5. function __construct()
  6. {
  7. parent::__construct();
  8. // creates the form
  9. $this->form = new TForm('form_cotacao');
  10. $this->form->class = 'tform';
  11. // cria as tabelas
  12. $table_data = new TTable;
  13. $table_destino = new TTable;
  14. $table_carga = new TTable;
  15. $table_frete = new TTable;
  16. $table_diversos = new TTable;
  17. //Tamanho do notebook
  18. $notebook = new TNotebook(500, 250);
  19. // adiciona as abas do notebook
  20. $this->form->add($notebook);
  21. // Adiciona o nome das abas do notebook
  22. $notebook->appendPage('Solicitante', $table_data);
  23. $notebook->appendPage('Destino', $table_destino);
  24. $notebook->appendPage('Carga',$table_carga);
  25. $notebook->appendPage('Frete', $table_frete);
  26. $notebook->appendPage('Diversos',$table_diversos);
  27. // campos do formulário
  28. 2356 = new TEntry('id');
  29. $customer_cnpj = new TSeekButton('customer_cnpj');
  30. $status = new TCombo('status');
  31. $observacoes = new TText('observacoes');
  32. $solicitante = new TEntry('solicitante');
  33. $address = new TEntry('address');
  34. $numero = new TEntry('numero');
  35. $complemento = new TEntry('complemento');
  36. $bairro = new TEntry('bairro');
  37. $cep = new TEntry('cep');
  38. $uf = new TEntry('uf');
  39. $municipio = new TEntry('municipio');
  40. $contato = new TEntry('contato');
  41. $telefone = new TEntry('telefone');
  42. $email = new TEntry('email');
  43. $empresa_col = new TEntry('empresa_col');
  44. $customercol_cnpj = new TSeekButton('customercol_cnpj');
  45. $address_col = new TEntry('address_col');
  46. $numero_col = new TEntry('numero_col');
  47. $complemento_col = new TEntry('complemento_col');
  48. $bairro_col = new TEntry('bairro_col');
  49. $cep_col = new TEntry('cep_col');
  50. $uf_col = new TEntry('uf_col');
  51. $municipio_col = new TEntry('municipio_col');
  52. $produto_id = new TDBCombo('produto_id' , 'samples', 'produto' , 'id', 'name');//busca o produto
  53. $grnatureza_id = new TDBCombo('grnatureza_id', 'samples', 'Grunatureza', 'id', 'name');//busca a natureza
  54. $embalagem_id = new TDBCombo('embalagem_id' , 'samples', 'Embalagem' , 'id', 'name');//busca a embalagem
  55. $distancia = new TEntry('distancia');
  56. $prod_quimico = new TCombo('prod_quimico');
  57. $onu = new TEntry('onu');
  58. $volume = new TEntry('volume');
  59. $peso = new TEntry('peso');
  60. $comprimento = new TEntry('comprimento');
  61. $largura = new TEntry('largura');
  62. $altura = new TEntry('altura');
  63. //$cubagem = new TEntry('cubagem');
  64. //$pesocubado = new TEntry('pesocubado');
  65. $peso_cubico = new TEntry('peso_cubico');
  66. $peso_cubado = new TEntry('peso_cubado');
  67. $valor_nf = new TEntry('valor_nf');
  68. $comentarios = new TText('comentarios');
  69. $fretepeso = new TEntry('fretepeso');
  70. $fretevalor = new TEntry('fretevalor');
  71. $coleta = new TEntry('coleta');
  72. $entrega = new TEntry('entrega');
  73. $data_cotacao = new TDate('data_cotacao');
  74. $outros = new TEntry('outros');
  75. $cat = new TEntry('cat');
  76. $sec_cat = new TEntry('sec_cat');
  77. $gris = new TEntry('gris');
  78. $txdespacho = new TEntry('txdespacho');
  79. $pedagio = new TEntry('pedagio');
  80. $perc_icms = new TEntry('perc_icms');
  81. $base_icms = new TEntry('base_icms');
  82. $valor_icms = new TEntry('valor_icms');
  83. $frete_total = new TEntry('frete_total');
  84. $alteracao = new TEntry('alteracao');
  85. // Tamanho dos campos e desabilitação para editar
  86. 2356 ->setSize(150);
  87. 2356 ->setEditable(false);
  88. $status ->setSize(150);
  89. $data_cotacao ->setSize(133);
  90. //Dados do Solicitante
  91. $solicitante ->setSize(220);
  92. $solicitante ->style = "text-transform: uppercase";
  93. $customer_cnpj ->setSize(130);
  94. $address ->setSize(220);
  95. $address ->style = "text-transform: uppercase";
  96. $municipio ->setSize(220);
  97. $municipio ->style = "text-transform: uppercase";
  98. $numero ->setSize(75);
  99. $complemento ->setSize(220);
  100. $complemento ->style = "text-transform: uppercase";
  101. $bairro ->setSize(173);
  102. $bairro ->style = "text-transform: uppercase";
  103. $cep ->setSize(122);
  104. $uf ->setSize(50);
  105. $uf ->style = "text-transform: uppercase";
  106. $contato ->setSize(220);
  107. $contato ->style = "text-transform: uppercase";
  108. $telefone ->setSize(155);
  109. $email ->setSize(220);
  110. $email ->style = "text-transform: lowercase";
  111. //Dados do destino
  112. $empresa_col ->setSize(220);
  113. $customercol_cnpj ->setSize(130);
  114. $address_col ->setSize(220);
  115. $municipio_col ->setSize(220);
  116. $numero_col ->setSize(75);
  117. $complemento_col ->setSize(220);
  118. $bairro_col ->setSize(173);
  119. $cep_col ->setSize(122);
  120. $uf_col ->setSize(50);
  121. //Dados do produto
  122. $produto_id ->setSize(350);
  123. $grnatureza_id ->setSize(350);
  124. $embalagem_id ->setSize(220);
  125. $distancia ->setSize(90);
  126. $prod_quimico ->setSize(144);
  127. $onu ->setSize(145);
  128. $observacoes ->setSize(350);
  129. //Dados da carga
  130. $volume ->setSize(144);
  131. $peso ->setSize(144);
  132. $peso_cubico ->setSize(144);
  133. $peso_cubado ->setSize(100);
  134. $comprimento ->setSize(44);
  135. $largura ->setSize(44);
  136. $altura ->setSize(44);
  137. $valor_nf ->setSize(144);
  138. //Dados do frete
  139. $fretepeso ->setSize(150);
  140. $fretevalor ->setSize(150);
  141. $coleta ->setSize(150);
  142. $entrega ->setSize(150);
  143. $txdespacho ->setSize(150);
  144. $outros ->setSize(150);
  145. $cat ->setSize(150);
  146. $sec_cat ->setSize(150);
  147. $gris ->setSize(150);
  148. $pedagio ->setSize(150);
  149. $perc_icms ->setSize(50);
  150. $base_icms ->setSize(145);
  151. $valor_icms ->setSize(95);
  152. $frete_total ->setSize(150);
  153. //Demais informações
  154. $alteracao ->setSize(150);
  155. $comentarios ->setSize(350);
  156. //Mascaras de entrada, campos obrigatórios, validações e campos obrigatórios
  157. $fretepeso ->setNumericMask(2, ',', '.',true);
  158. $fretevalor ->setNumericMask(2, ',', '.',true);
  159. $coleta ->setNumericMask(2, ',', '.',true);
  160. $entrega ->setNumericMask(2, ',', '.',true);
  161. $txdespacho ->setNumericMask(2, ',', '.',true);
  162. $outros ->setNumericMask(2, ',', '.',true);
  163. $cat ->setNumericMask(2, ',', '.',true);
  164. $sec_cat ->setNumericMask(2, ',', '.',true);
  165. $gris ->setNumericMask(2, ',', '.',true);
  166. $pedagio ->setNumericMask(2, ',', '.',true);
  167. $valor_icms ->setNumericMask(2, ',', '.',true);
  168. $frete_total ->setNumericMask(2, ',', '.',true);
  169. $valor_nf ->setNumericMask(2, ',', '.',true);
  170. $base_icms ->setNumericMask(2, ',', '.',true);
  171. $perc_icms ->setNumericMask(2, ',', '.',true);
  172. $peso_cubico ->setNumericMask(2, ',','.' ,true);
  173. $peso_cubado ->setNumericMask(2, ',','.' ,true);
  174. $comprimento ->setNumericMask(2, ',','.' ,true);
  175. $largura ->setNumericMask(2, ',','.' ,true);
  176. $altura ->setNumericMask(2, ',','.' ,true);
  177. $data_cotacao ->setMask('dd/mm/yyyy');
  178. $cep ->setMask('99999-999');
  179. $telefone ->setMask('(99)9999-9999');
  180. $cep_col ->setMask('99999-999');
  181. $email ->addValidation('E-mail',new TEmailValidator);
  182. //Ação dos campos ao perder o foco
  183. $altura ->setExitAction(new TAction(array($this, 'onCubagem' )));
  184. $peso_cubico ->setExitAction(new TAction(array($this, 'onPesocubado')));
  185. //Objeto para criar o campo de busca de solicitante e destinatário por cnpj ou rz social
  186. $obj = new Remetente; //
  187. $customer_cnpj->setAction(new TAction(array($obj, 'onReload')));
  188. $obj2 = new Destinatario; //
  189. $customercol_cnpj->setAction(new TAction(array($obj2, 'onReload')));
  190. //Itens do Status
  191. $itemStatus= array();
  192. $itemStatus['Lançado'] = 'Lançado';
  193. $itemStatus['Impresso'] = 'Impresso';
  194. $itemStatus['Aprovado'] = 'Aprovado';
  195. $itemStatus['Reprovado'] = 'Reprovado';
  196. $status->setValue('Lançado');
  197. $status->addItems($itemStatus);
  198. //Itens do químico
  199. $itemQ= array();
  200. $itemQ['Não'] = 'Não';
  201. $itemQ['Sim'] = 'Sim';
  202. $prod_quimico->setValue('Não');
  203. $prod_quimico->addItems($itemQ);
  204. //Valores padrões para os campos de calculo do frete, isso evita o erro da linha 79
  205. $fretepeso ->setValue('0');
  206. $fretevalor ->setValue('0');
  207. $coleta ->setValue('0');
  208. $entrega ->setValue('0');
  209. $txdespacho ->setValue('0');
  210. $outros ->setValue('0');
  211. $cat ->setValue('0');
  212. $sec_cat ->setValue('0');
  213. $gris ->setValue('0');
  214. $pedagio ->setValue('0');
  215. $valor_icms ->setValue('0');
  216. $frete_total ->setValue('0');
  217. $valor_nf ->setValue('0');
  218. $base_icms ->setValue('0');
  219. $comprimento ->setValue('0');
  220. $largura ->setValue('0');
  221. $altura ->setValue('0');
  222. $peso_cubico ->setValue('0');
  223. $peso_cubado ->setValue('0');
  224. $perc_icms ->setValue('12');
  225. $status ->setValue('Lançado');
  226. $alteracao ->setValue(date('d-m-Y / H:i'));
  227. $alteracao ->setEditable(FALSE);
  228. $base_icms ->setEditable(FALSE);
  229. $valor_icms ->setEditable(FALSE);
  230. // Campos da Aba Solicitante
  231. $table_data->addRowSet(new TLabel(''));
  232. $table_data->addRowSet(new TLabel('Número:') ,array(2356, new TLabel('Data de solicitação :'),$data_cotacao));
  233. $table_data->addRowSet(new TLabel('CNPJ:') ,array($customer_cnpj,new TLabel('Rz Social:'),$solicitante));
  234. $table_data->addRowSet(new TLabel('Endereço:') ,array($address, new TLabel('Número do endereço:'),$numero));
  235. $table_data->addRowSet(new TLabel('Complemento:'),array($complemento));
  236. $table_data->addRowSet(new TLabel('Cidade:') ,array($municipio, new TLabel('Bairro:'),$bairro));
  237. $table_data->addRowSet(new TLabel('Estado:') ,array($uf, new TLabel('CEP:'),$cep));
  238. $table_data->addRowSet(new TLabel('Contato:') ,array($contato, new TLabel('Telefone :'),$telefone));
  239. $table_data->addRowSet(new TLabel('E-mail:') ,$email);
  240. // Campos da Aba Destino
  241. $table_destino->addRowSet(new TLabel(''));
  242. $table_destino->addRowSet(new TLabel('CNPJ:') ,array($customercol_cnpj, new TLabel('Rz Social:'),$empresa_col));
  243. $table_destino->addRowSet(new TLabel('Endereço:') ,array($address_col, new TLabel('Número do endereço:'),$numero_col));
  244. $table_destino->addRowSet(new TLabel('Complemento:'),array($complemento_col));
  245. $table_destino->addRowSet(new TLabel('Cidade:') ,array($municipio_col, new TLabel('Bairro:'),$bairro_col));
  246. $table_destino->addRowSet(new TLabel('Estado:') ,array($uf_col, new TLabel('CEP:'),$cep_col));
  247. // Campos da Aba carga
  248. $table_carga->addRowSet(new TLabel(''));
  249. $table_carga->addRowSet(new TLabel('Produto:') ,array($produto_id));
  250. $table_carga->addRowSet(new TLabel('Grupo:') ,array($grnatureza_id) );
  251. $table_carga->addRowSet(new TLabel('Embalagem:'),array($embalagem_id, new TLabel('KM:'),$distancia));
  252. $table_carga->addRowSet(new TLabel('Químico?') ,array($prod_quimico, new TLabel('O.n.U :'),$onu));
  253. $table_carga->addRowSet(new TLabel('Volume:') ,array($volume, new TLabel('PESO :') ,$peso));
  254. $table_carga->addRowSet(new TLabel('Vlr NF-e:') ,array($valor_nf, new TLabel('C') ,$comprimento,new TLabel('L'),$largura,new TLabel('A'),$altura));
  255. $table_carga->addRowSet(new TLabel('Cubagem:') ,array($peso_cubico, new TLabel('Peso Cubado:') ,$peso_cubado));
  256. $table_carga->addRowSet(new TLabel('A carga é:'),array($observacoes));
  257. //Campos da Aba Frete
  258. $table_frete->addRowSet(new TLabel(''));
  259. $table_frete->addRowSet(new TLabel('Frete Peso:'),array($fretepeso, new TLabel('Frete Valor :') ,$fretevalor));
  260. $table_frete->addRowSet(new TLabel('Entrega:') ,array($entrega, new TLabel('T.Despacho:') ,$txdespacho));
  261. $table_frete->addRowSet(new TLabel('Coleta:') ,array($coleta, new TLabel('Outra taxa .:') ,$outros));
  262. $table_frete->addRowSet(new TLabel('C.A.T:') ,array($cat, new TLabel('Vlr. Pedágio:') ,$pedagio));
  263. $table_frete->addRowSet(new TLabel('GRIS:') ,array($gris, new TLabel('S.E.C / CAT.:') ,$sec_cat));
  264. $table_frete->addRowSet(new TLabel(''));
  265. $table_frete->addRowSet(new TLabel('ICMS %') ,array($perc_icms, new TLabel('Base:'),$base_icms, new TLabel('ICMS:'),$valor_icms));
  266. $table_frete->addRowSet(new TLabel('Total') ,array($frete_total) );
  267. // Campos da Aba Diversos
  268. $table_diversos->addRowSet(new TLabel(''));
  269. $table_diversos->addRowSet(new TLabel('Status:') ,array($status));
  270. $table_diversos->addRowSet(new TLabel('Comentário:') ,array($comentarios));
  271. $table_diversos->addRowSet(new TLabel(''));
  272. $table_diversos->addRowSet(new TLabel('Alterado:') ,array($alteracao));
  273. //criação das ações dos botões (action button)
  274. $button1=new TButton('action1');
  275. $button1->setAction(new TAction(array($this, 'onSave')), 'Salvar');
  276. $button1->setImage('fa:floppy-o');
  277. // create an action button (go to list)
  278. $button2=new TButton('list');
  279. $button2->setAction(new TAction(array('CotacaoFormView', 'onReload')), 'Voltar para a listagem');
  280. $button2->setImage('fa:table blue');
  281. // create an action button (go to list)
  282. $button3=new TButton('novo');
  283. $button3->setAction (new TAction(array($this, 'onClear')), _t('New'));//onEdit
  284. $button3->setImage('bs:plus-sign green');
  285. // Vai chamar a função para calcular o frete
  286. $button4=new TButton('calcFrete');
  287. $button4->setAction (new TAction(array($this, 'onFrete')), ('Calcula o Frete'));
  288. $button4->setImage('bs:plus-sign green');
  289. // define os campos que são gravados na model e a variável dos botões
  290. $this->form->setFields(array(2356, $status, $customer_cnpj,$solicitante,$observacoes,$address,$numero,$complemento,
  291. $bairro,$cep,$uf,$contato,
  292. $telefone,$email,$empresa_col,$customercol_cnpj,$address_col,$numero_col,$complemento_col,$bairro_col,$cep_col,
  293. $uf_col,$produto_id,$municipio_col,$municipio,
  294. $grnatureza_id,$embalagem_id,$distancia,$prod_quimico,$onu,$volume,$peso,$peso_cubico,$peso_cubado,$valor_nf,
  295. $comentarios,$fretepeso,$fretevalor,
  296. $coleta,$entrega,$txdespacho,$outros,$cat,$sec_cat,$gris,$pedagio,$perc_icms,$valor_icms,$frete_total,
  297. $data_cotacao,$alteracao,
  298. $button1,$button2,$button3,$button4,$altura,$comprimento,$largura,$base_icms));
  299. // coloca os botões
  300. $subtable = new TTable;
  301. $row = $subtable->addRow();
  302. $row->addCell($button1);
  303. $row->addCell($button3);
  304. $row->addCell($button2);
  305. $row->addCell($button4);
  306. // Sub menu bonito
  307. $vbox = new TVBox;
  308. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  309. $vbox->add($this->form);
  310. $vbox->style = 'width: 55%';
  311. //$vbox->add($this->datagrid); //pra mostra a grid
  312. $vbox->add($subtable);
  313. parent::add($vbox);
  314. }
  315. //*********************** Funções ******************************
  316. public function onClear( $param ) // botão novo
  317. {
  318. $this->form->clear();//Limpa o formulário
  319. //Informações padrões a serem preenchidas no formulário
  320. $perc_icms = 12;
  321. $status = 'Lançado';
  322. $alteracao = date('d-m-Y / H:i');
  323. //Apresentação e tratamento do campos
  324. $obj = new StdClass;
  325. $obj->perc_icms = number_format($perc_icms , 2, ',', '.');
  326. $obj->status = $status;
  327. $obj->alteracao = $alteracao;
  328. TForm::sendData('form_cotacao', $obj);
  329. }
  330. // Calculo da cubagem
  331. static function onCubagem($param)
  332. {
  333. $comprimento = str_replace(',','.', str_replace('.','', $param['comprimento']));
  334. $largura = str_replace(',','.', str_replace('.','', $param['largura']));
  335. $altura = str_replace(',','.', str_replace('.','', $param['altura']));
  336. $peso_cubico = $comprimento * $largura * $altura;
  337. $obj = new StdClass;
  338. $obj->peso_cubico = number_format($peso_cubico, 2, ',', '.');
  339. TForm::sendData('form_cotacao', $obj);
  340. }
  341. // Calculo do peso cubado
  342. static function onPesocubado($param)
  343. {
  344. $peso_cubico = str_replace(',','.', str_replace('.','', $param['peso_cubico']));
  345. $peso_cubado = $peso_cubico * 300;
  346. $obj = new StdClass;
  347. $obj->peso_cubado = number_format($peso_cubado, 2, ',', '.');
  348. TForm::sendData('form_cotacao', $obj);
  349. }
  350. // Calculo do valor do frete
  351. static function onFrete($param)
  352. {
  353. //Tratamento dos campos
  354. $fretepeso = str_replace(',','.', str_replace('.','', $param['fretepeso']));
  355. $fretevalor = str_replace(',','.', str_replace('.','', $param['fretevalor']));
  356. $coleta = str_replace(',','.', str_replace('.','', $param['coleta']));
  357. $entrega = str_replace(',','.', str_replace('.','', $param['entrega']));
  358. $txdespacho = str_replace(',','.', str_replace('.','', $param['txdespacho']));
  359. $outros = str_replace(',','.', str_replace('.','', $param['outros']));
  360. $cat = str_replace(',','.', str_replace('.','', $param['cat']));
  361. $sec_cat = str_replace(',','.', str_replace('.','', $param['sec_cat']));
  362. $gris = str_replace(',','.', str_replace('.','', $param['gris']));
  363. $pedagio = str_replace(',','.', str_replace('.','', $param['pedagio']));
  364. $perc_icms = str_replace(',','.', str_replace('.','', $param['perc_icms']));
  365. //Calculos
  366. $base_icms = ($fretepeso + $fretevalor + $coleta + $entrega + $txdespacho +
  367. $outros + $cat + $sec_cat + $gris + $pedagio) ;
  368. $frete_total = $base_icms / ((100 - $perc_icms)/100);
  369. $valor_icms = $frete_total - $base_icms;
  370. //Apresentação e tratamento do campos
  371. $obj = new StdClass;
  372. $obj->base_icms = number_format($base_icms , 2, ',', '.');
  373. $obj->frete_total = number_format($frete_total, 2, ',', '.');
  374. $obj->valor_icms = number_format($valor_icms , 2, ',', '.');
  375. TForm::sendData('form_cotacao', $obj);
  376. }
  377. /**
  378. * Load object to form data
  379. * @param $param Request
  380. */
  381. public function onEdit( $param )
  382. {
  383. try
  384. {
  385. if (isset($param['key']))
  386. {
  387. $key = $param['key']; // get the parameter $key
  388. TTransaction::open('samples'); // open a transaction
  389. $object = new Cotacao($key); // instantiates the Active Record
  390. $object->data_cotacao = TDate::date2br($object->data_cotacao);
  391. $this->form->setData($object); // fill the form
  392. TTransaction::close(); // close the transaction
  393. }
  394. else
  395. {
  396. $this->form->clear();
  397. }
  398. }
  399. catch (Exception $e) // in case of exception
  400. {
  401. new TMessage('error', $e->getMessage()); // shows the exception error message
  402. TTransaction::rollback(); // undo all pending operations
  403. }
  404. }
  405. /**
  406. * method onSave()
  407. * Executed whenever the user clicks at the save button
  408. */
  409. function onSave()
  410. {
  411. try
  412. {
  413. $alteracao = date('d-m-Y / H:i');
  414. $obj = new StdClass;
  415. $obj->alteracao = $alteracao;
  416. TForm::sendData('form_cotacao', $obj);
  417. TTransaction::open('samples'); // Abre a conexão com o banco
  418. $this->form->validate(); // validação dos dados
  419. $object = $this->form->getData('Cotacao');//abre a tabela
  420. $object->data_cotacao = TDate::date2us($object->data_cotacao);//converte para formato US
  421. $object->store();//grava
  422. $object->data_cotacao = TDate::date2br($object->data_cotacao);
  423. $this->form->setData($object);//
  424. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  425. TTransaction::close(); //fecha o banco
  426. }
  427. catch (Exception $e) // in case of exception
  428. {
  429. // shows the exception error message
  430. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  431. TTransaction::rollback();
  432. }
  433. }
  434. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


IF

Olá Robson. Tenta com JQuery:

 
  1. <?php
  2. //Defina um ID para os campos que vc vai manipular
  3. $frete_total->setId('frete_total');
  4. $status->setChangeAction(new TAction(array($this ,'onChangeStatus')));
  5. //Crie a function onChangeStatus
  6. static function onChangeStatus($param)
  7. {
  8. $status = $param['status'];
  9. if ($status == 'Aprovado')
  10. {
  11. TScript::create('$("#frete_total").addClass("tfield_disabled");');
  12. }
  13. else
  14. {
  15. TScript::create('$("#frete_total").removeClass("tfield_disabled");');
  16. }
  17. }
  18. ?>


Não sei se é a melhor forma de fazer isso, mas eu uso assim e funciona!
RF

Boa noite Ivan, quase funcionou do modo como desejado, na verdade ao abrir o formulário de lançamento (CotacaoForm) o campo continua sendo exibido, ou seja, só funciona quando altero o status.
Na verdade eu queria: Ao selecionar um registro do formulário CotacaoFormView, e o Status fosse "Aprovado" ao abrir CotacaoForm alguns campos (por exemplo frete_total) aparecesse desabilitado.

 
  1. <?php
  2. /**
  3. * CotacaoFormView Listing
  4. * @author <your name here>
  5. */
  6. class CotacaoFormView extends TPage
  7. {
  8. private $form; // form
  9. private $datagrid; // listing
  10. private $pageNavigation;
  11. private $formgrid;
  12. private $loaded;
  13. private $deleteButton;
  14. /**
  15. * Class constructor
  16. * Creates the page, the form and the listing
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. // creates the form
  22. $this->form = new TQuickForm('form_search_Cotacao');
  23. $this->form->class = 'tform'; // change CSS class
  24. $this->form->style = 'display: table;width:100%'; // change style
  25. // create the form fields
  26. $id = new TEntry('id');
  27. $status = new TCombo('status');
  28. $data_cotacao = new TDate('data_cotacao');
  29. //filtro que busca dentro da propria tabela os dados
  30. //campo combo de busca campo que recebe banco tabela chave de busca campo encontrado
  31. $solicitante = new TDBCombo('solicitante' , 'samples', 'Cotacao', 'solicitante' , 'solicitante');
  32. $empresa_col = new TDBCombo('empresa_col' , 'samples', 'Cotacao', 'empresa_col' , 'empresa_col');
  33. $municipio_col = new TDBCombo('municipio_col' , 'samples', 'Cotacao', 'municipio_col', 'municipio_col');
  34. $uf_col = new TCombo('uf_col');
  35. //Itens do Status
  36. $itemStatus= array();
  37. $itemStatus['Lançado'] = 'Lançado';
  38. $itemStatus['Emitido'] = 'Emitido';
  39. $itemStatus['Aprovado'] = 'Aprovado';
  40. $status->setValue('Lançado');
  41. $status->addItems($itemStatus);
  42. //Lista de UFs
  43. $itemUf = array();
  44. $itemUf['AC'] = 'AC';
  45. $itemUf['AL'] = 'AL';
  46. $itemUf['AM'] = 'AM';
  47. $itemUf['AP'] = 'AP';
  48. $itemUf['BA'] = 'BA';
  49. $itemUf['CE'] = 'CE';
  50. $itemUf['DF'] = 'DF';
  51. $itemUf['ES'] = 'ES';
  52. $itemUf['EX'] = 'EX';
  53. $itemUf['GO'] = 'GO';
  54. $itemUf['MA'] = 'MA';
  55. $itemUf['MG'] = 'MG';
  56. $itemUf['MS'] = 'MS';
  57. $itemUf['MT'] = 'MT';
  58. $itemUf['PA'] = 'PA';
  59. $itemUf['PB'] = 'PB';
  60. $itemUf['PE'] = 'PE';
  61. $itemUf['PI'] = 'PI';
  62. $itemUf['PR'] = 'PR';
  63. $itemUf['RJ'] = 'RJ';
  64. $itemUf['RN'] = 'RN';
  65. $itemUf['RO'] = 'RO';
  66. $itemUf['RR'] = 'RR';
  67. $itemUf['RS'] = 'RS';
  68. $itemUf['SC'] = 'SC';
  69. $itemUf['SE'] = 'SE';
  70. $itemUf['SP'] = 'SP';
  71. $itemUf['TO'] = 'TO';
  72. $uf_col->addItems($itemUf);
  73. //Mascara da data
  74. $data_cotacao -> setMask('dd/mm/yyyy');
  75. // add the fields
  76. $this->form->addQuickField('Número', $id, 200 );
  77. $this->form->addQuickField('Status', $status, 200 );
  78. $this->form->addQuickField('Solicitante', $solicitante, 200 );
  79. $this->form->addQuickField('Empresa de Coleta', $empresa_col, 200 );
  80. $this->form->addQuickField('UF de Coleta', $uf_col, 200 );
  81. $this->form->addQuickField('Cidade de Coleta', $municipio_col, 200 );
  82. $this->form->addQuickField('Data de Cotação', $data_cotacao, 180 );
  83. // keep the form filled during navigation with session data
  84. $this->form->setData( TSession::getValue('Cotacao_filter_data') );
  85. // add the search form actions
  86. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  87. $this->form->addQuickAction(_t('New'), new TAction(array('CotacaoForm', 'onEdit')), 'bs:plus-sign green');
  88. // creates a Datagrid
  89. $this->datagrid = new TDataGrid;
  90. $this->datagrid->style = 'width: 100%';
  91. $this->datagrid->setHeight(320);
  92. // $this->datagrid->datatable = 'true';
  93. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  94. // creates the datagrid columns
  95. $column_id = new TDataGridColumn('id', 'Número', 'right');
  96. $column_status = new TDataGridColumn('status', 'Status', 'left');
  97. $column_data_cotacao = new TDataGridColumn('data_cotacao', 'Data', 'left');
  98. $column_solicitante = new TDataGridColumn('solicitante', 'Solicitante', 'left');
  99. $column_customer_cnpj = new TDataGridColumn('customer_cnpj', 'C.N.P.J', 'left');
  100. $column_contato = new TDataGridColumn('contato', 'Contato', 'left');
  101. $column_telefone = new TDataGridColumn('telefone', 'Telefone', 'left');
  102. $column_email = new TDataGridColumn('email', 'Email', 'left');
  103. $column_observacoes = new TDataGridColumn('observacoes', 'Observações', 'left');
  104. $column_empresa_col = new TDataGridColumn('empresa_col', 'Empresa de Coleta', 'left');
  105. $column_uf_col = new TDataGridColumn('uf_col', 'UF de Coleta', 'left');
  106. $column_municipio_col = new TDataGridColumn('municipio_col', 'Cidade de Coleta', 'left');
  107. $column_produto_id = new TDataGridColumn('produto_id', 'Produto', 'right');
  108. $column_grnatureza_id = new TDataGridColumn('grnatureza_id', 'Grupo de Natureza', 'right');
  109. $column_embalagem_id = new TDataGridColumn('embalagem_id', 'Embalagem', 'right');
  110. $column_distancia = new TDataGridColumn('distancia', 'Distância', 'right');
  111. $column_prod_quimico = new TDataGridColumn('prod_quimico', 'Químico', 'left');
  112. $column_onu = new TDataGridColumn('onu', 'Onu', 'left');
  113. $column_volume = new TDataGridColumn('volume', 'Volume', 'right');
  114. $column_peso = new TDataGridColumn('peso', 'Peso', 'right');
  115. $column_cubagem = new TDataGridColumn('cubagem', 'Cubagem', 'right');
  116. $column_pesocubado = new TDataGridColumn('pesocubado', 'Peso Cubado', 'right');
  117. $column_valor_nf = new TDataGridColumn('valor_nf', 'Valor da NF-e', 'right');
  118. $column_comentarios = new TDataGridColumn('comentarios', 'Comentários', 'left');
  119. $column_frete_total = new TDataGridColumn('frete_total', 'Frete Total', 'right');
  120. // Columas do DataGrid
  121. $this->datagrid->addColumn($column_id);
  122. $this->datagrid->addColumn($column_status);
  123. $this->datagrid->addColumn($column_data_cotacao);
  124. $this->datagrid->addColumn($column_solicitante);
  125. $this->datagrid->addColumn($column_empresa_col);
  126. $this->datagrid->addColumn($column_contato);
  127. $this->datagrid->addColumn($column_telefone);
  128. $this->datagrid->addColumn($column_prod_quimico);
  129. $this->datagrid->addColumn($column_frete_total);
  130. //$this->datagrid->addColumn($column_email);
  131. //$this->datagrid->addColumn($column_observacoes);
  132. //$this->datagrid->addColumn($column_uf_col);
  133. //$this->datagrid->addColumn($column_municipio_col);
  134. //$this->datagrid->addColumn($column_produto_id);
  135. //$this->datagrid->addColumn($column_grnatureza_id);
  136. //$this->datagrid->addColumn($column_embalagem_id);
  137. //$this->datagrid->addColumn($column_distancia);
  138. //$this->datagrid->addColumn($column_onu);
  139. //$this->datagrid->addColumn($column_volume);
  140. //$this->datagrid->addColumn($column_peso);
  141. //$this->datagrid->addColumn($column_cubagem);
  142. //$this->datagrid->addColumn($column_pesocubado);
  143. //$this->datagrid->addColumn($column_valor_nf);
  144. //$this->datagrid->addColumn($column_comentarios);
  145. //$this->datagrid->addColumn($column_customer_cnpj);
  146. // create EDIT action
  147. $action_edit = new TDataGridAction(array('CotacaoForm', 'onEdit'));
  148. $action_edit->setUseButton(TRUE);
  149. $action_edit->setButtonClass('btn btn-default');
  150. //$action_edit->setLabel(_t('Edit'));
  151. $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  152. $action_edit->setField('id');
  153. $this->datagrid->addAction($action_edit);
  154. /*
  155. // create DELETE action
  156. $action_del = new TDataGridAction(array($this, 'onDelete'));
  157. $action_del->setUseButton(TRUE);
  158. $action_del->setButtonClass('btn btn-default');
  159. //$action_del->setLabel(_t('Delete'));
  160. $action_del->setImage('fa:trash-o red fa-lg');
  161. $action_del->setField('id');
  162. $this->datagrid->addAction($action_del);
  163. */
  164. // create the datagrid model
  165. $this->datagrid->createModel();
  166. // creates the page navigation
  167. $this->pageNavigation = new TPageNavigation;
  168. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  169. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  170. // Sub menu bonito
  171. $vbox = new TVBox;
  172. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  173. $vbox->add($this->form);
  174. $vbox->style = 'width: 100%';
  175. $vbox->add($this->datagrid);
  176. $vbox->add($this->pageNavigation);
  177. parent::add($vbox);
  178. }
  179. /**
  180. * Inline record editing
  181. * @param $param Array containing:
  182. * key: object ID value
  183. * field name: object attribute to be updated
  184. * value: new attribute content
  185. */
  186. public function onInlineEdit($param)
  187. {
  188. try
  189. {
  190. // get the parameter $key
  191. $field = $param['field'];
  192. $key = $param['key'];
  193. $value = $param['value'];
  194. TTransaction::open('samples'); // open a transaction with database
  195. $object = new Cotacao($key); // instantiates the Active Record
  196. $object->data_cotacao = TDate::date2br($object->data_cotacao);
  197. $object->{$field} = $value;
  198. $object->store(); // update the object in the database
  199. TTransaction::close(); // close the transaction
  200. $this->onReload($param); // reload the listing
  201. new TMessage('info', "Record Updated");
  202. }
  203. catch (Exception $e) // in case of exception
  204. {
  205. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  206. TTransaction::rollback(); // undo all pending operations
  207. }
  208. }
  209. /**
  210. * Register the filter in the session
  211. */
  212. public function onSearch()
  213. {
  214. // get the search form data
  215. $data = $this->form->getData();
  216. // clear session filters
  217. TSession::setValue('CotacaoFormView_filter_id', NULL);
  218. TSession::setValue('CotacaoFormView_filter_status', NULL);
  219. TSession::setValue('CotacaoFormView_filter_data_cotacao', NULL);
  220. TSession::setValue('CotacaoFormView_filter_solicitante', NULL);
  221. TSession::setValue('CotacaoFormView_filter_empresa_col', NULL);
  222. TSession::setValue('CotacaoFormView_filter_uf_col', NULL);
  223. TSession::setValue('CotacaoFormView_filter_municipio_col', NULL);
  224. if (isset($data->id) AND ($data->id)) {
  225. $filter = new TFilter('id', 'like', "%{$data->id}%"); // create the filter
  226. TSession::setValue('CotacaoFormView_filter_id', $filter); // stores the filter in the session
  227. }
  228. if (isset($data->status) AND ($data->status)) {
  229. $filter = new TFilter('status', 'like', "%{$data->status}%"); // create the filter
  230. TSession::setValue('CotacaoFormView_filter_status', $filter); // stores the filter in the session
  231. }
  232. if (isset($data->data_cotacao) AND ($data->data_cotacao)) {
  233. $data->data_cotacao = TDate::date2us($data->data_cotacao);//Muda para o formato USA
  234. $filter = new TFilter('data_cotacao', 'like', "%{$data->data_cotacao}%"); // create the filter
  235. $data->data_cotacao = TDate::date2br($data->data_cotacao);//Volta para o formato BRA
  236. TSession::setValue('CotacaoFormView_filter_data_cotacao', $filter); // stores the filter in the session
  237. }
  238. if (isset($data->solicitante) AND ($data->solicitante)) {
  239. $filter = new TFilter('solicitante', 'like', "%{$data->solicitante}%"); // create the filter
  240. TSession::setValue('CotacaoFormView_filter_solicitante', $filter); // stores the filter in the session
  241. }
  242. if (isset($data->empresa_col) AND ($data->empresa_col)) {
  243. $filter = new TFilter('empresa_col', 'like', "%{$data->empresa_col}%"); // create the filter
  244. TSession::setValue('CotacaoFormView_filter_empresa_col', $filter); // stores the filter in the session
  245. }
  246. if (isset($data->uf_col) AND ($data->uf_col)) {
  247. $filter = new TFilter('uf_col', 'like', "%{$data->uf_col}%"); // create the filter
  248. TSession::setValue('CotacaoFormView_filter_uf_col', $filter); // stores the filter in the session
  249. }
  250. if (isset($data->municipio_col) AND ($data->municipio_col)) {
  251. $filter = new TFilter('municipio_col', 'like', "%{$data->municipio_col}%"); // create the filter
  252. TSession::setValue('CotacaoFormView_filter_municipio_col', $filter); // stores the filter in the session
  253. }
  254. // fill the form with data again
  255. $this->form->setData($data);
  256. // keep the search data in the session
  257. TSession::setValue('Cotacao_filter_data', $data);
  258. $param=array();
  259. $param['offset'] =0;
  260. $param['first_page']=1;
  261. $this->onReload($param);
  262. }
  263. /**
  264. * Load the datagrid with data
  265. */
  266. public function onReload($param = NULL)
  267. {
  268. try
  269. {
  270. // open a transaction with database 'samples'
  271. TTransaction::open('samples');
  272. // creates a repository for Cotacao
  273. $repository = new TRepository('Cotacao');
  274. $limit = 10;
  275. // creates a criteria
  276. $criteria = new TCriteria;
  277. // default order
  278. if (empty($param['order']))
  279. {
  280. $param['order'] = 'id';
  281. $param['direction'] = 'asc';
  282. }
  283. $criteria->setProperties($param); // order, offset
  284. $criteria->setProperty('limit', $limit);
  285. if (TSession::getValue('CotacaoFormView_filter_id')) {
  286. $criteria->add(TSession::getValue('CotacaoFormView_filter_id')); // add the session filter
  287. }
  288. if (TSession::getValue('CotacaoFormView_filter_status')) {
  289. $criteria->add(TSession::getValue('CotacaoFormView_filter_status')); // add the session filter
  290. }
  291. if (TSession::getValue('CotacaoFormView_filter_data_cotacao')) {
  292. $criteria->add(TSession::getValue('CotacaoFormView_filter_data_cotacao')); // add the session filter
  293. }
  294. if (TSession::getValue('CotacaoFormView_filter_solicitante')) {
  295. $criteria->add(TSession::getValue('CotacaoFormView_filter_solicitante')); // add the session filter
  296. }
  297. if (TSession::getValue('CotacaoFormView_filter_empresa_col')) {
  298. $criteria->add(TSession::getValue('CotacaoFormView_filter_empresa_col')); // add the session filter
  299. }
  300. if (TSession::getValue('CotacaoFormView_filter_uf_col')) {
  301. $criteria->add(TSession::getValue('CotacaoFormView_filter_uf_col')); // add the session filter
  302. }
  303. if (TSession::getValue('CotacaoFormView_filter_municipio_col')) {
  304. $criteria->add(TSession::getValue('CotacaoFormView_filter_municipio_col')); // add the session filter
  305. }
  306. // load the objects according to criteria
  307. $objects = $repository->load($criteria, FALSE);
  308. if (is_callable($this->transformCallback))
  309. {
  310. call_user_func($this->transformCallback, $objects, $param);
  311. }
  312. $this->datagrid->clear();
  313. if ($objects)
  314. {
  315. // iterate the collection of active records
  316. foreach ($objects as $object)
  317. {
  318. // add the object inside the datagrid // converta a data para dd/mm/yyyy e exibe
  319. $object->data_cotacao = TDate::date2br($object->data_cotacao);
  320. $this->datagrid->addItem($object);
  321. }
  322. }
  323. // reset the criteria for record count
  324. $criteria->resetProperties();
  325. $count= $repository->count($criteria);
  326. $this->pageNavigation->setCount($count); // count of records
  327. $this->pageNavigation->setProperties($param); // order, page
  328. $this->pageNavigation->setLimit($limit); // limit
  329. // close the transaction
  330. TTransaction::close();
  331. $this->loaded = true;
  332. }
  333. catch (Exception $e) // in case of exception
  334. {
  335. // shows the exception error message
  336. new TMessage('error', $e->getMessage());
  337. // undo all pending operations
  338. TTransaction::rollback();
  339. }
  340. }
  341. /**
  342. * Ask before deletion
  343. */
  344. public function onDelete($param)
  345. {
  346. // define the delete action
  347. $action = new TAction(array($this, 'Delete'));
  348. $action->setParameters($param); // pass the key parameter ahead
  349. // shows a dialog to the user
  350. new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  351. }
  352. /**
  353. * Delete a record
  354. */
  355. public function Delete($param)
  356. {
  357. try
  358. {
  359. $key=$param['key']; // get the parameter $key
  360. TTransaction::open('samples'); // open a transaction with database
  361. $object = new Cotacao($key, FALSE); // instantiates the Active Record
  362. $object->delete(); // deletes the object from the database
  363. TTransaction::close(); // close the transaction
  364. $this->onReload( $param ); // reload the listing
  365. new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
  366. }
  367. catch (Exception $e) // in case of exception
  368. {
  369. new TMessage('error', $e->getMessage()); // shows the exception error message
  370. TTransaction::rollback(); // undo all pending operations
  371. }
  372. }
  373. /**
  374. * method show()
  375. * Shows the page
  376. */
  377. public function show()
  378. {
  379. // check if the datagrid is already loaded
  380. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  381. {
  382. if (func_num_args() > 0)
  383. {
  384. $this->onReload( func_get_arg(0) );
  385. }
  386. else
  387. {
  388. $this->onReload();
  389. }
  390. }
  391. parent::show();
  392. }
  393. }
  394. </your>
IF

Entendi, então faça assim:

No início do programa declare os campos que vc vai querer manipular como private:

 
  1. <?php
  2. class CotacaoForm extends TPage
  3. {
  4. private $form; // form
  5. private $frete_total;
  6. ?>


Depois declare as variáveis dos campos com o this:

 
  1. <?php
  2. $this->frete_valor = new TEntry('frete_valor');
  3. ?>


Na function onEdit(), vc faz a verificação do status e altera o atributo dos campos:

 
  1. <?php
  2. ...
  3. if (isset($param['key']))
  4. {
  5. $key = $param['key']; // get the parameter $key
  6. TTransaction::open('samples'); // open a transaction
  7. $object = new Cotacao($key); // instantiates the Active Record
  8. $object->data_cotacao = TDate::date2br($object->data_cotacao);
  9. //Aqui vc faz a verificação
  10. if ($object->status=='Aprovado')
  11. {
  12. $this->frete_valor->setEditable(FALSE);
  13. ...
  14. }
  15. $this->form->setData($object); // fill the form
  16. TTransaction::close(); // close the transaction
  17. }
  18. ...
  19. ?>


Acho que é isso
RF

Boa noite Ivan, muito obrigado mais uma vez. Deu certo, aprendi mais algumas coisas.
Na verdade para esse momento vou fazer algo diferente. Só não vou permitir que o registro seja gravado se o Status for igual a Lançado, para a próxima tela (Ordens de coleta e Romaneio) vou usar esse conceito que entendi.
Amanhã publico a versão corrigida, se desejar dar uma olhada no meu trabalho entre em transpalog.esy.es usuário convidado, senha convidado.
Até a próxima dúvida... rssss
IF

Ok Robson, vou dar uma olhada. Abraço