Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cnpjEmitente"></param>
        /// <param name="numeroLote"></param>
        /// <param name="sequenciaEvento"></param>
        /// <param name="chaveAcesso"></param>
        /// <param name="protocolo"></param>
        /// <param name="justificativa"></param>
        /// <returns></returns>
        public RetornoRecepcaoEvento CancelarNFe(string cnpjEmitente, int numeroLote, short sequenciaEvento, string chaveAcesso,
                                                 string protocolo, string justificativa)
        {
            var servicoNFe = new ServicosNFe(ConfiguracaoServico.Instancia);

            return(servicoNFe.RecepcaoEventoCancelamento(numeroLote, sequenciaEvento, protocolo, chaveAcesso, justificativa, cnpjEmitente));
        }
Пример #2
0
        private void BtnCancelarNFe_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Cancelar NFe

                var idlote = Funcoes.InpuBox(this, "Cancelar NFe", "Identificador de controle do Lote de envio:");
                if (String.IsNullOrEmpty(idlote))
                {
                    throw new Exception("A Id do Lote deve ser informada!");
                }

                var sequenciaEvento = Funcoes.InpuBox(this, "Cancelar NFe", "Número sequencial do evento:");
                if (String.IsNullOrEmpty(sequenciaEvento))
                {
                    throw new Exception("O número sequencial deve ser informado!");
                }

                var protocolo = Funcoes.InpuBox(this, "Cancelar NFe", "Protocolo de Autorização da NFe:");
                if (String.IsNullOrEmpty(protocolo))
                {
                    throw new Exception("O protocolo deve ser informado!");
                }

                var chave = Funcoes.InpuBox(this, "Cancelar NFe", "Chave da NFe:");
                if (String.IsNullOrEmpty(chave))
                {
                    throw new Exception("A Chave deve ser informada!");
                }
                if (chave.Length != 44)
                {
                    throw new Exception("Chave deve conter 44 caracteres!");
                }

                var justificativa = Funcoes.InpuBox(this, "Cancelar NFe", "Justificativa");
                if (String.IsNullOrEmpty(justificativa))
                {
                    throw new Exception("A justificativa deve ser informada!");
                }

                var servicoNFe          = new ServicosNFe(_configuracoes.CfgServico);
                var cpfcnpj             = String.IsNullOrEmpty(_configuracoes.Emitente.CNPJ) ? _configuracoes.Emitente.CPF : _configuracoes.Emitente.CNPJ;
                var retornoCancelamento = servicoNFe.RecepcaoEventoCancelamento(Convert.ToInt16(idlote), Convert.ToInt16(sequenciaEvento), protocolo, chave, justificativa, cpfcnpj);
                TrataRetorno(retornoCancelamento);

                #endregion
            }
            catch (Exception ex)
            {
                if (!String.IsNullOrEmpty(ex.Message))
                {
                    Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
                }
            }
        }
        /// <summary>
        /// Responsavel de Cancelar NFe Emitida
        /// </summary>
        /// <param name="cFgServico"></param>
        /// <param name="cnpjEmitente"></param>
        /// <param name="numeroLote"></param>
        /// <param name="sequenciaEvento"></param>
        /// <param name="chaveAcesso"></param>
        /// <param name="protocolo"></param>
        /// <param name="justificativa"></param>
        /// <returns></returns>
        public RetornoRecepcaoEvento CancelarNFe(string cnpjEmitente, int numeroLote, short sequenciaEvento, string chaveAcesso,
                                                 string protocolo, string justificativa, ConfiguracaoServico cFgServico)
        {
            var servicoNFe   = new ServicosNFe(cFgServico);
            var retornoEnvio = servicoNFe.RecepcaoEventoCancelamento(numeroLote, sequenciaEvento, protocolo, chaveAcesso, justificativa, cnpjEmitente);

            foreach (var evento in retornoEnvio.ProcEventosNFe)
            {
                var proceventoXmlString = evento.ObterXmlString();

                if (evento.retEvento.infEvento.cStat == 135 | evento.retEvento.infEvento.cStat == 155)
                {
                    //Salva procEventoNFe
                    this.SalvarXmlArquivo(evento.retEvento.infEvento.chNFe + "-canc", proceventoXmlString, cFgServico.tpAmb);
                }
            }

            return(retornoEnvio);
        }