Example #1
0
        internal static TNFeInfNFeIde GetIdentificacao(NotaFiscal notaFiscal)
        {
            var ide = new TNFeInfNFeIde();

            ide.cUF      = TCodUfIBGEConversor.ToTCodUfIBGE(notaFiscal.Identificacao.UF);
            ide.nNF      = notaFiscal.Identificacao.Numero;
            ide.cNF      = notaFiscal.Identificacao.Codigo;
            ide.natOp    = notaFiscal.Identificacao.NaturezaOperacao;
            ide.mod      = (TMod)(int)notaFiscal.Identificacao.Modelo;
            ide.serie    = notaFiscal.Identificacao.Serie.ToString();
            ide.dhEmi    = notaFiscal.Identificacao.DataHoraEmissao.ToString("yyyy-MM-ddTHH:mm:sszzz");
            ide.tpNF     = (TNFeInfNFeIdeTpNF)(int)notaFiscal.Identificacao.TipoOperacao;
            ide.idDest   = (TNFeInfNFeIdeIdDest)(int)notaFiscal.Identificacao.OperacaoDestino;
            ide.cMunFG   = notaFiscal.Identificacao.CodigoMunicipio;
            ide.tpImp    = (TNFeInfNFeIdeTpImp)(int)notaFiscal.Identificacao.FormatoImpressao;
            ide.tpEmis   = (TNFeInfNFeIdeTpEmis)(int)notaFiscal.Identificacao.TipoEmissao;
            ide.tpAmb    = (TAmb)(int)notaFiscal.Identificacao.Ambiente;
            ide.finNFe   = (TFinNFe)(int)notaFiscal.Identificacao.FinalidadeEmissao;
            ide.indFinal = (TNFeInfNFeIdeIndFinal)(int)notaFiscal.Identificacao.FinalidadeConsumidor;
            ide.indPres  = (TNFeInfNFeIdeIndPres)(int)notaFiscal.Identificacao.PresencaComprador;
            ide.procEmi  = (TProcEmi)(int)notaFiscal.Identificacao.ProcessoEmissao;
            ide.verProc  = notaFiscal.Identificacao.VersaoAplicativo;
            ide.cDV      = notaFiscal.Identificacao.DigitoVerificador.ToString();

            if (notaFiscal.Identificacao.TipoEmissao == TipoEmissao.ContigenciaNfce ||
                notaFiscal.Identificacao.TipoEmissao == TipoEmissao.FsDa)
            {
                ide.dhCont = notaFiscal.Identificacao.DataHoraEntradaContigencia.ToString("yyyy-MM-ddTHH:mm:sszzz");
                ide.xJust  = notaFiscal.Identificacao.JustificativaContigencia;
            }

            return(ide);
        }
Example #2
0
        public static bool ExecutarConsultaStatus(CodigoUfIbge codigoUF, Ambiente ambiente, X509Certificate2 certificado, Modelo modelo)
        {
            XmlNode node = null;

            try
            {
                var parametro = new TConsStatServ();
                parametro.cUF    = TCodUfIBGEConversor.ToTCodUfIBGE(codigoUF);
                parametro.tpAmb  = ambiente == Ambiente.Homologacao ? TAmb.Item2 : TAmb.Item1;
                parametro.versao = "4.00";
                parametro.xServ  = TConsStatServXServ.STATUS;

                string nFeNamespaceName = "http://www.portalfiscal.inf.br/nfe";
                string parametroXML     = XmlUtil.Serialize(parametro, nFeNamespaceName);

                XmlDocument doc    = new XmlDocument();
                XmlReader   reader = XmlReader.Create(new StringReader(parametroXML));
                reader.MoveToContent();

                node = doc.ReadNode(reader);

                string endpoint = "";

                if (ambiente == Ambiente.Homologacao)
                {
                    if (modelo == Modelo.Modelo55)
                    {
                        endpoint = "NfeStatusServico2Hom";
                    }
                    else
                    {
                        endpoint = "NfceStatusServico2Hom";
                    }
                }
                else
                {
                    if (modelo == Modelo.Modelo55)
                    {
                        endpoint = "NfeStatusServico2Prod";
                    }
                    else
                    {
                        endpoint = "NfceStatusServico2Prod";
                    }
                }

                var soapClient = new NfeStatusServico4SoapClient(endpoint);
                soapClient.ClientCredentials.ClientCertificate.Certificate = certificado;

                XmlNode result = soapClient.nfeStatusServicoNF(node);

                var retorno = (XmlSchemas.NfeStatusServico2.Retorno.TRetConsStatServ)XmlUtil.Deserialize <XmlSchemas.NfeStatusServico2.Retorno.TRetConsStatServ>(result.OuterXml);

                return(retorno.cStat == "107");
            }
            catch (Exception e)
            {
                log.Error(e);
                return(false);
            }
        }