Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- eNotasGW::configure(array(
- 'apiKey' => '<api key>'
- ));
- $empresaId = 'a9f9d282-fdb9-4259-a7b8-2f19be4da06d';
- try {
- $nfeId = 'ab765f39-a2e0-4c4b-88b4-4b6b4a2baace';
- eNotasGW::$NFeServicoApi->cancelar($empresaId, $nfeId);
- /** Quando é cancelada a Nota Fiscal, o status é atualizado para Nota Cancelada. */
- $this->Nfse->NfStatus->contain();
- $options = array('conditions' => array('NfStatus.status' => 'Nota Cancelada', 'NfStatus.group_id' => $this->Session->read('Group.id')));
- $nfStatus = $this->Nfse->NfStatus->find('first', $options);
- /** Atualiza no banco de dados com o id da nota inserida e novo Status da Nota (Nota Cancelada) no sistema. */
- $this->Nfse->id = $id;
- $this->Nfse->save(array('enotas_nfse_id' => $nfeId, 'nf_status_id' => $nfStatus['NfStatus']['id']));
- $this->Session->setFlash(__('A Nota Fiscal de Serviço foi cancelada.'), 'flash_sucess');
- $this->redirect(array('action' => 'index'));
- /**
- //descomentar caso não possua o id único e queira efetuar o cancelamento pelo id externo
- $idExterno = '1';
- eNotasGW::$NFeApi->cancelarPorIdExterno($empresaId, $idExterno);
- */
- } catch (Exceptions\invalidApiKeyException $ex) {
- $this->Session->setFlash(__('Erro de autenticação: ' . $ex->getMessage()), 'flash_error');
- $this->redirect(array('action' => 'index'));
- } catch (Exceptions\unauthorizedException $ex) {
- $this->Session->setFlash(__('Acesso negado: ' . $ex->getMessage()), 'flash_error');
- $this->redirect(array('action' => 'index'));
- } catch (Exceptions\apiException $ex) {
- $this->Session->setFlash(__('Erro de validação: ' . $ex->getMessage()), 'flash_error');
- $this->redirect(array('action' => 'index'));
- } catch (Exceptions\requestException $ex) {
- $msg = 'Erro na requisição web: ' . $ex->getMessage()
- . 'Requested url: ' . $ex->requestedUrl
- . '</br>'
- . 'Response Code: ' . $ex->getCode()
- . '</br>'
- . 'Message: ' . $ex->getMessage()
- . '</br>'
- . 'Response Body: ' . $ex->responseBody;
- $this->Session->setFlash(__($msg), 'flash_error');
- $this->redirect(array('action' => 'index'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement