protected override void TratarRetornoConsultarNFSe(RetornoConsultarNFSe retornoWebservice, NotaServicoCollection notas)
        {
            // Analisa mensagem de retorno
            var xmlRet = XDocument.Parse(retornoWebservice.XmlRetorno);

            MensagemErro(retornoWebservice, xmlRet.ElementAnyNs("esConsultarNfseResposta"), "mensagemRetorno");
            if (retornoWebservice.Erros.Count > 0)
            {
                return;
            }

            var elementRoot = xmlRet.ElementAnyNs("esConsultarNfseResposta");
            var listaNfse   = elementRoot.ElementAnyNs("listaNfse");

            if (listaNfse == null)
            {
                retornoWebservice.Erros.Add(new Evento {
                    Codigo = "0", Descricao = "Lista de NFSe não encontrada! (listaNfse)"
                });
                return;
            }

            var notasServico = new List <NotaServico>();

            foreach (var nfse in listaNfse.ElementsAnyNs("nfse"))
            {
                var nota = new NotaServico(Configuracoes);
                nota.IdentificacaoNFSe.Chave       = nfse?.ElementAnyNs("cdAutenticacao")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoNFSe.Numero      = nfse?.ElementAnyNs("nrNfse")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoRps.Numero       = nfse?.ElementAnyNs("nrRps")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoNFSe.DataEmissao = nfse.ElementAnyNs("dtEmissaoNfs")?.GetValue <DateTime>() ?? DateTime.MinValue;
                nota.Situacao = SituacaoNFSeRps.Normal;

                var infoCancelamento = nfse.ElementAnyNs("cancelamento");
                if (infoCancelamento != null)
                {
                    nota.Cancelamento.DataHora           = infoCancelamento.ElementAnyNs("dtCancelamento")?.GetValue <DateTime>() ?? DateTime.MinValue;
                    nota.Cancelamento.MotivoCancelamento = infoCancelamento?.ElementAnyNs("dsCancelamento")?.GetValue <string>() ?? string.Empty;
                    nota.Situacao = SituacaoNFSeRps.Cancelado;
                }

                notas.Add(nota);
                notasServico.Add(nota);
            }

            retornoWebservice.Notas   = notasServico.ToArray();
            retornoWebservice.Sucesso = true;
        }
示例#2
0
        protected override XElement WriteTomadorRps(NotaServico nota)
        {
            var tomador = new XElement("Tomador");

            var ideTomador = new XElement("IdentificacaoTomador");

            tomador.Add(ideTomador);

            var cpfCnpjTomador = new XElement("CpfCnpj");

            ideTomador.Add(cpfCnpjTomador);

            cpfCnpjTomador.AddChild(AdicionarTagCNPJCPF("", "Cpf", "Cnpj", nota.Tomador.CpfCnpj));

            ideTomador.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipal", 1, 15, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoMunicipal));

            tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "RazaoSocial", 1, 115, Ocorrencia.NaoObrigatoria, nota.Tomador.RazaoSocial));

            if (!nota.Tomador.Endereco.Logradouro.IsEmpty() || !nota.Tomador.Endereco.Numero.IsEmpty() ||
                !nota.Tomador.Endereco.Complemento.IsEmpty() || !nota.Tomador.Endereco.Bairro.IsEmpty() ||
                nota.Tomador.Endereco.CodigoMunicipio > 0 || !nota.Tomador.Endereco.Uf.IsEmpty() ||
                !nota.Tomador.Endereco.Cep.IsEmpty())
            {
                var endereco = new XElement("Endereco");
                tomador.Add(endereco);

                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Endereco", 1, 125, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Logradouro));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Numero", 1, 10, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Numero));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Complemento", 1, 60, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Complemento));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Bairro", 1, 60, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Bairro));
                endereco.AddChild(AdicionarTag(TipoCampo.Int, "", "Cidade", 7, 7, Ocorrencia.MaiorQueZero, nota.Tomador.Endereco.CodigoMunicipio));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Estado", 2, 2, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Uf));
                endereco.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "Cep", 8, 8, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Cep));
            }

            if (!nota.Tomador.DadosContato.DDD.IsEmpty() || !nota.Tomador.DadosContato.Telefone.IsEmpty() ||
                !nota.Tomador.DadosContato.Email.IsEmpty())
            {
                var contato = new XElement("Contato");
                tomador.Add(contato);

                contato.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "Telefone", 1, 11, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.DDD + nota.Tomador.DadosContato.Telefone));
                contato.AddChild(AdicionarTag(TipoCampo.Str, "", "Email", 1, 80, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));
            }

            return(tomador);
        }
        /// <inheritdoc />
        protected override void LoadPrestador(NotaServico nota, XElement rootNFSe)
        {
            // Endereco Prestador
            var prestadorServico = rootNFSe.ElementAnyNs("PrestadorServico");

            if (prestadorServico == null)
            {
                return;
            }

            nota.Prestador.RazaoSocial  = prestadorServico.ElementAnyNs("RazaoSocial")?.GetValue <string>() ?? string.Empty;
            nota.Prestador.NomeFantasia = prestadorServico.ElementAnyNs("NomeFantasia")?.GetValue <string>() ?? string.Empty;

            var indPrestador = prestadorServico.ElementAnyNs("IdentificacaoPrestador");

            if (indPrestador != null)
            {
                nota.Prestador.CpfCnpj            = indPrestador.ElementAnyNs("CpfCnpj")?.GetCPF_CNPJ();
                nota.Prestador.InscricaoMunicipal = indPrestador.ElementAnyNs("InscricaoMunicipal")?.GetValue <string>() ?? string.Empty;
            }

            // Endereco Prestador
            var enderecoPrestador = prestadorServico.ElementAnyNs("Endereco");

            if (enderecoPrestador != null)
            {
                nota.Prestador.Endereco.Logradouro      = enderecoPrestador.ElementAnyNs("Endereco")?.GetValue <string>() ?? string.Empty;
                nota.Prestador.Endereco.Numero          = enderecoPrestador.ElementAnyNs("Numero")?.GetValue <string>() ?? string.Empty;
                nota.Prestador.Endereco.Complemento     = enderecoPrestador.ElementAnyNs("Complemento")?.GetValue <string>() ?? string.Empty;
                nota.Prestador.Endereco.Bairro          = enderecoPrestador.ElementAnyNs("Bairro")?.GetValue <string>() ?? string.Empty;
                nota.Prestador.Endereco.CodigoMunicipio = enderecoPrestador.ElementAnyNs("CodigoMunicipio")?.GetValue <int>() ?? 0;
                nota.Prestador.Endereco.Uf  = enderecoPrestador.ElementAnyNs("Uf")?.GetValue <string>() ?? string.Empty;
                nota.Prestador.Endereco.Cep = enderecoPrestador.ElementAnyNs("Cep")?.GetValue <string>() ?? string.Empty;
            }

            // Contato Prestador
            var contatoPrestador = prestadorServico.ElementAnyNs("Contato");

            if (contatoPrestador == null)
            {
                return;
            }

            nota.Prestador.DadosContato.Telefone = contatoPrestador.ElementAnyNs("Telefone")?.GetValue <string>() ?? string.Empty;
            nota.Prestador.DadosContato.Email    = contatoPrestador.ElementAnyNs("Email")?.GetValue <string>() ?? string.Empty;
        }
        protected override XElement WritePrestador(NotaServico nota)
        {
            var prestador = new XElement("PrestadorServico");

            prestador.AddChild(AdicionarTag(TipoCampo.Str, "", "RazaoSocial", 1, 150, Ocorrencia.Obrigatoria, nota.Prestador.RazaoSocial));
            prestador.AddChild(AdicionarTag(TipoCampo.Str, "", "NomeFantasia", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.NomeFantasia));

            var indPrestador = new XElement("IdentificacaoPrestador");

            prestador.AddChild(indPrestador);

            var cpfCNPJ = new XElement("CpfCnpj");

            indPrestador.AddChild(cpfCNPJ);

            cpfCNPJ.AddChild(AdicionarTagCNPJCPF("", "Cpf", "Cnpj", nota.Prestador.CpfCnpj));
            indPrestador.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipal", 1, 15, Ocorrencia.NaoObrigatoria, nota.Prestador.InscricaoMunicipal));

            var endereco = new XElement("Endereco");

            prestador.AddChild(endereco);

            endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Endereco", 1, 125, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Logradouro));
            endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Numero", 1, 10, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Numero));
            endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Complemento", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Complemento));
            endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Bairro", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Bairro));
            endereco.AddChild(AdicionarTag(TipoCampo.Int, "", "CodigoMunicipio", 7, 7, Ocorrencia.MaiorQueZero, nota.Prestador.Endereco.CodigoMunicipio));
            endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Uf", 2, 2, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Uf));
            endereco.AddChild(AdicionarTag(TipoCampo.Int, "", "CodigoPais", 4, 4, Ocorrencia.MaiorQueZero, nota.Prestador.Endereco.CodigoPais));
            endereco.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "Cep", 8, 8, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Cep));

            if (!nota.Prestador.DadosContato.Telefone.IsEmpty() ||
                !nota.Prestador.DadosContato.Email.IsEmpty())
            {
                var contato = new XElement("contato");
                prestador.AddChild(contato);

                contato.AddChild(AdicionarTag(TipoCampo.Str, "", "Telefone", 1, 20, Ocorrencia.NaoObrigatoria, nota.Prestador.DadosContato.Telefone));
                contato.AddChild(AdicionarTag(TipoCampo.Str, "", "Email", 1, 80, Ocorrencia.NaoObrigatoria, nota.Prestador.DadosContato.Email));
            }

            return(prestador);
        }
        protected override XElement WriteRps(NotaServico nota)
        {
            var rootRps = new XElement("Rps");

            var infServico = new XElement("InfDeclaracaoPrestacaoServico", new XAttribute("Id", $"R{nota.IdentificacaoRps.Numero.OnlyNumbers()}"));

            rootRps.Add(infServico);

            infServico.Add(WriteRpsRps(nota));

            infServico.AddChild(AdicionarTag(TipoCampo.Dat, "", "Competencia", 10, 10, Ocorrencia.Obrigatoria, nota.Competencia));

            infServico.AddChild(WriteServicosRps(nota));
            infServico.AddChild(WritePrestadorRps(nota));
            infServico.AddChild(WriteTomadorRps(nota));
            infServico.AddChild(WriteIntermediarioRps(nota));
            infServico.AddChild(WriteConstrucaoCivilRps(nota));

            string regimeEspecialTributacao;
            string optanteSimplesNacional;

            if (nota.RegimeEspecialTributacao == RegimeEspecialTributacao.SimplesNacional)
            {
                regimeEspecialTributacao = "6";
                optanteSimplesNacional   = "1";
            }
            else
            {
                regimeEspecialTributacao = ((int)nota.RegimeEspecialTributacao).ToString();
                optanteSimplesNacional   = "2";
            }

            if (nota.RegimeEspecialTributacao != RegimeEspecialTributacao.Nenhum)
            {
                infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "RegimeEspecialTributacao", 1, 1, Ocorrencia.NaoObrigatoria, regimeEspecialTributacao));
            }

            infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "OptanteSimplesNacional", 1, 1, Ocorrencia.Obrigatoria, optanteSimplesNacional));
            infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "IncentivoFiscal", 1, 1, Ocorrencia.Obrigatoria, nota.IncentivadorCultural == NFSeSimNao.Sim ? 1 : 2));

            return(rootRps);
        }
