Example #1
0
 function onImportFile()
 {
     $data = $this->form->getData();
     $this->importacao = new Importar();
     $this->importacao->loadFile($data->file);
     $this->importacao->setActiveRow(3);
     try {
         TTransaction::open('saciq');
         $criteria = new TCriteria();
         $criteria->add(new TFilter('numeroSRP', '=', $this->importacao->getNroSRP()));
         $criteria->add(new TFilter('numeroIRP', '=', $this->importacao->getNroIRP()));
         $criteria->add(new TFilter('numeroProcesso', '=', $this->importacao->getNumeroProcesso()));
         $criteria->add(new TFilter('uasg', '=', $this->importacao->getUasgGerenciadora()));
         $criteria->add(new TFilter('validade', '=', $this->importacao->getValidadeAta()));
         $repositorySrp = new TRepository('Srp');
         $count = $repositorySrp->count($criteria);
         if ($count > 0) {
             $RepSRP = $repositorySrp->load($criteria);
             $RepSRP[0]->delete();
         }
         $srp = null;
         while (!$this->importacao->eof()) {
             if (!$this->importacao->isValidRow()) {
                 $this->importacao->nextRow();
                 continue;
             }
             $natureza = $this->LoadObjectByField('Natureza', 'descricao', $this->importacao->getNaturezaDespesa());
             if (!isset($natureza)) {
                 $natureza = new Natureza();
                 $natureza->descricao = $this->importacao->getNaturezaDespesa();
                 $natureza->store();
             }
             $subelemento = $this->LoadObjectByField('Subelemento', 'descricao', $this->importacao->getDescricaoSubElemento());
             if (!isset($subelemento)) {
                 $subelemento = new Subelemento();
                 $subelemento->id = $this->importacao->getNumeroSubElemento();
                 $subelemento->descricao = $this->importacao->getDescricaoSubElemento();
                 $subelemento->store();
             }
             $fornecedor = $this->LoadObjectByField('Fornecedor', 'cnpj', $this->importacao->getCNPJ());
             if (!isset($fornecedor)) {
                 $fornecedor = new Fornecedor();
                 $fornecedor->nome = $this->importacao->getFornecedor();
                 $fornecedor->cnpj = $this->importacao->getCNPJ();
                 $fornecedor->store();
             }
             if (!isset($srp)) {
                 $srp = new Srp();
                 $srp->numeroSRP = $this->importacao->getNroSRP();
                 $srp->numeroIRP = $this->importacao->getNroIRP();
                 $srp->numeroProcesso = $this->importacao->getNumeroProcesso();
                 $srp->uasg = $this->importacao->getUasgGerenciadora();
                 $srp->validade = $this->importacao->getValidadeAta();
                 $srp->nome = $this->importacao->getNomeProcesso();
                 $srp->natureza = $natureza;
             }
             $item = new Item();
             $item->numeroItem = $this->importacao->getItem();
             $item->descricaoSumaria = $this->importacao->getDescricaoSumaria();
             $item->descricaoCompleta = $this->importacao->getDescricaoCompleta();
             $item->descricaoPosLicitacao = $this->importacao->getDescricaoPosLicitacao();
             $item->unidadeMedida = $this->importacao->getUnidadeDeMedida();
             $item->marca = $this->importacao->getMarca();
             $item->valorUnitario = $this->importacao->getValorUnitarioLicitado();
             $item->quantidadeDisponivel = $this->importacao->getOrgao(CAMPUS);
             $item->estoqueDisponivel = $item->quantidadeDisponivel;
             $item->fabricante = $this->importacao->getFabricante();
             $item->fornecedor = $fornecedor;
             $item->subelemento = $subelemento;
             $srp->addItem($item);
             $this->importacao->nextRow();
         }
         $srp->store();
         new TMessage('info', 'Planilha importada com sucesso');
         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();
     }
     $this->notebook->setCurrentPage(0);
     $this->form->setData($data);
     $this->step->select('Seleção');
 }
Example #2
0
 /**
  * method onInlineEdit()
  * Inline record editing
  * @param $param Array containing:
  *              key: object ID value
  *              field name: object attribute to be updated
  *              value: new attribute content 
  */
 function onInlineEdit($param)
 {
     try {
         // get the parameter $key
         $field = $param['field'];
         $key = $param['key'];
         $value = $param['value'];
         TTransaction::open('saciq');
         // open a transaction with database
         $object = new Fornecedor($key);
         // instantiates the Active Record
         $object->{$field} = $value;
         $object->store();
         // update the object in the database
         TTransaction::close();
         // close the transaction
         $this->onReload($param);
         // reload the listing
         new TMessage('info', "Record Updated");
     } 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();
     }
 }