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.
- <?php
- class NotaFiscalServicoForm extends TPage
- {
- protected $form; // form
- protected $apontamento_list;
-
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
-
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Nota_fiscal_servico');
- $this->form->setFormTitle('Nota Fiscal de Serviço');
-
- // create the form fields
- $id = new TEntry('id');
- $numero_nota = new TEntry('numero_nota');
- $valor_total = new TEntry('valor_total');
- $tipo_movimento_id = new TDBUniqueSearch('tipo_movimento_id', 'app', 'TipoMovimento', 'id', 'nome');
- $data_emissao = new TDate('data_emissao');
-
- $btn = $this->form->addAction( _t('Save'), new TAction(array($this, 'onSave')), 'far:save');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink( _t('Clear'), new TAction(array($this, 'onEdit')), 'fa:eraser red');
- $this->form->addActionLink( _t('Back'), new TAction(array('NotaFiscalServicoList','onReload')), 'far:arrow-alt-circle-left blue');
-
- // define the sizes
- $id->setSize('50%');
- $numero_nota->setSize('100%');
- $valor_total->setSize('100%');
- $tipo_movimento_id->setSize('100%');
- $tipo_movimento_id->setMinLength(1);
- $data_emissao->setSize('100%');
-
- // outros
- $id->setEditable(false);
- $valor_total->setEditable(false);
-
- // validations
- $numero_nota->addValidation(_t('Número da Nota'), new TRequiredValidator);
- $valor_total->addValidation('Valor Total', new TRequiredValidator);
- $tipo_movimento_id->addValidation('Tipo de Movimento', new TRequiredValidator);
- $data_emissao->addValidation('Data Emissão', new TRequiredValidator);
-
- $this->form->addFields( [new TLabel('ID')], [$id], [new TLabel(('Número Nota'))], [$numero_nota] );
- $this->form->addFields( [new TLabel(('Valor Total'))], [$valor_total], [new TLabel(('Tipo de Movimento'))], [$tipo_movimento_id] );
- $this->form->addFields( [new TLabel(('Data Emissao'))], [$data_emissao] );
-
- $search = new TEntry('search');
- $search->placeholder = ('Search');
- $search->style = 'width:50%;margin-left: 2px; border-radius: 4px';
-
- $this->apontamento_list = new TCheckList('apontamento_list');
- $this->apontamento_list->setIdColumn('id');
- $this->apontamento_list->addColumn('id', 'ID', 'center', '10%');
- $this->apontamento_list->addColumn('Rat->numero_rat',('RAT') . $search->getContents(), 'left', '30%');
- $this->apontamento_list->addColumn('Rat->descricao', 'Descrição','left', '40%');
- $this->apontamento_list->addColumn('data_apontamento', 'Data', 'left', '40%');
- $this->apontamento_list->addColumn('quantidade_horas', 'Horas', 'left', '40%');
- $this->apontamento_list->setHeight(100);
- $this->apontamento_list->makeScrollable();
-
- $this->apontamento_list->enableSearch($search, 'Rat->numero_rat');
-
- $this->form->addFields( [new TFormSeparator(('Apontamentos'))] );
- $this->form->addFields( [$this->apontamento_list] );
-
-
- $check = new TDataGridAction(array($this,'onCheckChange'));
-
- TTransaction::open('app');
- $this->apontamento_list->addItems( Apontamento::get() );
- TTransaction::close();
-
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add($this->form);
- // add the container to the page
- parent::add($container);
- }
- /**
- * Save user data
- */
- public function onSave($param)
- {
- try
- {
- // open a transaction with database 'permission'
- TTransaction::open('app');
- $data = $this->form->getData();
- $this->form->setData($data);
-
- $object = new NotaFiscalServico;
- $object->fromArray( (array) $data );
- $object->system_user_id = TSession::getValue('userid');
- $object->valor_total = 100;
-
- $object->store();
- $object->clearParts();
-
- if (!empty($data->apontamento_list))
- {
- foreach ($data->apontamento_list as $apontamento_id)
- {
- $object->addNotaFiscalServicoApontamento( new Apontamento( $apontamento_id ) );
- }
- }
-
- $data = new stdClass;
- $data->id = $object->id;
- TForm::sendData('form_Nota_Fiscal_Servico', $data);
-
- // close the transaction
- TTransaction::close();
-
- // shows the success message
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
-
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- public function onCheckChange($param)
- {
- try
- {
- // get the parameter $key
- var_dump($param);
- $check = $param['check'];
- $quantidade_horas = $param['quantidade_horas'];
-
- $this->onReload($param); // reload the listing
- new TMessage('info', "Record Updated");
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- // get the parameter $key
- $key=$param['key'];
-
- // open a transaction with database 'app'
- TTransaction::open('app');
-
- // instantiates object System_user
- $object = new NotaFiscalServico($key);
-
- $apontamento_ids = array();
- foreach ($object->getNotaFiscalServicoApontamentos() as $apontamento)
- {
- $apontamento_ids[] = $apontamento->id;
- }
-
- $object->apontamento_list = $apontamento_ids;
-
- // fill the form with the active record data
- $this->form->setData($object);
-
- // close the transaction
- TTransaction::close();
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
- ?>
como este porém somando os valores do checklist
https://www.adianti.com.br/framework_files/tutor/index.php?class=FormCheckListVi
Boa Tarde Guilherme,
Estou com o mesmo problema, como conseguiu resolver? pode me ajudar?
Infelizmente usando este recurso na época não dava pra fazer, tive que abandonar este desenvolvimento.