示例#6
0
        protected override XElement WriteServicosValoresRps(NotaServico nota)
        {
            var servico = new XElement("Servico");
            var valores = new XElement("Valores");

            servico.AddChild(valores);

            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorServicos", 1, 15, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorServicos));

            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorDeducoes", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorDeducoes));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorPis", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorPis));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCofins", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorCofins));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorInss", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorInss));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIr", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIr));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCsll", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorCsll));

            valores.AddChild(AdicionarTag(TipoCampo.Int, "", "IssRetido", 1, 1, Ocorrencia.Obrigatoria, nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ? 1 : 2));

            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIss", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIss));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIssRetido", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIssRetido));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "OutrasRetencoes", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.OutrasRetencoes));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "BaseCalculo", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.BaseCalculo));

            // Valor Percentual - Exemplos: 1% => 1.00   /   25,5% => 25.5   /   100% => 100
            valores.AddChild(AdicionarTag(TipoCampo.De4, "", "Aliquota", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.Aliquota));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorLiquidoNfse", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorLiquidoNfse));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "DescontoIncondicionado", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.DescontoIncondicionado));
            valores.AddChild(AdicionarTag(TipoCampo.De2, "", "DescontoCondicionado", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.DescontoCondicionado));

            servico.AddChild(AdicionarTag(TipoCampo.Str, "", "ItemListaServico", 1, 5, Ocorrencia.Obrigatoria, nota.Servico.ItemListaServico));

            servico.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "CodigoCnae", 1, 7, Ocorrencia.NaoObrigatoria, nota.Servico.CodigoCnae));

            servico.AddChild(AdicionarTag(TipoCampo.Str, "", "CodigoTributacaoMunicipio", 1, 20, Ocorrencia.NaoObrigatoria, nota.Servico.CodigoTributacaoMunicipio));
            servico.AddChild(AdicionarTag(TipoCampo.Str, "", "Discriminacao", 1, 2000, Ocorrencia.Obrigatoria, nota.Servico.Discriminacao));
            servico.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "MunicipioPrestacaoServico", 1, 7, Ocorrencia.Obrigatoria, nota.Servico.CodigoMunicipio));

            return(servico);
        }
示例#7
0
        /// <inheritdoc />
        protected override void LoadIntermediario(NotaServico nota, XElement rootNFSe)
        {
            // Intermediario
            var rootIntermediario = rootNFSe.ElementAnyNs("Intermediario");

            if (rootIntermediario == null)
            {
                return;
            }

            nota.Intermediario.RazaoSocial = rootIntermediario.ElementAnyNs("RazaoSocial")?.GetValue <string>() ?? string.Empty;

            var intermediarioIdentificacao = rootIntermediario.ElementAnyNs("IdentificacaoIntermediario");

            if (intermediarioIdentificacao == null)
            {
                return;
            }

            nota.Intermediario.CpfCnpj            = intermediarioIdentificacao.ElementAnyNs("CpfCnpj")?.GetCPF_CNPJ();
            nota.Intermediario.InscricaoMunicipal = intermediarioIdentificacao.ElementAnyNs("InscricaoMunicipal")?.GetValue <string>() ?? string.Empty;
            nota.Intermediario.CodigoMunicipio    = intermediarioIdentificacao.ElementAnyNs("CodigoMunicipio")?.GetValue <string>() ?? string.Empty;
        }
        protected override void TratarRetornoConsultarLoteRps(RetornoConsultarLoteRps retornoWebservice, NotaServicoCollection notas)
        {
            // Analisa mensagem de retorno
            var xmlRet      = XDocument.Parse(retornoWebservice.XmlRetorno);
            var rootElement = xmlRet.ElementAnyNs("esConsultarLoteRpsResposta");

            MensagemErro(retornoWebservice, rootElement, "mensagemRetorno");
            if (retornoWebservice.Erros.Count > 0)
            {
                return;
            }

            var elementRoot = xmlRet.ElementAnyNs("esConsultarLoteRpsResposta");

            var listaNfse = elementRoot.ElementAnyNs("listaNfse");

            if (listaNfse == null)
            {
                retornoWebservice.Erros.Add(new Evento {
                    Codigo = "0", Descricao = "Lista de NFSe não encontrada! (listaNfse)"
                });
                return;
            }

            foreach (var nfse in listaNfse.ElementsAnyNs("nfse"))
            {
                var nota = new NotaServico(Configuracoes);
                nota.IdentificacaoNFSe.Chave       = nfse?.ElementAnyNs("cdAutenticacao")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoNFSe.Numero      = nfse?.ElementAnyNs("nrNfse")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoRps.Numero       = nfse?.ElementAnyNs("nrRps")?.GetValue <string>() ?? string.Empty;
                nota.IdentificacaoNFSe.DataEmissao = nfse.ElementAnyNs("dtEmissaoNfs")?.GetValue <DateTime>() ?? DateTime.MinValue;

                notas.Add(nota);
            }

            retornoWebservice.Sucesso = true;
        }
