Qual evento uso pra pegar o check ativado no datagrid Preciso através do componente check list validar quando o check estiver marcar e somar os valores das horas e atualizar o valor total na capa da nota fiscal de serviço. ...
GG
Qual evento uso pra pegar o check ativado no datagrid  
Preciso através do componente check list validar quando o check estiver marcar e somar os valores das horas e atualizar o valor total na capa da nota fiscal de serviço.

 
  1. <?php
  2. class NotaFiscalServicoForm extends TPage
  3. {
  4. protected $form; // form
  5. protected $apontamento_list;
  6. /**
  7. * Class constructor
  8. * Creates the page and the registration form
  9. */
  10. function __construct()
  11. {
  12. parent::__construct();
  13. // creates the form
  14. $this->form = new BootstrapFormBuilder('form_Nota_fiscal_servico');
  15. $this->form->setFormTitle('Nota Fiscal de Serviço');
  16. // create the form fields
  17. $id = new TEntry('id');
  18. $numero_nota = new TEntry('numero_nota');
  19. $valor_total = new TEntry('valor_total');
  20. $tipo_movimento_id = new TDBUniqueSearch('tipo_movimento_id', 'app', 'TipoMovimento', 'id', 'nome');
  21. $data_emissao = new TDate('data_emissao');
  22. $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'far:save');
  23. $btn->class = 'btn btn-sm btn-primary';
  24. $this->form->addActionLink( _t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
  25. $this->form->addActionLink( _t('Back'), new TAction(array('NotaFiscalServicoList','onReload')), 'far:arrow-alt-circle-left blue');
  26. // define the sizes
  27. $id->setSize('50%');
  28. $numero_nota->setSize('100%');
  29. $valor_total->setSize('100%');
  30. $tipo_movimento_id->setSize('100%');
  31. $tipo_movimento_id->setMinLength(1);
  32. $data_emissao->setSize('100%');
  33. // outros
  34. $id->setEditable(false);
  35. $valor_total->setEditable(false);
  36. // validations
  37. $numero_nota->addValidation(_t('Número da Nota'), new TRequiredValidator);
  38. $valor_total->addValidation('Valor Total', new TRequiredValidator);
  39. $tipo_movimento_id->addValidation('Tipo de Movimento', new TRequiredValidator);
  40. $data_emissao->addValidation('Data Emissão', new TRequiredValidator);
  41. $this->form->addFields( [new TLabel('ID')], [$id], [new TLabel(('Número Nota'))], [$numero_nota] );
  42. $this->form->addFields( [new TLabel(('Valor Total'))], [$valor_total], [new TLabel(('Tipo de Movimento'))], [$tipo_movimento_id] );
  43. $this->form->addFields( [new TLabel(('Data Emissao'))], [$data_emissao] );
  44. $search = new TEntry('search');
  45. $search->placeholder = ('Search');
  46. $search->style = 'width:50%;margin-left: 2px; border-radius: 4px';
  47. $this->apontamento_list = new TCheckList('apontamento_list');
  48. $this->apontamento_list->setIdColumn('id');
  49. $this->apontamento_list->addColumn('id', 'ID', 'center', '10%');
  50. $this->apontamento_list->addColumn('Rat->numero_rat',('RAT') . $search->getContents(), 'left', '30%');
  51. $this->apontamento_list->addColumn('Rat->descricao', 'Descrição','left', '40%');
  52. $this->apontamento_list->addColumn('data_apontamento', 'Data', 'left', '40%');
  53. $this->apontamento_list->addColumn('quantidade_horas', 'Horas', 'left', '40%');
  54. $this->apontamento_list->setHeight(100);
  55. $this->apontamento_list->makeScrollable();
  56. $this->apontamento_list->enableSearch($search, 'Rat->numero_rat');
  57. $this->form->addFields( [new TFormSeparator(('Apontamentos'))] );
  58. $this->form->addFields( [$this->apontamento_list] );
  59. $check = new TDataGridAction(array($this,'onCheckChange'));
  60. TTransaction::open('app');
  61. $this->apontamento_list->addItems( Apontamento::get() );
  62. TTransaction::close();
  63. $container = new TVBox;
  64. $container->style = 'width: 100%';
  65. $container->add($this->form);
  66. // add the container to the page
  67. parent::add($container);
  68. }
  69. /**
  70. * Save user data
  71. */
  72. public function onSave($param)
  73. {
  74. try
  75. {
  76. // open a transaction with database 'permission'
  77. TTransaction::open('app');
  78. $data = $this->form->getData();
  79. $this->form->setData($data);
  80. $object = new NotaFiscalServico;
  81. $object->fromArray( (array) $data );
  82. $object->system_user_id = TSession::getValue('userid');
  83. $object->valor_total = 100;
  84. $object->store();
  85. $object->clearParts();
  86. if (!empty($data->apontamento_list))
  87. {
  88. foreach ($data->apontamento_list as $apontamento_id)
  89. {
  90. $object->addNotaFiscalServicoApontamento( new Apontamento( $apontamento_id ) );
  91. }
  92. }
  93. $data = new stdClass;
  94. $data->id = $object->id;
  95. TForm::sendData('form_Nota_Fiscal_Servico', $data);
  96. // close the transaction
  97. TTransaction::close();
  98. // shows the success message
  99. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
  100. }
  101. catch (Exception $e) // in case of exception
  102. {
  103. new TMessage('error', $e->getMessage());
  104. TTransaction::rollback();
  105. }
  106. }
  107. /**
  108. * method onEdit()
  109. * Executed whenever the user clicks at the edit button da datagrid
  110. */
  111. public function onCheckChange($param)
  112. {
  113. try
  114. {
  115. // get the parameter $key
  116. var_dump($param);
  117. $check = $param['check'];
  118. $quantidade_horas = $param['quantidade_horas'];
  119. $this->onReload($param); // reload the listing
  120. new TMessage('info', "Record Updated");
  121. }
  122. catch (Exception $e) // in case of exception
  123. {
  124. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  125. TTransaction::rollback(); // undo all pending operations
  126. }
  127. }
  128. function onEdit($param)
  129. {
  130. try
  131. {
  132. if (isset($param['key']))
  133. {
  134. // get the parameter $key
  135. $key=$param['key'];
  136. // open a transaction with database 'app'
  137. TTransaction::open('app');
  138. // instantiates object System_user
  139. $object = new NotaFiscalServico($key);
  140. $apontamento_ids = array();
  141. foreach ($object->getNotaFiscalServicoApontamentos() as $apontamento)
  142. {
  143. $apontamento_ids[] = $apontamento->id;
  144. }
  145. $object->apontamento_list = $apontamento_ids;
  146. // fill the form with the active record data
  147. $this->form->setData($object);
  148. // close the transaction
  149. TTransaction::close();
  150. }
  151. else
  152. {
  153. $this->form->clear();
  154. }
  155. }
  156. catch (Exception $e) // in case of exception
  157. {
  158. new TMessage('error', $e->getMessage());
  159. TTransaction::rollback();
  160. }
  161. }
  162. }
  163. ?>

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


GG

como este porém somando os valores do checklist
https://www.adianti.com.br/framework_files/tutor/index.php?class=FormCheckListVi
G

Boa Tarde Guilherme,
Estou com o mesmo problema, como conseguiu resolver? pode me ajudar?
GG

Infelizmente usando este recurso na época não dava pra fazer, tive que abandonar este desenvolvimento.