/** * Class Constructor * @param $name name of the form field * @param $database name of the database connection * @param $form name of the parent form * @param $model name of the Active Record to be searched * @param $display_field name of the field to be searched and shown * @param $receive_key name of the form field to receive the primary key * @param $receive_display_field name of the form field to receive the "display field" */ public function __construct($name, $database, $form, $model, $display_field, $receive_key, $receive_display_field, TCriteria $criteria = NULL) { parent::__construct($name); if (empty($database)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'database', __CLASS__)); } if (empty($model)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'model', __CLASS__)); } if (empty($display_field)) { throw new Exception(AdiantiCoreTranslator::translate('The parameter (^1) of ^2 is required', 'display_field', __CLASS__)); } $obj = new TStandardSeek(); // define the action parameters $action = new TAction(array($obj, 'onSetup')); $action->setParameter('database', $database); $action->setParameter('parent', $form); $action->setParameter('model', $model); $action->setParameter('display_field', $display_field); $action->setParameter('receive_key', $receive_key); $action->setParameter('receive_field', $receive_display_field); $action->setParameter('criteria', base64_encode(serialize($criteria))); parent::setAction($action); }
public function onEdit($param) { if (isset($param) && isset($param['key'])) { $key = $param['key']; } if (!isset($key)) { $form_requisicao = new stdClass(); $form_requisicao->numeroSRP = ''; $form_requisicao->numeroProcessoOrigem = ''; $form_requisicao->numeroProcesso = ''; $form_requisicao->validade = ''; $form_requisicao->nome = ''; $form_requisicao->uasg = ''; $form_requisicao->emissao = date('d/m/Y'); TSession::delValue('requisicao_itens'); TSession::delValue('requisicao_itens_o'); TSession::delValue('form_requisicao'); TSession::delValue('SRP_id'); TForm::sendData('form_requisicao', $form_requisicao); $this->onReload(); return; } try { TTransaction::open('saciq'); $requisicao = new Requisicao($key); $form_requisicao = new stdClass(); $form_requisicao->id = $key; $form_requisicao->numeroSRP = $requisicao->srp->numeroSRP; $form_requisicao->numeroProcessoOrigem = $requisicao->srp->numeroProcesso; $form_requisicao->numeroProcesso = $requisicao->numeroProcesso; $form_requisicao->validade = TDate::date2br($requisicao->srp->validade); $form_requisicao->nome = $requisicao->srp->nome; $form_requisicao->uasg = $requisicao->srp->uasg; $form_requisicao->emissao = TDate::date2br($requisicao->emissao); TSession::delValue('requisicao_itens'); TSession::delValue('requisicao_itens_o'); TSession::setValue('SRP_id', $requisicao->srp->id); TSeekButton::disableField('form_requisicao', 'numeroSRP'); foreach ($requisicao->getItems() as $item_requisicao) { $item = new stdClass(); $item->item_id = $item_requisicao->id; $item->numeroItem = $item_requisicao->numeroItem; $item->descricaoSumaria = $item_requisicao->descricaoSumaria; $item->quantidade = $item_requisicao->quantidade; $item->valorUnitario = $item_requisicao->valorUnitario; $item->justificativa = $item_requisicao->justificativa; $item->prazoEntrega = $item_requisicao->prazoEntrega; $item->total = $item_requisicao->total; $itens[$item->numeroItem] = $item; } TSession::setValue('requisicao_itens', $itens); TSession::setValue('requisicao_itens_o', $itens); TSession::setValue('form_requisicao', $form_requisicao); TForm::sendData('form_requisicao', $form_requisicao); $this->onReload(); TTransaction::close(); } catch (Exception $e) { if ($e->getCode() == 23000) { new TMessage('error', '<b>Registro duplicado</b><br>Verifique os campos inseridos e tente novamente'); } else { if ($e->getCode() == 0) { new TMessage('error', '<b>Error</b> <br>' . $e->getMessage()); } else { new TMessage('error', '<b>Error Desconhecido</b> <br>Código: ' . $e->getCode()); } } // desfazer todas as operacoes pendentes TTransaction::rollback(); } }
/** * */ public function makeTSeekButton($properties) { $widget = new TSeekButton((string) $properties->{'name'}); $widget->setSize((int) $properties->{'width'}); if ($properties->{'database'} and $properties->{'model'}) { $obj = new TStandardSeek(); $action = new TAction(array($obj, 'onSetup')); $action->setParameter('database', (string) $properties->{'database'}); if (isset($this->form)) { if ($this->form instanceof TForm) { $action->setParameter('parent', $this->form->getName()); } } $action->setParameter('model', (string) $properties->{'model'}); $action->setParameter('display_field', (string) $properties->{'display'}); $action->setParameter('receive_key', (string) $properties->{'name'}); $action->setParameter('receive_field', (string) $properties->{'receiver'}); $widget->setAction($action); } $this->fields[] = $widget; $this->fieldsByName[(string) $properties->{'name'}] = $widget; return $widget; }
function __construct() { parent::__construct(); //cria os containers $this->form_cessao = new TForm('form_cessao'); $this->form_cessao->class = 'tform'; $this->form_itens = new TForm('form_itens'); $this->form_itens->class = 'tform'; $table_cessao = new TTable(); $table_cessao->width = '100%'; $table_itens = new TTable(); $table_itens->width = '100%'; //empacota os dados $this->form_cessao->add($table_cessao); $this->form_itens->add($table_itens); //campos da cessao; $numeroSRP = new TSeekButton('numeroSRP'); $nome = new TEntry('nome'); $numeroProcessoOrigem = new TEntry('numeroProcessoOrigem'); $uasg = new TEntry('uasg'); $validadeAta = new TEntry('validade'); $numeroCessao = new TEntry('numeroCessao'); $campusID = new TDBSeekButton('campusID', 'saciq', 'form_cessao', 'Campus', 'nome', 'campusID', 'campusNome'); $campusNome = new TEntry('campusNome'); $emissao = new TDate('emissao'); //campos do itens $numeroItem = new TSeekButton('numeroItem'); $item_id = new THidden('item_id'); $descricaoSumaria = new TEntry('descricaoSumaria'); $valorUnitario = new TEntry('valorUnitario'); $quantidade = new TEntry('quantidade'); //$prazoEntrega = new TEntry('prazoEntrega'); //$justificativa = new TEntry('justificativa'); $addItem = new TButton('addItem'); $save = new TButton('save'); $new = new TButton('new'); $list = new TButton('list'); //ações dos campos $numeroSRP->setAction(new TAction(array(new SrpSeekCessao(), 'onReload'))); $numeroCessao->setExitAction(new TAction(array($this, 'onExitNumeroProcesso'))); $campusID->setExitAction(new TAction(array($this, 'onExitCampus'))); $emissao->setExitAction(new TAction(array($this, 'onExitEmissao'))); $numeroItem->setAction(new TAction(array(new ItemSeekCessao(), 'onReload'))); $addItem->setAction(new TAction(array($this, 'onAddItem')), 'Adicionar'); $addItem->setImage('fa:plus-square-o'); $save->setAction(new TAction(array($this, 'onSave')), 'Salvar'); $save->setImage('ico_save.png'); $new->setAction(new TAction(array($this, 'onEdit')), 'Novo'); $new->setImage('ico_new.png'); $list->setAction(new TAction(array('CessaoList', 'onReload')), 'Voltar para a listagem'); $list->setImage('ico_datagrid.png'); $quantidade->setExitAction(new TAction(array($this, 'onValidaQuantidade'))); //validadores $numeroSRP->addValidation('Nº SRP', new TRequiredValidator()); $numeroItem->addValidation('Item', new TRequiredValidator()); $valorUnitario->addValidation('Preço', new TRequiredValidator()); $quantidade->addValidation('Quantidade', new TRequiredValidator()); $quantidade->addValidation('Quantidade', new TMinValueValidator(), array(1)); $quantidade->addValidation('Quantidade', new TMaxLengthValidator(), array(11)); $numeroCessao->addValidation('Nº Cessão', new TRequiredValidator()); $numeroCessao->addValidation('Nº Cessão', new TMaxLengthValidator(), array(30)); $campusID->addValidation('Câmpus', new TRequiredValidator()); $emissao->addValidation('Emissão', new TRequiredValidator()); //outras propriedades $descricaoSumaria->setEditable(false); $nome->setEditable(false); $numeroProcessoOrigem->setEditable(false); $uasg->setEditable(false); $validadeAta->setEditable(false); $valorUnitario->setEditable(false); $numeroSRP->setSize(80); $nome->setSize(300); $nome->setProperty('style', 'margin-right: 10px', false); $numeroProcessoOrigem->setSize(160); $uasg->setSize(70); $validadeAta->setSize(85); $numeroItem->setSize(60); $descricaoSumaria->setSize('100%'); $descricaoSumaria->setProperty('style', 'margin-right: 10px', false); $numeroCessao->setSize(230); $numeroCessao->setTip('Número do processo gerado no SIGA'); $campusID->setSize(50); $campusNome->setSize('100%'); $campusNome->setEditable(false); $validadeAta->setMask('dd/mm/yyyy'); $emissao->setSize(90); $emissao->setProperty('style', 'margin-right: 0px;', false); $emissao->setMask('dd/mm/yyyy'); $emissao->setValue(date('d/m/Y')); $quantidade->class = 'frm_number_only'; //$prazoEntrega->setValue('60 Dias'); //$addItem->setProperty('style', 'margin: 0 0 10px 10px;', false); $row = $table_cessao->addRow(); $row->class = 'tformtitle'; // CSS class $cell = $row->addCell(new TLabel('Cessão de quantitativo')); $cell->colspan = 4; $row = $table_cessao->addRow(); $row->addCell(new TLabel('Nº SRP:'))->width = '150px'; $row->addCell($numeroSRP); $row->addCell(new TLabel('Nome Licitação:'))->width = '150px'; $row->addCell($nome); $table_cessao->addRowSet(new TLabel('Proc. Orig:'), $numeroProcessoOrigem, new TLabel('UASG:'), $uasg); $table_cessao->addRowSet(new TLabel('Validade da Ata:'), $validadeAta, new TLabel('Nº Cessão:'), $numeroCessao); $row = $table_cessao->addRow(); $row->addCell(new TLabel('Câmpus:')); $box = new THBox(); $box->add($campusID); $box->add($campusNome)->style = 'width: 75%; display : inline-block;'; $row->addCell($box)->colspan = 3; $table_cessao->addRowSet(new TLabel('Data Emissão:'), $emissao); $row = $table_itens->addRow(); $row->class = 'tformtitle'; // CSS class $cell = $row->addCell(new TLabel('Itens')); $cell->colspan = 4; $row = $table_itens->addRow(); $row->addCell(new TLabel('Item:')); $box = new THBox(); $box->add($numeroItem); $box->add($descricaoSumaria)->style = 'width : 75%;display:inline-block;'; $box->style = 'width : 600px'; $row->addCell($box); //->style = 'width : 85%'; $table_itens->addRowSet($item_id); $table_itens->addRowSet(new TLabel('Preço:'), $valorUnitario); $table_itens->addRowSet(new TLabel('Quantidade:'), $quantidade); //$table_itens->addRowSet(new TLabel('Prazo de entrega:'), $prazoEntrega); //$table_itens->addRowSet(new TLabel('Justificativa:'), $justificativa); $row = $table_itens->addRow(); $row->class = 'tformaction'; $row->addCell($addItem)->colspan = 2; parent::include_css('app/resources/custom-table.css'); $this->datagrid = new TDataGrid(); $this->datagrid->style = 'width: 100%'; $this->datagrid->class = 'tdatagrid_table customized-table'; $this->datagrid->setHeight(175); $this->datagrid->makeScrollable(); $this->datagrid->disableDefaultClick(); $GnumeroItem = new TDataGridColumn('numeroItem', 'Item', 'center', 50); $GdescricaoSumaria = new TDataGridColumn('descricaoSumaria', 'Descrição', 'left', 230); $Gquantidade = new TDataGridColumn('quantidade', 'Quantidade', 'right', 110); $GvalorUnitario = new TDataGridColumn('valorUnitario', 'Preço', 'right', 110); $Gtotal = new TDataGridColumn('total', 'Total', 'right', 160); //transformers $GvalorUnitario->setTransformer(array($this, 'formatValor')); $Gtotal->setTransformer(array($this, 'formatValor')); $edit = new TDataGridAction(array($this, 'onEditItem')); $edit->setLabel('Editar'); $edit->setImage('ico_edit.png'); $edit->setField('numeroItem'); $delete = new TDataGridAction(array($this, 'onDeleteItem')); $delete->setLabel('Deletar'); $delete->setImage('ico_delete.png'); $delete->setField('numeroItem'); $this->datagrid->addAction($edit); $this->datagrid->addAction($delete); $this->datagrid->addColumn($GnumeroItem); $this->datagrid->addColumn($GdescricaoSumaria); $this->datagrid->addColumn($Gquantidade); $this->datagrid->addColumn($GvalorUnitario); $this->datagrid->addColumn($Gtotal); $this->datagrid->createModel(); $this->form_cessao->setFields(array($numeroSRP, $nome, $numeroProcessoOrigem, $uasg, $validadeAta, $numeroCessao, $campusID, $campusNome, $emissao, $new, $save, $list)); $this->form_itens->setFields(array($item_id, $numeroItem, $descricaoSumaria, $valorUnitario, $quantidade, $addItem)); $hbox = new THBox(); $hbox->add($save); $hbox->add($new); $hbox->add($list); $table_grid = new TTable(); $table_grid->style = 'width: 100%;border-spacing: 0px;'; $table_grid->addRowSet($this->datagrid); $row = $table_grid->addRow(); $row->class = 'tformaction'; // CSS class $row->addCell($hbox)->colspan = 2; $vbox = new TVBox(); $vbox->add($this->form_cessao); $vbox->add($this->form_itens); $vbox->add($table_grid); $vbox->add(new TLabel(' ')); parent::add($vbox); }