示例#9
0
        protected override XElement WriteIntermediarioRps(NotaServico nota)
        {
            if (nota.Intermediario.CpfCnpj.IsEmpty())
            {
                return(null);
            }

            var intermediario    = new XElement("Intermediario");
            var ideIntermediario = new XElement("IdentificacaoIntermediario");

            intermediario.Add(ideIntermediario);

            var cpfCnpj = new XElement("CpfCnpj");

            ideIntermediario.Add(cpfCnpj);

            cpfCnpj.AddChild(AdicionarTagCNPJCPF("", "Cpf", "Cnpj", nota.Intermediario.CpfCnpj));

            ideIntermediario.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipal", 1, 15, Ocorrencia.NaoObrigatoria, nota.Intermediario.InscricaoMunicipal));
            intermediario.AddChild(AdicionarTag(TipoCampo.Str, "", "RazaoSocial", 1, 115, Ocorrencia.NaoObrigatoria, nota.Intermediario.RazaoSocial));
            intermediario.AddChild(AdicionarTag(TipoCampo.Str, "", "CodigoMunicipio", 1, 115, Ocorrencia.NaoObrigatoria, nota.Intermediario.CodigoMunicipio));

            return(intermediario);
        }
        public override string WriteXmlRps(NotaServico nota, bool identado, bool showDeclaration)
        {
            string tipoRps;

            switch (nota.IdentificacaoRps.Tipo)
            {
            case TipoRps.RPS:
                tipoRps = "RPS";
                break;

            case TipoRps.NFConjugada:
                tipoRps = "RPS-M";
                break;

            case TipoRps.Cupom:
                tipoRps = "RPS-C";
                break;

            default:
                tipoRps = "";
                break;
            }

            string tipoTributacao;

            switch (nota.TipoTributacao)
            {
            case TipoTributacao.Tributavel:
                tipoTributacao = "T";
                break;

            case TipoTributacao.ForaMun:
                tipoTributacao = "F";
                break;

            case TipoTributacao.Isenta:
                tipoTributacao = "A";
                break;

            case TipoTributacao.ForaMunIsento:
                tipoTributacao = "B";
                break;

            case TipoTributacao.Imune:
                tipoTributacao = "M";
                break;

            case TipoTributacao.ForaMunImune:
                tipoTributacao = "N";
                break;

            case TipoTributacao.Suspensa:
                tipoTributacao = "X";
                break;

            case TipoTributacao.ForaMunSuspensa:
                tipoTributacao = "V";
                break;

            case TipoTributacao.ExpServicos:
                tipoTributacao = "P";
                break;

            default:
                tipoTributacao = "";
                break;
            }

            var situacao = nota.Situacao == SituacaoNFSeRps.Normal ? "N" : "C";

            var issRetido = nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ? "true" : "false";

            // RPS
            XNamespace ns = "";

            var xmlDoc = new XDocument(new XDeclaration("1.0", "UTF-8", null));
            var rps    = new XElement(ns + "RPS");

            xmlDoc.Add(rps);

            var hashRps = GetHashRps(nota);

            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "Assinatura", 1, 2000, Ocorrencia.Obrigatoria, hashRps));

            var chaveRPS = new XElement("ChaveRPS");

            rps.Add(chaveRPS);
            chaveRPS.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "InscricaoPrestador", 1, 15, Ocorrencia.Obrigatoria, nota.Prestador.InscricaoMunicipal));
            chaveRPS.AddChild(AdicionarTag(TipoCampo.Int, "", "SerieRPS", 1, 5, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Serie));
            chaveRPS.AddChild(AdicionarTag(TipoCampo.Int, "", "NumeroRPS", 1, 15, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Numero));

            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoRPS", 1, 1, Ocorrencia.Obrigatoria, tipoRps));
            rps.AddChild(AdicionarTag(TipoCampo.Dat, "", "DataEmissao", 20, 20, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao));
            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "StatusRPS", 1, 1, Ocorrencia.Obrigatoria, situacao));
            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "TributacaoRPS", 1, 1, Ocorrencia.Obrigatoria, tipoTributacao));

            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorServicos", 1, 15, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorServicos));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorDeducoes", 1, 15, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorDeducoes));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorPIS", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorPis));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCOFINS", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorCofins));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorINSS", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorInss));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIR", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorIr));
            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCSLL", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorCsll));

            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "CodigoServico", 1, 5, Ocorrencia.Obrigatoria, nota.Servico.ItemListaServico));
            rps.AddChild(AdicionarTag(TipoCampo.De4, "", "AliquotaServicos", 1, 15, Ocorrencia.Obrigatoria, nota.Servico.Valores.Aliquota / 100));  // Valor Percentual - Exemplos: 1% => 0.01   /   25,5% => 0.255   /   100% => 1
            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "ISSRetido", 1, 4, Ocorrencia.Obrigatoria, issRetido));

            var tomadorCpfCnpj = new XElement("CPFCNPJTomador");

            rps.Add(tomadorCpfCnpj);
            tomadorCpfCnpj.AddChild(AdicionarTagCNPJCPF("", "CPF", "CNPJ", nota.Tomador.CpfCnpj));

            rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "InscricaoMunicipalTomador", 1, 8, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoMunicipal));
            rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "InscricaoEstadualTomador", 1, 19, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoEstadual));
            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "RazaoSocialTomador", 1, 115, Ocorrencia.NaoObrigatoria, nota.Tomador.RazaoSocial));

            if (!nota.Tomador.Endereco.Logradouro.IsEmpty())
            {
                var endereco = new XElement("EnderecoTomador");
                rps.AddChild(endereco);
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogradouro", 1, 3, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.TipoLogradouro));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Logradouro", 1, 125, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Logradouro));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "NumeroEndereco", 1, 10, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Numero));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplementoEndereco", 1, 10, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Complemento));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "Bairro", 1, 60, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Bairro));
                endereco.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "Cidade", 1, 7, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.CodigoMunicipio));
                endereco.AddChild(AdicionarTag(TipoCampo.Str, "", "UF", 2, 2, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Uf));
                endereco.AddChild(AdicionarTag(TipoCampo.StrNumberFill, "", "CEP", 8, 8, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Cep));
            }

            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "EmailTomador", 1, 75, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));

            if (!nota.Intermediario.CpfCnpj.IsEmpty())
            {
                var intermediarioCpfCnpj = new XElement("CPFCNPJIntermediario");
                rps.Add(intermediarioCpfCnpj);
                intermediarioCpfCnpj.AddChild(AdicionarTagCNPJCPF("", "CPF", "CNPJ", nota.Intermediario.CpfCnpj));

                rps.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipalIntermediario", 1, 8, 0, nota.Intermediario.InscricaoMunicipal));
                rps.AddChild(AdicionarTag(TipoCampo.Str, "", "RazaoSocialIntermediario", 1, 115, 0, nota.Intermediario.RazaoSocial));

                var issRetidoIntermediario = nota.Intermediario.IssRetido == SituacaoTributaria.Retencao ? "true" : "false";
                rps.AddChild(AdicionarTag(TipoCampo.Str, "", "ISSRetidoIntermediario", 1, 4, Ocorrencia.Obrigatoria, issRetidoIntermediario));
                rps.AddChild(AdicionarTag(TipoCampo.Str, "", "EmailIntermediario", 1, 75, Ocorrencia.NaoObrigatoria, nota.Intermediario.EMail));
            }

            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "Discriminacao", 1, 2000, Ocorrencia.Obrigatoria, nota.Servico.Discriminacao));

            rps.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCargaTributaria", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorCargaTributaria));
            rps.AddChild(AdicionarTag(TipoCampo.De4, "", "PercentualCargaTributaria", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaCargaTributaria / 100));
            rps.AddChild(AdicionarTag(TipoCampo.Str, "", "FonteCargaTributaria", 1, 10, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.FonteCargaTributaria));

            rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "CodigoCEI", 1, 12, Ocorrencia.NaoObrigatoria, nota.ConstrucaoCivil.CodigoCEI));
            rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "MatriculaObra", 1, 12, Ocorrencia.NaoObrigatoria, nota.ConstrucaoCivil.Matricula));
            //rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "MunicipioPrestacao", 1, 7, Ocorrencia.MaiorQueZero, nota.Servico.CodigoMunicipio));
            rps.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "NumeroEncapsulamento", 1, 7, Ocorrencia.NaoObrigatoria, nota.Material.NumeroEncapsulamento));

            return(xmlDoc.AsString(identado, showDeclaration, Encoding.UTF8));
        }
示例#11
0
        private XElement WriteTomadorRps(NotaServico nota)
        {
            string sTpDoc;

            if (!string.IsNullOrEmpty(nota.Tomador.DocTomadorEstrangeiro))
            {
                sTpDoc = "3"; // Estrangeiro
            }
            else if (nota.Tomador.CpfCnpj.IsCNPJ())
            {
                sTpDoc = "2"; // CNPJ
            }
            else
            {
                sTpDoc = "1"; // CPF
            }
            var tomador   = new XElement("tomador");
            var documento = new XElement("documento");

            documento.AddChild(AdicionarTagCNPJCPF("", "nrDocumento", "nrDocumento", nota.Tomador.CpfCnpj));
            documento.AddChild(AdicionarTag(TipoCampo.Int, "", "tpDocumento", 1, 1, Ocorrencia.Obrigatoria, sTpDoc));
            documento.AddChild(AdicionarTag(TipoCampo.Str, "", "dsDocumentoEstrangeiro", 1, 115, Ocorrencia.Obrigatoria, nota.Tomador.DocTomadorEstrangeiro));
            tomador.Add(documento);

            tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nmTomador", 1, 80, Ocorrencia.Obrigatoria, nota.Tomador.RazaoSocial));
            tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "dsEmail", 0, 80, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));

            tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nrInscricaoEstadual", 1, 20, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoEstadual));
            // tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nrInscricaoMunicipal", 1, 15, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoMunicipal));

            if (!nota.Tomador.Endereco.Logradouro.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "dsEndereco", 0, 40, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Logradouro));
            }
            if (!nota.Tomador.Endereco.Numero.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "nrEndereco", 0, 10, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Numero));
            }
            if (!nota.Tomador.Endereco.Complemento.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "dsComplemento", 0, 60, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Complemento));
            }
            if (!nota.Tomador.Endereco.Bairro.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nmBairro", 0, 25, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Bairro));
            }
            if (nota.Tomador.Endereco.CodigoMunicipio > 0)
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Int, "", "nrCidadeIbge", 7, 7, Ocorrencia.MaiorQueZero, nota.Tomador.Endereco.CodigoMunicipio));
            }
            if (!nota.Tomador.Endereco.Uf.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nmUf", 2, 2, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Uf));
            }

            if (!nota.Tomador.DocTomadorEstrangeiro.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nmCidadeEstrangeira", 1, 115, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Municipio));
            }

            if (!nota.Tomador.Endereco.Pais.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.Str, "", "nmPais", 1, 100, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Pais));
            }

            if (!nota.Tomador.Endereco.Cep.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "nrCep", 8, 8, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Cep));
            }

            if (!nota.Tomador.DadosContato.DDD.IsEmpty() || !nota.Tomador.DadosContato.Telefone.IsEmpty())
            {
                tomador.AddChild(AdicionarTag(TipoCampo.StrNumber, "", "nrTelefone", 1, 11, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.DDD + nota.Tomador.DadosContato.Telefone));
            }

            return(tomador);
        }
示例#12
0
        private XElement WriteRetencoes(NotaServico nota)
        {
            var retencoes = new XElement("retencoes");

            if (nota.Servico.Valores.ValorCofins > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlCofins", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorCofins));
            }

            if (nota.Servico.Valores.ValorCsll > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "VlCsll", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorCsll));
            }

            if (nota.Servico.Valores.ValorInss > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlInss", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorInss));
            }

            if (nota.Servico.Valores.ValorIr > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlIrrf", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorIr));
            }

            if (nota.Servico.Valores.ValorPis > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlPis", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.ValorPis));
            }

            if (nota.Servico.Valores.ValorIssRetido > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlIss", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIssRetido));
            }

            if (nota.Servico.Valores.AliquotaCofins > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlAliquotaCofins", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaCofins));
            }

            if (nota.Servico.Valores.AliquotaCsll > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlAliquotaCsll", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaCsll));
            }

            if (nota.Servico.Valores.AliquotaInss > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlAliquotaInss", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaInss));
            }

            if (nota.Servico.Valores.AliquotaIR > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlAliquotaIrrf", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaIR));
            }

            if (nota.Servico.Valores.AliquotaPis > 0)
            {
                retencoes.AddChild(AdicionarTag(TipoCampo.De2, "", "vlAliquotaPis", 1, 15, Ocorrencia.NaoObrigatoria, nota.Servico.Valores.AliquotaPis));
            }

            return(retencoes);
        }
示例#13
0
        private XElement WriteValoresServicos(NotaServico nota)
        {
            var listaServicos = new XElement("listaServicos");

            if (nota.Servico.ItensServico.Count > 0)
            {
                foreach (var servicoItem in nota.Servico.ItensServico)
                {
                    var iSerItem    = 0;
                    var iSerSubItem = 0;
                    var iAux        = int.Parse(Regex.Replace(servicoItem.ItemListaServico, "[^0-9]", "")); //Ex.: 1402, 901

                    if (iAux > 999)
                    {
                        iSerItem    = int.Parse(iAux.ToString().Substring(0, 2)); //14
                        iSerSubItem = int.Parse(iAux.ToString().Substring(2, 2)); //2
                    }
                    else
                    {
                        iSerItem    = int.Parse(iAux.ToString().Substring(0, 1)); //9
                        iSerSubItem = int.Parse(iAux.ToString().Substring(1, 2)); //1
                    }

                    var servico = new XElement("servico");
                    servico.AddChild(new XElement("nrServicoItem", iSerItem));
                    servico.AddChild(new XElement("nrServicoSubItem", iSerSubItem));
                    servico.AddChild(new XElement("vlServico", servicoItem.ValorUnitario));
                    servico.AddChild(new XElement("vlAliquota", servicoItem.Aliquota));

                    if (nota.Servico.Valores.ValorDeducoes > 0)
                    {
                        var deducao = new XElement("deducao");
                        deducao.AddChild(AdicionarTag(TipoCampo.De2, "", "vlDeducao", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorDeducoes));
                        deducao.AddChild(AdicionarTag(TipoCampo.Str, "", "dsJustificativaDeducao", 1, 115, Ocorrencia.Obrigatoria, nota.Servico.Valores.JustificativaDeducao));
                        servico.AddChild(deducao);
                    }

                    servico.AddChild(AdicionarTag(TipoCampo.De2, "", "vlBaseCalculo", 1, 15, Ocorrencia.MaiorQueZero, servicoItem.BaseCalculo));
                    servico.AddChild(AdicionarTag(TipoCampo.De2, "", "vlIssServico", 1, 15, Ocorrencia.MaiorQueZero, servicoItem.ValorIss));
                    servico.AddChild(AdicionarTag(TipoCampo.Str, "", "dsDiscriminacaoServico", 1, 15, Ocorrencia.MaiorQueZero, servicoItem.Discriminacao));
                    listaServicos.Add(servico);
                }
            }
            else
            {
                var iSerItem    = 0;
                var iSerSubItem = 0;
                var iAux        = int.Parse(Regex.Replace(nota.Servico.ItemListaServico, "[^0-9]", "")); //Ex.: 1402, 901

                if (iAux > 999)
                {
                    iSerItem    = int.Parse(iAux.ToString().Substring(0, 2)); //14
                    iSerSubItem = int.Parse(iAux.ToString().Substring(2, 2)); //2
                }
                else
                {
                    iSerItem    = int.Parse(iAux.ToString().Substring(0, 1)); //9
                    iSerSubItem = int.Parse(iAux.ToString().Substring(1, 2)); //1
                }

                var servico = new XElement("servico");
                servico.AddChild(new XElement("nrServicoItem", iSerItem));
                servico.AddChild(new XElement("nrServicoSubItem", iSerSubItem));
                servico.AddChild(new XElement("vlServico", nota.Servico.Valores.ValorServicos));
                servico.AddChild(new XElement("vlAliquota", nota.Servico.Valores.Aliquota));

                if (nota.Servico.Valores.ValorDeducoes > 0)
                {
                    var deducao = new XElement("deducao");
                    deducao.AddChild(AdicionarTag(TipoCampo.De2, "", "vlDeducao", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorDeducoes));
                    deducao.AddChild(AdicionarTag(TipoCampo.Str, "", "dsJustificativaDeducao", 1, 115, Ocorrencia.Obrigatoria, nota.Servico.Valores.JustificativaDeducao));
                    servico.AddChild(deducao);
                }

                servico.AddChild(AdicionarTag(TipoCampo.De2, "", "vlBaseCalculo", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.BaseCalculo));
                servico.AddChild(AdicionarTag(TipoCampo.De2, "", "vlIssServico", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIss));
                servico.AddChild(AdicionarTag(TipoCampo.Str, "", "dsDiscriminacaoServico", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Discriminacao));

                listaServicos.Add(servico);
            }

            return(listaServicos);
        }
示例#14
0
        /// <inheritdoc />
        protected override void LoadRps(NotaServico nota, XElement rpsRoot)
        {
            base.LoadRps(nota, rpsRoot);

            //ToDo: Ler a tag evento, informações complementares e a lista de deduções.
        }
        private XElement WriteREG30(NotaServico nota)
        {
            var reg30 = new XElement("Reg30");

            if (nota.Servico.Valores.ValorCofins > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "COFINS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaCofins.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorCofins.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorCofins);
            }

            if (nota.Servico.Valores.ValorCsll > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "CSLL"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaCsll.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorCsll.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorCsll);
            }

            if (nota.Servico.Valores.ValorInss > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "INSS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaInss.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorInss.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorInss);
            }

            if (nota.Servico.Valores.ValorIr > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "IR"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaIR.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIr.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorIr);
            }

            if (nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "ISS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaInss.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIssRetido.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorIssRetido);
            }

            if (nota.Servico.Valores.ValorPis > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "PIS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaPis.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorPis.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorPis);
            }

            return(reg30);
        }
示例#16
0
        private XElement WriteREG30(NotaServico nota)
        {
            var reg30 = new XElement("Reg30");

            if (nota.Servico.Valores.ValorCofins > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "COFINS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaCofins.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorCofins.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorCofins);
            }

            if (nota.Servico.Valores.ValorCsll > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "CSLL"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaCsll.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorCsll.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorCsll);
            }

            if (nota.Servico.Valores.ValorInss > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "INSS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaInss.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorInss.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorInss);
            }

            if (nota.Servico.Valores.ValorIr > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "IR"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaIR.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIr.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorIr);
            }

            //Não entendi ao certo, pois no manual fala isso, porém, olhando exemplos de clientes, esta tag não vai
            //if (nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao)
            //{
            //    var reg30Item = new XElement("Reg30Item");
            //    reg30.AddChild(reg30Item);

            //    reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "ISS"));
            //    reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.Aliquota.ToString("##0.00")));
            //    reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIssRetido.ToString("##0.00")));

            //    valoresTipo30.Add(nota.Servico.Valores.ValorIssRetido);
            //}

            if (nota.Servico.Valores.ValorPis > 0)
            {
                var reg30Item = new XElement("Reg30Item");
                reg30.AddChild(reg30Item);

                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoSigla", 1, 10, Ocorrencia.Obrigatoria, "PIS"));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoAliquota", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.AliquotaPis.ToString("##0.00")));
                reg30Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TributoValor", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorPis.ToString("##0.00")));

                valoresTipo30.Add(nota.Servico.Valores.ValorPis);
            }

            return(reg30);
        }
示例#17
0
 public override string WriteXmlNFSe(NotaServico nota, bool identado = true, bool showDeclaration = true)
 {
     throw new NotImplementedException("Função não implementada/suportada neste Provedor !");
 }
示例#18
0
        public override string WriteXmlRps(NotaServico nota, bool identado = true, bool showDeclaration = true)
        {
            var xmldoc  = new XDocument(new XDeclaration("1.0", "UTF-8", null));
            var notaTag = new XElement("DescricaoRps");

            xmldoc.Add(notaTag);

            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "ccm", 1, 120, Ocorrencia.Obrigatoria, Configuracoes.WebServices.Usuario));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "cnpj", 1, 14, Ocorrencia.Obrigatoria, nota.Prestador.CpfCnpj.OnlyNumbers()));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "senha", 1, 120, Ocorrencia.Obrigatoria, Configuracoes.WebServices.Senha));

            //obrigatorio apenas para simplesnacional
            if (nota.RegimeEspecialTributacao == RegimeEspecialTributacao.SimplesNacional)
            {
                notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "aliquota_simples", 1, 11, Ocorrencia.Obrigatoria, nota.Servico.Valores.Aliquota));
            }

            if (nota.NumeroLote > 0) //nao obrigatorio e pode ser utilizado para controle
            {
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "id_sis_legado", 1, 15, Ocorrencia.NaoObrigatoria, nota.NumeroLote));
            }

            notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "servico", 1, 20, Ocorrencia.Obrigatoria, nota.Servico.CodigoTributacaoMunicipio));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "situacao", 2, 2, Ocorrencia.Obrigatoria, NaturezaOperacao.Sigiss.GetValue(nota.NaturezaOperacao)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "valor", 1, 15, Ocorrencia.Obrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorServicos)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "base", 1, 15, Ocorrencia.Obrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.BaseCalculo)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "descricaoNF", 0, 2000, Ocorrencia.NaoObrigatoria, nota.Servico.Descricao.RemoveAccent()));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_tipo", 14, 14, Ocorrencia.NaoObrigatoria, nota.Tomador.Tipo)); //TipoTomador

            if (nota.Tomador.Tipo != TipoTomador.Sigiss.PFNI)
            {
                notaTag.AddChild(AdicionarTagCNPJCPF("", "tomador_cnpj", "tomador_cnpj", nota.Tomador.CpfCnpj ?? string.Empty));
            }

            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_email", 1, 120, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));
            notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "tomador_im", 1, 120, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoMunicipal.OnlyNumbers()));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_ie", 1, 120, Ocorrencia.NaoObrigatoria, nota.Tomador.InscricaoEstadual.OnlyNumbers()));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_razao", 1, 120, Ocorrencia.Obrigatoria, RetirarAcentos ? nota.Tomador.RazaoSocial.RemoveAccent() : nota.Tomador.RazaoSocial));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_endereco", 1, 120, Ocorrencia.NaoObrigatoria, RetirarAcentos ? nota.Tomador.Endereco.Logradouro.RemoveAccent() : nota.Tomador.Endereco.Logradouro));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_numero", 1, 9, Ocorrencia.NaoObrigatoria, string.IsNullOrEmpty(nota.Tomador.Endereco.Numero) ? "S/N" : nota.Tomador.Endereco.Numero));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_complemento", 1, 30, Ocorrencia.NaoObrigatoria, RetirarAcentos ? nota.Tomador.Endereco.Complemento.RemoveAccent() : nota.Tomador.Endereco.Complemento));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_bairro", 1, 50, Ocorrencia.NaoObrigatoria, RetirarAcentos ? nota.Tomador.Endereco.Bairro.RemoveAccent() : nota.Tomador.Endereco.Bairro));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_CEP", 1, 8, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.Cep.OnlyNumbers()));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_cod_cidade", 1, 10, Ocorrencia.NaoObrigatoria, nota.Tomador.Endereco.CodigoMunicipio));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "tomador_fone", 0, 15, Ocorrencia.Obrigatoria, nota.Tomador.DadosContato.DDD.OnlyNumbers() + nota.Tomador.DadosContato.Telefone.OnlyNumbers()));

            if (!string.IsNullOrEmpty(nota.IdentificacaoRps.Numero) && !string.IsNullOrEmpty(nota.IdentificacaoRps.Serie))
            {
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "rps_num", 1, 12, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Numero));
                notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "rps_serie", 1, 20, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Serie));
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "rps_dia", 1, 2, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao.Day));
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "rps_mes", 1, 2, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao.Month));
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "rps_ano", 1, 4, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao.Year));
            }

            if (nota.Tomador.Tipo == TipoTomador.Sigiss.JuridicaForaMunicipio)
            {
                notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "outro_municipio", 1, 1, Ocorrencia.Obrigatoria, nota.Servico.MunicipioIncidencia));
                if (nota.Servico.MunicipioIncidencia == 1)
                {
                    notaTag.AddChild(AdicionarTag(TipoCampo.Int, "", "cod_outro_municipio", 1, 10, Ocorrencia.Obrigatoria, nota.Servico.CodigoMunicipio));
                }
            }

            //iis retido pode acontecer em varios casos, no manual está que apenas caso for fora do município, o que está incorreto segundo contadores da região.
            if (nota.Servico.Valores.ValorIssRetido > 0)
            {
                notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "retencao_iss", 1, 15, Ocorrencia.Obrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorIssRetido)));
            }

            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "pis", 1, 15, Ocorrencia.NaoObrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorPis)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "cofins", 1, 15, Ocorrencia.NaoObrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorCofins)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "inss", 1, 15, Ocorrencia.NaoObrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorInss)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "irrf", 1, 15, Ocorrencia.NaoObrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorIr)));
            notaTag.AddChild(AdicionarTag(TipoCampo.Str, "", "csll", 1, 15, Ocorrencia.NaoObrigatoria, FormataDecimalModeloSigiss(nota.Servico.Valores.ValorCsll)));

            return(xmldoc.Root.AsString(identado, showDeclaration, Encoding.UTF8));
        }
示例#19
0
 //ToDo: Verificar o motivo de não ter geração do xml da NFSe
 public override string WriteXmlNFSe(NotaServico nota, bool identado = true, bool showDeclaration = true)
 {
     throw new NotImplementedException();
 }
        public override NotaServico LoadXml(XDocument xml)
        {
            Guard.Against <XmlException>(xml == null, "Xml invalido.");

            XElement rootDoc = xml.Root;

            Guard.Against <XmlException>(rootDoc == null, "Xml de RPS ou NFSe invalido.");

            var ret = new NotaServico();

            ret.Assinatura = rootDoc.ElementAnyNs("Assinatura")?.GetValue <string>() ?? string.Empty;

            // Nota Fiscal
            ret.IdentificacaoNFSe.Numero     = rootDoc.ElementAnyNs("ChaveNFe")?.ElementAnyNs("NumeroNFe")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoNFSe.Chave      = rootDoc.ElementAnyNs("ChaveNFe")?.ElementAnyNs("CodigoVerificacao")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.InscricaoMunicipal = rootDoc.ElementAnyNs("ChaveNFe")?.ElementAnyNs("InscricaoPrestador")?.GetValue <string>() ?? string.Empty;

            ret.IdentificacaoNFSe.DataEmissao = rootDoc.ElementAnyNs("DataEmissao")?.GetValue <DateTime>() ?? DateTime.MinValue;
            ret.NumeroLote = rootDoc.ElementAnyNs("NumeroLote")?.GetValue <int>() ?? 0;

            // RPS
            ret.IdentificacaoRps.Numero = rootDoc.ElementAnyNs("ChaveRPS")?.ElementAnyNs("NumeroRPS")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoRps.Serie  = rootDoc.ElementAnyNs("ChaveRPS")?.ElementAnyNs("SerieRPS")?.GetValue <string>() ?? string.Empty;
            if (ret.Prestador.InscricaoMunicipal == "")
            {
                ret.Prestador.InscricaoMunicipal = rootDoc.ElementAnyNs("ChaveRPS")?.ElementAnyNs("InscricaoPrestador")?.GetValue <string>() ?? string.Empty;
            }

            switch (rootDoc.ElementAnyNs("TipoRPS")?.GetValue <string>() ?? string.Empty)
            {
            case "RPS":
                ret.IdentificacaoRps.Tipo = TipoRps.RPS;
                break;

            case "RPS-M":
                ret.IdentificacaoRps.Tipo = TipoRps.NFConjugada;
                break;

            case "RPS-C":
                ret.IdentificacaoRps.Tipo = TipoRps.Cupom;
                break;
            }

            ret.IdentificacaoRps.DataEmissao = rootDoc.ElementAnyNs("DataEmissaoRPS")?.GetValue <DateTime>() ?? DateTime.MinValue;

            // Tipo da Tributação
            switch (rootDoc.ElementAnyNs("TributacaoNFe")?.GetValue <string>() ?? string.Empty)
            {
            case "T":
                ret.TipoTributacao = TipoTributacao.Tributavel;
                break;

            case "F":
                ret.TipoTributacao = TipoTributacao.ForaMun;
                break;

            case "A":
                ret.TipoTributacao = TipoTributacao.Isenta;
                break;

            case "B":
                ret.TipoTributacao = TipoTributacao.ForaMunIsento;
                break;

            case "M":
                ret.TipoTributacao = TipoTributacao.Imune;
                break;

            case "N":
                ret.TipoTributacao = TipoTributacao.ForaMunImune;
                break;

            case "X":
                ret.TipoTributacao = TipoTributacao.Suspensa;
                break;

            case "V":
                ret.TipoTributacao = TipoTributacao.ForaMunSuspensa;
                break;

            case "P":
                ret.TipoTributacao = TipoTributacao.ExpServicos;
                break;
            }

            switch (rootDoc.ElementAnyNs("StatusNFe")?.GetValue <string>() ?? string.Empty)
            {
            case "N":
                ret.Situacao = SituacaoNFSeRps.Normal;
                break;

            case "F":
                ret.Situacao = SituacaoNFSeRps.Cancelado;
                break;
            }

            ret.Servico.Discriminacao                   = rootDoc.ElementAnyNs("Discriminacao")?.GetValue <string>() ?? string.Empty;
            ret.Servico.Valores.ValorServicos           = rootDoc.ElementAnyNs("ValorServicos")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.Aliquota                = rootDoc.ElementAnyNs("AliquotaServicos")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.ValorIss                = rootDoc.ElementAnyNs("ValorISS")?.GetValue <decimal>() ?? 0;
            ret.Servico.ItemListaServico                = rootDoc.ElementAnyNs("CodigoServico")?.GetValue <string>() ?? string.Empty;
            ret.Servico.Valores.ValorCargaTributaria    = rootDoc.ElementAnyNs("ValorCargaTributaria")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.AliquotaCargaTributaria = rootDoc.ElementAnyNs("PercentualCargaTributaria")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.FonteCargaTributaria    = rootDoc.ElementAnyNs("FonteCargaTributaria")?.GetValue <string>() ?? string.Empty;
            ret.ValorCredito = rootDoc.ElementAnyNs("ValorCredito")?.GetValue <decimal>() ?? 0;

            switch (rootDoc.ElementAnyNs("ISSRetido")?.GetValue <string>() ?? string.Empty)
            {
            case "true":
                ret.Servico.Valores.IssRetido = SituacaoTributaria.Retencao;
                break;

            case "false":
                ret.Servico.Valores.IssRetido = SituacaoTributaria.Normal;
                break;
            }

            ret.Prestador.CpfCnpj = rootDoc.ElementAnyNs("CPFCNPJPrestador")?.ElementAnyNs("CNPJ")?.GetValue <string>() ?? string.Empty;
            if (ret.Prestador.CpfCnpj == "")
            {
                ret.Prestador.CpfCnpj = rootDoc.ElementAnyNs("CPFCNPJPrestador")?.ElementAnyNs("CPF")?.GetValue <string>() ?? string.Empty;
            }
            ret.Prestador.RazaoSocial = rootDoc.ElementAnyNs("RazaoSocialPrestador")?.GetValue <string>() ?? string.Empty;
            var endPrestador = rootDoc.ElementAnyNs("EnderecoPrestador");

            if (endPrestador != null)
            {
                ret.Prestador.Endereco.TipoLogradouro  = endPrestador.ElementAnyNs("TipoLogradouro")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.Logradouro      = endPrestador.ElementAnyNs("Logradouro")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.Numero          = endPrestador.ElementAnyNs("NumeroEndereco")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.Complemento     = endPrestador.ElementAnyNs("ComplementoEndereco")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.Bairro          = endPrestador.ElementAnyNs("Bairro")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.CodigoMunicipio = endPrestador.ElementAnyNs("Cidade")?.GetValue <int>() ?? 0;
                ret.Prestador.Endereco.Uf  = endPrestador.ElementAnyNs("UF")?.GetValue <string>() ?? string.Empty;
                ret.Prestador.Endereco.Cep = endPrestador.ElementAnyNs("CEP")?.GetValue <string>() ?? string.Empty;
            }

            ret.Tomador.CpfCnpj = rootDoc.ElementAnyNs("CPFCNPJTomador")?.ElementAnyNs("CNPJ")?.GetValue <string>() ?? string.Empty;
            if (ret.Tomador.CpfCnpj == "")
            {
                ret.Tomador.CpfCnpj = rootDoc.ElementAnyNs("CPFCNPJTomador")?.ElementAnyNs("CPF")?.GetValue <string>() ?? string.Empty;
            }
            ret.Tomador.RazaoSocial = rootDoc.ElementAnyNs("RazaoSocialTomador")?.GetValue <string>() ?? string.Empty;
            var endTomador = rootDoc.ElementAnyNs("EnderecoTomador");

            if (endTomador != null)
            {
                ret.Tomador.Endereco.TipoLogradouro  = endTomador.ElementAnyNs("TipoLogradouro")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.Logradouro      = endTomador.ElementAnyNs("Logradouro")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.Numero          = endTomador.ElementAnyNs("NumeroEndereco")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.Complemento     = endTomador.ElementAnyNs("ComplementoEndereco")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.Bairro          = endTomador.ElementAnyNs("Bairro")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.CodigoMunicipio = endTomador.ElementAnyNs("Cidade")?.GetValue <int>() ?? 0;
                ret.Tomador.Endereco.Uf  = endTomador.ElementAnyNs("UF")?.GetValue <string>() ?? string.Empty;
                ret.Tomador.Endereco.Cep = endTomador.ElementAnyNs("CEP")?.GetValue <string>() ?? string.Empty;
            }

            return(ret);
        }
示例#21
0
        private XElement WriteREG20(NotaServico nota)
        {
            var reg20     = new XElement("Reg20");
            var reg20Item = new XElement("Reg20Item");

            reg20.AddChild(reg20Item);

            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoNFS", 3, 3, Ocorrencia.Obrigatoria, "RPS"));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Int, "", "NumRps", 0, 0, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Numero));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SerRps", 1, 3, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Serie));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DtEmi", 0, 0, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao.ToString("dd/MM/yyyy")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "RetFonte", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ? "SIM" : "NAO"));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CodSrv", 5, 5, Ocorrencia.Obrigatoria, nota.Servico.CodigoTributacaoMunicipio));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DiscrSrv", 1, 4000, Ocorrencia.Obrigatoria, nota.Servico.Discriminacao));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlNFS", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorServicos.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlDed", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorDeducoes.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DiscrDed", 0, 4000, Ocorrencia.Obrigatoria, nota.Servico.Valores.JustificativaDeducao));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlBasCalc", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.BaseCalculo.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "AlqIss", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.Aliquota.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlIss", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIss.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlIssRet", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIssRetido.ToString("##0.00")));

            if (!string.IsNullOrEmpty(nota.Tomador.CpfCnpj))
            {
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CpfCnpTom", 14, 14, Ocorrencia.Obrigatoria, nota.Tomador.CpfCnpj.Length <= 11 ? nota.Tomador.CpfCnpj.ZeroFill(11) : nota.Tomador.CpfCnpj.ZeroFill(14)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "RazSocTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.RazaoSocial));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogtom", 1, 10, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.TipoLogradouro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "LogTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Logradouro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "NumEndTom", 1, 10, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Numero));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplEndTom", 0, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Complemento));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "BairroTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Bairro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "MunTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Municipio));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SiglaUFTom", 2, 2, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Uf));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CepTom", 8, 8, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Cep.ZeroFill(8)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "Telefone", 10, 10, Ocorrencia.Obrigatoria, (nota.Tomador.DadosContato.DDD.OnlyNumbers() + nota.Tomador.DadosContato.Telefone.OnlyNumbers()).ZeroFill(10)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipal", 1, 20, Ocorrencia.Obrigatoria, nota.Tomador.InscricaoMunicipal));

                if (
                    !string.IsNullOrEmpty(nota.EnderecoPrestacao.Logradouro) && (
                        nota.EnderecoPrestacao.Numero != nota.Tomador.Endereco.Numero ||
                        nota.EnderecoPrestacao.Cep.ZeroFill(8) != nota.Tomador.Endereco.Cep.ZeroFill(8)
                        )
                    )
                {
                    if (
                        string.IsNullOrEmpty(nota.EnderecoPrestacao.Numero) ||
                        string.IsNullOrEmpty(nota.EnderecoPrestacao.Bairro) ||
                        string.IsNullOrEmpty(nota.EnderecoPrestacao.Municipio) ||
                        string.IsNullOrEmpty(nota.EnderecoPrestacao.Uf) ||
                        string.IsNullOrEmpty(nota.EnderecoPrestacao.Cep)
                        )
                    {
                        throw new Exception("Para emissão com endereço de prestação do serviço diferente do endereço do tomador, informe os campos CEP, Logradouro, Numero, Bairro, Cidade e UF do local da prestação!");
                    }

                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogLocPre", 1, 10, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.TipoLogradouro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "LogLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Logradouro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "NumEndLocPre", 1, 10, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Numero));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplEndLocPre", 0, 60, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Complemento));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "BairroLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Bairro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "MunLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Municipio));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SiglaUFLocpre", 2, 2, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Uf));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CepLocPre", 8, 8, Ocorrencia.NaoObrigatoria, nota.EnderecoPrestacao.Cep.ZeroFill(8)));
                }

                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "Email1", 0, 120, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));
            }
            else
            {
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CpfCnpjTom", 1, 14, Ocorrencia.Obrigatoria, "CONSUMIDOR"));
            }

            if (
                nota.Servico.Valores.ValorCofins > 0 ||
                nota.Servico.Valores.ValorCsll > 0 ||
                nota.Servico.Valores.ValorInss > 0 ||
                nota.Servico.Valores.ValorIr > 0 ||
                nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ||
                nota.Servico.Valores.ValorPis > 0
                )
            {
                reg20Item.Add(WriteREG30(nota));
            }

            return(reg20);
        }
        private string GetHashRps(NotaServico nota)
        {
            string tipoTributacao;

            switch (nota.TipoTributacao)
            {
            case TipoTributacao.Tributavel:
                tipoTributacao = "T";
                break;

            case TipoTributacao.ForaMun:
                tipoTributacao = "F";
                break;

            case TipoTributacao.Isenta:
                tipoTributacao = "A";
                break;

            case TipoTributacao.ForaMunIsento:
                tipoTributacao = "B";
                break;

            case TipoTributacao.Imune:
                tipoTributacao = "M";
                break;

            case TipoTributacao.ForaMunImune:
                tipoTributacao = "N";
                break;

            case TipoTributacao.Suspensa:
                tipoTributacao = "X";
                break;

            case TipoTributacao.ForaMunSuspensa:
                tipoTributacao = "V";
                break;

            case TipoTributacao.ExpServicos:
                tipoTributacao = "P";
                break;

            default:
                tipoTributacao = "?";
                break;
            }

            var situacao  = nota.Situacao == SituacaoNFSeRps.Normal ? "N" : "C";
            var issRetido = nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ? "S" : "N";

            var indCpfCnpjTomador = "3";

            switch (nota.Tomador.CpfCnpj.Length)
            {
            case 11:
                indCpfCnpjTomador = "1";
                break;

            case 14:
                indCpfCnpjTomador = "2";
                break;
            }

            // Assinatura do RPS
            string hash = nota.Prestador.InscricaoMunicipal.PadLeft(8, '0') +
                          nota.IdentificacaoRps.Serie.PadRight(5, ' ') +
                          nota.IdentificacaoRps.Numero.PadLeft(12, '0') +
                          nota.IdentificacaoRps.DataEmissao.Year.ToString().PadLeft(4, '0') +
                          nota.IdentificacaoRps.DataEmissao.Month.ToString().PadLeft(2, '0') +
                          nota.IdentificacaoRps.DataEmissao.Day.ToString().PadLeft(2, '0') +
                          tipoTributacao +
                          situacao +
                          issRetido +
                          Convert.ToInt32(nota.Servico.Valores.ValorServicos * 100).ToString().PadLeft(15, '0') +
                          Convert.ToInt32(nota.Servico.Valores.ValorDeducoes * 100).ToString().PadLeft(15, '0') +
                          nota.Servico.ItemListaServico.PadLeft(5, '0') +
                          indCpfCnpjTomador +
                          nota.Tomador.CpfCnpj.PadLeft(14, '0');

            if (!nota.Intermediario.CpfCnpj.IsEmpty())
            {
                var indCpfCnpjIntermediario = "3";
                switch (nota.Intermediario.CpfCnpj.Length)
                {
                case 11:
                    indCpfCnpjIntermediario = "1";
                    break;

                case 14:
                    indCpfCnpjIntermediario = "2";
                    break;
                }

                var issRetidoIntermediario = nota.Intermediario.IssRetido == SituacaoTributaria.Retencao ? "S" : "N";
                hash = hash +
                       indCpfCnpjIntermediario +
                       nota.Intermediario.CpfCnpj.PadLeft(14, '0') +
                       issRetidoIntermediario;
            }

            var rsa       = (RSACryptoServiceProvider)Certificado.PrivateKey;
            var hashBytes = Encoding.ASCII.GetBytes(hash);

            byte[] signData = rsa.SignData(hashBytes, new SHA1CryptoServiceProvider());
            return(Convert.ToBase64String(signData));
        }
示例#23
0
        public override NotaServico LoadXml(XDocument xml)
        {
            Guard.Against <XmlException>(xml == null, "Xml invalido.");

            var ret        = new NotaServico(Configuracoes);
            var xmlElement = xml.ElementAnyNs("Nota");

            ret.Competencia = xmlElement.ElementAnyNs("DtEmiNf")?.GetValue <DateTime>() ?? DateTime.MinValue;

            //Dados da NFS-e
            ret.IdentificacaoNFSe.Numero      = xmlElement.ElementAnyNs("NumNf")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoNFSe.ModeloNfse  = xmlElement.ElementAnyNs("SerNf")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoNFSe.Chave       = xmlElement.ElementAnyNs("CodVernf")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoNFSe.DataEmissao = xmlElement.ElementAnyNs("DtEmiNf")?.GetValue <DateTime>() ?? DateTime.MinValue;
            ret.Situacao = SituacaoNFSeRps.Normal;

            if ((xmlElement.ElementAnyNs("SitNf")?.GetValue <string>() ?? string.Empty) == "2")
            {
                ret.Situacao = SituacaoNFSeRps.Cancelado;
                ret.Cancelamento.DataHora           = xmlElement.ElementAnyNs("DataCncNf")?.GetValue <DateTime>() ?? DateTime.MinValue;
                ret.Cancelamento.MotivoCancelamento = xmlElement.ElementAnyNs("MotivoCncNf")?.GetValue <string>() ?? string.Empty;
            }

            //Dados do RPS
            ret.IdentificacaoRps.Numero      = xmlElement.ElementAnyNs("NumRps")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoRps.Serie       = xmlElement.ElementAnyNs("SerRps")?.GetValue <string>() ?? string.Empty;
            ret.IdentificacaoRps.Tipo        = TipoRps.RPS;
            ret.IdentificacaoRps.DataEmissao = xmlElement.ElementAnyNs("DtEmiRps")?.GetValue <DateTime>() ?? DateTime.MinValue;

            //Dados do Prestador
            ret.Prestador.CpfCnpj              = xmlElement.ElementAnyNs("CpfCnpjPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.RazaoSocial          = xmlElement.ElementAnyNs("RazSocPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Logradouro  = xmlElement.ElementAnyNs("LogPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Numero      = xmlElement.ElementAnyNs("NumEndPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Complemento = xmlElement.ElementAnyNs("ComplEndPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Bairro      = xmlElement.ElementAnyNs("BairroPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Municipio   = xmlElement.ElementAnyNs("MunPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Uf          = xmlElement.ElementAnyNs("SiglaUFPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.Endereco.Cep         = xmlElement.ElementAnyNs("CepPre")?.GetValue <string>() ?? string.Empty;
            ret.Prestador.DadosContato.Email   = xmlElement.ElementAnyNs("EmailPre")?.GetValue <string>() ?? string.Empty;

            //Dados do Tomador
            ret.Tomador.CpfCnpj              = xmlElement.ElementAnyNs("CpfCnpjTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.RazaoSocial          = xmlElement.ElementAnyNs("RazSocTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Logradouro  = xmlElement.ElementAnyNs("LogTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Numero      = xmlElement.ElementAnyNs("NumEndTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Complemento = xmlElement.ElementAnyNs("ComplEndTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Bairro      = xmlElement.ElementAnyNs("BairroTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Municipio   = xmlElement.ElementAnyNs("MunTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Uf          = xmlElement.ElementAnyNs("SiglaUFTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.Endereco.Cep         = xmlElement.ElementAnyNs("CepTom")?.GetValue <string>() ?? string.Empty;
            ret.Tomador.DadosContato.Email   = xmlElement.ElementAnyNs("EMailTom")?.GetValue <string>() ?? string.Empty;

            //Dados do Serviço
            ret.Servico.CodigoTributacaoMunicipio    = xmlElement.ElementAnyNs("CodSrv")?.GetValue <string>() ?? string.Empty;
            ret.Servico.Discriminacao                = xmlElement.ElementAnyNs("DiscrSrv")?.GetValue <string>() ?? string.Empty;
            ret.Servico.Valores.ValorServicos        = xmlElement.ElementAnyNs("VlNFS")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.ValorDeducoes        = xmlElement.ElementAnyNs("VlDed")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.JustificativaDeducao = xmlElement.ElementAnyNs("DiscrDed")?.GetValue <string>() ?? string.Empty;
            ret.Servico.Valores.BaseCalculo          = xmlElement.ElementAnyNs("VlBasCalc")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.Aliquota             = xmlElement.ElementAnyNs("AlqIss")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.ValorIss             = xmlElement.ElementAnyNs("VlIss")?.GetValue <decimal>() ?? 0;
            ret.Servico.Valores.ValorIssRetido       = xmlElement.ElementAnyNs("VlIssRet")?.GetValue <decimal>() ?? 0;

            return(ret);
        }
        private XElement WriteREG20(NotaServico nota)
        {
            var reg20     = new XElement("Reg20");
            var reg20Item = new XElement("Reg20Item");

            reg20.AddChild(reg20Item);

            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoNFS", 3, 3, Ocorrencia.Obrigatoria, "RPS"));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Int, "", "NumRps", 0, 0, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Numero));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SerRps", 1, 3, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.Serie));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DtEmi", 0, 0, Ocorrencia.Obrigatoria, nota.IdentificacaoRps.DataEmissao.ToString("dd/MM/yyyy")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "RetFonte", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.IssRetido == SituacaoTributaria.Retencao ? "SIM" : "NAO"));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CodSrv", 5, 5, Ocorrencia.Obrigatoria, nota.Servico.CodigoTributacaoMunicipio));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DiscrSrv", 1, 4000, Ocorrencia.Obrigatoria, nota.Servico.Discriminacao));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlNFS", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorServicos.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlDed", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorDeducoes.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "DiscrDed", 0, 4000, Ocorrencia.Obrigatoria, nota.Servico.Valores.JustificativaDeducao));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlBasCalc", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.BaseCalculo.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "AlqIss", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.Aliquota.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlIss", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIss.ToString("##0.00")));
            reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "VlIssRet", 0, 0, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorIssRetido.ToString("##0.00")));

            if (!string.IsNullOrEmpty(nota.Tomador.CpfCnpj))
            {
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CpfCnpTom", 14, 14, Ocorrencia.Obrigatoria, nota.Tomador.CpfCnpj.Length <= 11 ? nota.Tomador.CpfCnpj.ZeroFill(11) : nota.Tomador.CpfCnpj.ZeroFill(14)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "RazSocTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.RazaoSocial));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogtom", 1, 10, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.TipoLogradouro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "LogTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Logradouro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "NumEndTom", 1, 10, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Numero));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplEndTom", 0, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Complemento));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "BairroTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Bairro));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "MunTom", 1, 60, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Municipio));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SiglaUFTom", 2, 2, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Uf));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CepTom", 8, 8, Ocorrencia.Obrigatoria, nota.Tomador.Endereco.Cep.ZeroFill(8)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "Telefone", 10, 10, Ocorrencia.Obrigatoria, (nota.Tomador.DadosContato.DDD.OnlyNumbers() + nota.Tomador.DadosContato.Telefone.OnlyNumbers()).ZeroFill(10)));
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "InscricaoMunicipal", 1, 20, Ocorrencia.Obrigatoria, nota.Tomador.InscricaoMunicipal));

                if (nota.NaturezaOperacao == 1 && nota.Tomador.Endereco.CodigoMunicipio != nota.Prestador.Endereco.CodigoMunicipio) //Natureza 1 = Tributacao no Município, 2 - Fora do Município
                {
                    //Quando a natureza é 1 (dentro do município) e o tomador é de cidade diferente do prestador, os campos abaixo são preenchidos com o endereço do prestador

                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogLocPre", 1, 10, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.TipoLogradouro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "LogLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Logradouro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "NumEndLocPre", 1, 10, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Numero));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplEndLocPre", 0, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Complemento));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "BairroLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Bairro));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "MunLocPre", 1, 60, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Municipio));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SiglaUFLocpre", 2, 2, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Uf));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CepLocPre", 8, 8, Ocorrencia.NaoObrigatoria, nota.Prestador.Endereco.Cep.ZeroFill(8)));
                }
                else
                {
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "TipoLogLocPre", 1, 10, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "LogLocPre", 1, 60, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "NumEndLocPre", 1, 10, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "ComplEndLocPre", 0, 60, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "BairroLocPre", 1, 60, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "MunLocPre", 1, 60, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "SiglaUFLocpre", 2, 2, Ocorrencia.NaoObrigatoria, ""));
                    reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CepLocPre", 8, 8, Ocorrencia.NaoObrigatoria, ""));
                }

                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "Email1", 0, 120, Ocorrencia.NaoObrigatoria, nota.Tomador.DadosContato.Email));
            }
            else
            {
                reg20Item.AddChild(AdicionarTag(TipoCampo.Str, "", "CpfCnpjTom", 1, 14, Ocorrencia.Obrigatoria, "CONSUMIDOR"));
            }

            return(reg20);
        }