Esempio n. 1
0
 public frmVisualizaNfs(tcLoteRps objLoteRps)
 {
     InitializeComponent();
     listErros.ListBox.MouseDoubleClick += new MouseEventHandler(listErros_MouseDoubleClick);
     this.objLoteRps = objLoteRps;
     CriaObjAlter();
     bsNotas.DataSource = this.objLoteRpsAlter.Rps;
     ValidaNotas();
     PopulaForm();
     VerificaCampos();
 }
Esempio n. 2
0
        public void LimpaRecibo(tcLoteRps objListaLote)
        {
            StringBuilder sSql = new StringBuilder();

            try
            {
                for (int i = 0; i < objListaLote.Rps.Count; i++)
                {
                    ApagaRecibo(objLoteRpsAlter.Rps[i].InfRps.IdentificacaoRps.Nfseq);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public void GerarArquivoXml2(tcLoteRps objLoteRpd)
        {
            try
            {
                List<string> ListaNfes = new List<string>();
                XDocument xdoc = new XDocument();
                XNamespace pf = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd";


                XContainer conEnviarLoteRpsEnvio = (new XElement(pf + "EnviarLoteRpsEnvio", new XAttribute("xmlns", "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd")));

                XContainer conLoteRps = null;
                conLoteRps = (new XElement(pf + "LoteRps", new XAttribute("Id", Convert.ToInt32(objLoteRpd.NumeroLote)),
                                                                                     new XElement(pf + "NumeroLote", objLoteRpd.NumeroLote.ToString()),
                                                                                     new XElement(pf + "Cnpj", objLoteRpd.Cnpj.ToString()),
                                                                                     new XElement(pf + "InscricaoMunicipal", objLoteRpd.InscricaoMunicipal.ToString()),
                                                                                     new XElement(pf + "QuantidadeRps", objLoteRpd.QuantidadeRps.ToString())));

                XContainer conListaRps = (new XElement(pf + "ListaRps"));
                XContainer conRps = (new XElement(pf + "Rps"));
                XContainer conInfRps = null;
                XContainer conSubstituto = null;
                XContainer conServico = null;
                XContainer conPrestador = null;
                XContainer conTomador = null;
                XContainer conIntermediarioServico = null;
                XContainer conConstrucaoCivil = null;


                belAssinaXml Assinatura = new belAssinaXml();

                foreach (TcRps rps in objLoteRpd.Rps)
                {
                    #region IdentificacaoRps conRps
                    try
                    {
                        conInfRps = (new XElement(pf + "InfRps", new XElement(pf + "IdentificacaoRps",
                                                                                     new XElement(pf + "Numero", rps.InfRps.IdentificacaoRps.Numero),
                                                                                     new XElement(pf + "Serie", rps.InfRps.IdentificacaoRps.Serie),
                                                                                     new XElement(pf + "Tipo", rps.InfRps.IdentificacaoRps.Tipo)),
                                                                          new XElement(pf + "DataEmissao", daoUtil.GetDateServidor().Date.ToString("yyyy-MM-ddTHH:mm:ss")),
                                                                          new XElement(pf + "NaturezaOperacao", rps.InfRps.NaturezaOperacao),
                                                                         ((rps.InfRps.RegimeEspecialTributacao != 0) ? new XElement(pf + "RegimeEspecialTributacao", rps.InfRps.RegimeEspecialTributacao) : null),
                                                                          new XElement(pf + "OptanteSimplesNacional", rps.InfRps.OptanteSimplesNacional),
                                                                          new XElement(pf + "IncentivadorCultural", rps.InfRps.IncentivadorCultural),
                                                                          new XElement(pf + "Status", rps.InfRps.Status)));

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IdentificacaoRps')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region RpsSubstituido
                    if (rps.InfRps.RpsSubstituido != null)
                    {
                        try
                        {
                            conSubstituto = (new XElement("RpsSubstituido",
                                                         new XElement("Numero", rps.InfRps.RpsSubstituido.Numero),
                                                         new XElement("Serie", rps.InfRps.RpsSubstituido.Serie),
                                                         new XElement("Tipo", rps.InfRps.RpsSubstituido.Tipo)));
                        }
                        catch (Exception x)
                        {
                            throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('RpsSubstituido')- "
                                + Environment.NewLine + "XML_Detalhes: "
                                + Environment.NewLine + x.Message);
                        }
                    }

                    #endregion

                    #region Servico
                    try
                    {
                        conServico = (new XElement(pf + "Servico", new XElement(pf + "Valores",
                                                    new XElement(pf + "ValorServicos", rps.InfRps.Servico.Valores.ValorServicos.ToString("#0.00").Replace(",", ".")),
                                                    ((rps.InfRps.Servico.Valores.ValorDeducoes != 0) ? new XElement(pf + "ValorDeducoes", rps.InfRps.Servico.Valores.ValorDeducoes.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorPis != null) ? new XElement(pf + "ValorPis", rps.InfRps.Servico.Valores.ValorPis.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorCofins != null) ? new XElement(pf + "ValorCofins", rps.InfRps.Servico.Valores.ValorCofins.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorInss != null) ? new XElement(pf + "ValorInss", rps.InfRps.Servico.Valores.ValorInss.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorIr != null) ? new XElement(pf + "ValorIr", rps.InfRps.Servico.Valores.ValorIr.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorCsll != null) ? new XElement(pf + "ValorCsll", rps.InfRps.Servico.Valores.ValorCsll.ToString("#0.00").Replace(",", ".")) : null),
                                                                                                      new XElement(pf + "IssRetido", rps.InfRps.Servico.Valores.IssRetido),
                                                    ((rps.InfRps.Servico.Valores.ValorIss != null) ? new XElement(pf + "ValorIss", rps.InfRps.Servico.Valores.ValorIss.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorIssRetido != null) ? new XElement(pf + "ValorIssRetido", rps.InfRps.Servico.Valores.ValorIssRetido.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.OutrasRetencoes != 0) ? new XElement(pf + "OutrasRetencoes", rps.InfRps.Servico.Valores.OutrasRetencoes.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.BaseCalculo != 0) ? new XElement(pf + "BaseCalculo", rps.InfRps.Servico.Valores.BaseCalculo.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.Aliquota != null) ? new XElement(pf + "Aliquota", (rps.InfRps.Servico.Valores.Aliquota / 100).ToString("#0.0000").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.ValorLiquidoNfse != 0) ? new XElement(pf + "ValorLiquidoNfse", rps.InfRps.Servico.Valores.ValorLiquidoNfse.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.DescontoCondicionado != 0) ? new XElement(pf + "DescontoCondicionado", rps.InfRps.Servico.Valores.DescontoCondicionado.ToString("#0.00").Replace(",", ".")) : null),
                                                    ((rps.InfRps.Servico.Valores.DescontoIncondicionado != 0) ? new XElement(pf + "DescontoIncondicionado", rps.InfRps.Servico.Valores.DescontoIncondicionado.ToString("#0.00").Replace(",", ".")) : null)),
                                                                                         new XElement(pf + "ItemListaServico", rps.InfRps.Servico.ItemListaServico),
                                       ((rps.InfRps.Servico.CodigoCnae != "") ? new XElement(pf + "CodigoCnae", rps.InfRps.Servico.CodigoCnae) : null),
                                       (((rps.InfRps.Servico.CodigoTributacaoMunicipio != "") && (rps.InfRps.Servico.CodigoTributacaoMunicipio != "0")) ? new XElement(pf + "CodigoTributacaoMunicipio", rps.InfRps.Servico.CodigoTributacaoMunicipio) : null),
                                                                                         new XElement(pf + "Discriminacao", rps.InfRps.Servico.Discriminacao),
                                       new XElement(pf + "CodigoMunicipio", rps.InfRps.Servico.CodigoMunicipio)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Servico')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Prestador
                    try
                    {
                        conPrestador = (new XElement(pf + "Prestador", new XElement(pf + "Cnpj", rps.InfRps.Prestador.Cnpj),
                                                                      ((rps.InfRps.Prestador.InscricaoMunicipal != "") ? new XElement(pf + "InscricaoMunicipal", rps.InfRps.Prestador.InscricaoMunicipal) : null)));

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Prestador')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Tomador
                    try
                    {
                        //conTomador = (new XElement(pf + "Tomador", ((rps.InfRps.Tomador.IdentificacaoTomador != null) ? new XElement(pf + "IdentificacaoTomador", new XElement(pf + "CpfCnpj",
                        //                                                                                       new XElement(pf + (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? "Cnpj" : "Cpf"), (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj : rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf))),
                        //                                            (rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal != "" ? (new XElement(pf + "InscricaoMunicipal", rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal)) : null)) : null),
                        //                                            new XElement(pf + "RazaoSocial", rps.InfRps.Tomador.RazaoSocial),
                        //                                            new XElement(pf + "Endereco",
                        //                                                               new XElement(pf + "Endereco", rps.InfRps.Tomador.Endereco.Endereco),
                        //                                                               new XElement(pf + "Numero", rps.InfRps.Tomador.Endereco.Numero),
                        //                                                              (rps.InfRps.Tomador.Endereco.Complemento != "" ? new XElement(pf + "Complemento", rps.InfRps.Tomador.Endereco.Complemento) : null),
                        //                                                               new XElement(pf + "Bairro", rps.InfRps.Tomador.Endereco.Bairro),
                        //                                                               new XElement(pf + "CodigoMunicipio", rps.InfRps.Tomador.Endereco.CodigoMunicipio),
                        //                                                               new XElement(pf + "Uf", rps.InfRps.Tomador.Endereco.Uf),
                        //                                                               new XElement(pf + "Cep", rps.InfRps.Tomador.Endereco.Cep))));

                        conTomador = (new XElement(pf + "Tomador", ((rps.InfRps.Tomador.IdentificacaoTomador != null) ? new XElement(pf + "IdentificacaoTomador", new XElement(pf + "CpfCnpj",
                                                                                                              new XElement(pf + (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? "Cnpj" : "Cpf"), (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj : rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf))),
                                                                   (rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal != "" ? (new XElement(pf + "InscricaoMunicipal", rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal)) : null)) : null),
                                                                   new XElement(pf + "RazaoSocial", rps.InfRps.Tomador.RazaoSocial),
                                                                   new XElement(pf + "Endereco",
                                                                                      new XElement(pf + "Endereco", rps.InfRps.Tomador.Endereco.Endereco),
                                                                                      new XElement(pf + "Numero", rps.InfRps.Tomador.Endereco.Numero),
                                                                                     (rps.InfRps.Tomador.Endereco.Complemento != "" ? new XElement(pf + "Complemento", rps.InfRps.Tomador.Endereco.Complemento) : null),
                                                                                      new XElement(pf + "Bairro", rps.InfRps.Tomador.Endereco.Bairro),
                                                                                      new XElement(pf + "CodigoMunicipio", rps.InfRps.Tomador.Endereco.CodigoMunicipio),
                                                                                      new XElement(pf + "Uf", rps.InfRps.Tomador.Endereco.Uf),
                                                                                      new XElement(pf + "Cep", rps.InfRps.Tomador.Endereco.Cep)),
                                                                                      ((rps.InfRps.Tomador.Contato.Telefone != "" || rps.InfRps.Tomador.Contato.Email != "") ?
                                                                                      (new XElement(pf + "Contato",
                                                                                                        ((rps.InfRps.Tomador.Contato.Telefone != "") ? new XElement(pf + "Telefone", rps.InfRps.Tomador.Contato.Telefone) : null),
                                                                                                        ((rps.InfRps.Tomador.Contato.Email != "") ? new XElement(pf + "Email", rps.InfRps.Tomador.Contato.Email) : null))) : null)));



                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Tomador')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }

                    #endregion

                    #region IntermediarioServico
                    try
                    {
                        if (rps.InfRps.IntermediarioServico != null)
                        {
                            conIntermediarioServico = (new XElement(pf + "IntermediarioServico", new XElement(pf + "RazaoSocial", rps.InfRps.IntermediarioServico.RazaoSocial),
                                                                                               new XElement(pf + "CpfCnpj", (new XElement((rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? "Cnpj" : "Cpf"), (rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj : rps.InfRps.IntermediarioServico.CpfCnpj.Cpf)))),
                                                                                               new XElement(pf + "InscricaoMunicipal", rps.InfRps.IntermediarioServico.InscricaoMunicipal)));
                        }
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IntermediarioServico')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region ConstrucaoCivil

                    try
                    {
                        if (rps.InfRps.ConstrucaoCivil != null)
                        {
                            if ((rps.InfRps.ConstrucaoCivil.CodigoObra != "") && (rps.InfRps.ConstrucaoCivil.Art != ""))
                            {
                                conConstrucaoCivil = (new XElement(pf + "ConstrucaoCivil", new XElement(pf + "CodigoObra", rps.InfRps.ConstrucaoCivil.CodigoObra),
                                                                                          new XElement(pf + "Art", rps.InfRps.ConstrucaoCivil.Art)));
                            }
                        }

                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('ConstrucaoCivil')- "
                            + Environment.NewLine + "XML_Detalhes: "
                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    try
                    {
                        if (conSubstituto != null)
                        {
                            conInfRps.Add(conSubstituto);
                        }
                        conInfRps.Add(conServico);
                        conInfRps.Add(conPrestador);
                        conInfRps.Add(conTomador);
                        if (conIntermediarioServico != null) { conInfRps.Add(conIntermediarioServico); }
                        if (conConstrucaoCivil != null) { conInfRps.Add(conConstrucaoCivil); }
                        conRps.Add(conInfRps);


                        conListaRps.Add(conRps);


                        //Salva o Rps;
                        XDocument xdocsalvanfesemlot = new XDocument(conRps);
                        string sPasta = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "");
                        string sNomeArquivo = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "") + rps.InfRps.IdentificacaoRps.Serie + rps.InfRps.IdentificacaoRps.Numero;
                        DirectoryInfo dPastaData = new DirectoryInfo(Pastas.ENVIO + "\\Servicos\\" + sPasta);
                        if (!dPastaData.Exists) { dPastaData.Create(); }
                        xdocsalvanfesemlot.Save(Pastas.ENVIO + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml");

                        conRps = (new XElement("Rps"));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota de Sequência - " + "sNota" + "Erro ao assinar a nfe de sequencia " + "sNota" + x.Message);
                    }
                }

                conLoteRps.Add(conListaRps);
                conEnviarLoteRpsEnvio.Add(conLoteRps);
                //Assina Arquivo
                string nfes = Assinatura.ConfigurarArquivo(conEnviarLoteRpsEnvio.ToString(), "LoteRps", Acesso.cert_NFs);
                sXmlLote = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + nfes;
                //Grava
                string sPathLote = Pastas.ENVIO + "\\Servicos\\" + "Lote_" + objLoteRpd.NumeroLote + ".xml";
                StreamWriter sw = new StreamWriter(sPathLote);
                sw.Write(sXmlLote);
                sw.Close();

                #region Valida_Xml


                try
                {
                    if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES)
                    {
                        belValidaXml.ValidarXml("http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd", Pastas.SCHEMA_NFSE + "\\servico_enviar_lote_rps_envio_v03.xsd", sPathLote);
                    }
                    else
                    {
                        belValidaXml.ValidarXml("http://www.nfe.com.br/WSNacional/XSD/1/nfse_municipal_v01.xsd", Pastas.SCHEMA_NFSE + "\\TIPLAN\\nfse_municipal_v01.xsd", sPathLote);
                    }
                }
                catch (XmlException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                catch (XmlSchemaException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public tcLoteRps BuscaDadosNFes(List<belPesquisaNotas> objListaNotas)
        {

            try
            {
                tcLoteRps objLoteRps = new tcLoteRps();

                objLoteRps.Rps = new List<TcRps>();
                foreach (belPesquisaNotas Nota in objListaNotas)
                {
                    TcRps objTcRps = new TcRps();

                    #region IdentificacaoRps - TcIdentificacaoRps

                    beltcIdentificacaoRps objbeltcIdentificacaoRps = new beltcIdentificacaoRps();
                    objTcRps.InfRps = new TcInfRps();

                    objTcRps.InfRps.DataEmissao = daoUtil.GetDateServidor();
                    objTcRps.InfRps.Status = 1;//Normal;

                    DataTable dt = BuscaDadosNota(Nota.sCD_NFSEQ);
                    foreach (DataRow dr in dt.Rows)
                    {
                        objTcRps.InfRps.NaturezaOperacao = Convert.ToInt16(dr["cd_natureza_oper_nfse"].ToString());
                        objTcRps.InfRps.OptanteSimplesNacional = (dr["st_simples"].ToString().Equals("S") ? 1 : 2);
                        objTcRps.InfRps.IncentivadorCultural = (dr["st_insentivador_cultural"].ToString().Equals("S") ? 1 : 2);
                        if (objTcRps.InfRps.OptanteSimplesNacional == 1)
                        {
                            objTcRps.InfRps.RegimeEspecialTributacao = Convert.ToInt16(dr["RegimeEspecialTributacao"].ToString());
                        }
                        else
                        {
                            objTcRps.InfRps.RegimeEspecialTributacao = 0;
                        }
                    }

                    objTcRps.InfRps.IdentificacaoRps = objbeltcIdentificacaoRps.BuscatcIdentificacaoRps(Nota.sCD_NFSEQ);

                    #endregion

                    #region   Servico - TcDadosServico

                    belServico objbelServico = new belServico();
                    objTcRps.InfRps.Servico = objbelServico.RetornaDadosServico(Nota.sCD_NFSEQ, objTcRps.InfRps.NaturezaOperacao);

                    #endregion

                    #region   Prestador - tcIdentificacaoPrestador

                    belPrestador objbelPrestador = new belPrestador();
                    objTcRps.InfRps.Prestador = objbelPrestador.RettcIdentificacaoPrestador(Nota.sCD_NFSEQ);
                    objLoteRps.Cnpj = objTcRps.InfRps.Prestador.Cnpj;
                    objLoteRps.InscricaoMunicipal = objTcRps.InfRps.Prestador.InscricaoMunicipal;

                    #endregion

                    #region Tomador - TcDadosTomador

                    belTomador objbelTomador = new belTomador();
                    objTcRps.InfRps.Tomador = objbelTomador.RettcDadosTomador(Nota.sCD_NFSEQ);

                    #endregion

                    #region  ConstrucaoCivil - TcDadosContrucaoCivil - Tratado na Visualização da Nota

                    if (Acesso.NM_EMPRESA.Equals("AENGE"))
                    {
                        belConstrucaoCivil objbelConstrucaoCivil = new belConstrucaoCivil();
                        objTcRps.InfRps.ConstrucaoCivil = objbelConstrucaoCivil.RettcDadosConstrucaoCivil(Nota.sCD_NFSEQ);
                    }
                    #endregion

                    objLoteRps.Rps.Add(objTcRps);
                }
                daoUtil objdaoUtil = new daoUtil();
                objLoteRps.NumeroLote = objdaoUtil.RetornaProximoValorGenerator("GEN_LOTE_NFES", 15);
                objLoteRps.QuantidadeRps = objLoteRps.Rps.Count;

                return objLoteRps;
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
Esempio n. 5
0
        private void CriaObjAlter()
        {
            try
            {

                tcLoteRps obj = new tcLoteRps();
                obj.Rps = new List<TcRps>();

                obj.NumeroLote = this.objLoteRps.NumeroLote;
                obj.Cnpj = this.objLoteRps.Cnpj;
                obj.InscricaoMunicipal = this.objLoteRps.InscricaoMunicipal;
                obj.QuantidadeRps = this.objLoteRps.QuantidadeRps;



                for (int i = 0; i < this.objLoteRps.Rps.Count; i++)
                {
                    TcRps objTcTcRps = new TcRps();
                    #region Identificacao
                    objTcTcRps.InfRps = new TcInfRps();
                    objTcTcRps.InfRps.DataEmissao = this.objLoteRps.Rps[i].InfRps.DataEmissao;
                    objTcTcRps.InfRps.NaturezaOperacao = this.objLoteRps.Rps[i].InfRps.NaturezaOperacao;
                    objTcTcRps.InfRps.RegimeEspecialTributacao = this.objLoteRps.Rps[i].InfRps.RegimeEspecialTributacao;
                    objTcTcRps.InfRps.OptanteSimplesNacional = this.objLoteRps.Rps[i].InfRps.OptanteSimplesNacional;
                    objTcTcRps.InfRps.IncentivadorCultural = this.objLoteRps.Rps[i].InfRps.IncentivadorCultural;
                    objTcTcRps.InfRps.Status = this.objLoteRps.Rps[i].InfRps.Status;


                    objTcTcRps.InfRps.IdentificacaoRps = new tcIdentificacaoRps();
                    objTcTcRps.InfRps.IdentificacaoRps.Numero = this.objLoteRps.Rps[i].InfRps.IdentificacaoRps.Numero;
                    objTcTcRps.InfRps.IdentificacaoRps.Serie = this.objLoteRps.Rps[i].InfRps.IdentificacaoRps.Serie;
                    objTcTcRps.InfRps.IdentificacaoRps.Tipo = this.objLoteRps.Rps[i].InfRps.IdentificacaoRps.Tipo;
                    objTcTcRps.InfRps.IdentificacaoRps.Nfseq = this.objLoteRps.Rps[i].InfRps.IdentificacaoRps.Nfseq;



                    if (this.objLoteRps.Rps[i].InfRps.RpsSubstituido != null)
                    {
                        objTcTcRps.InfRps.RpsSubstituido = new tcIdentificacaoRps();
                        objTcTcRps.InfRps.RpsSubstituido.Numero = this.objLoteRps.Rps[i].InfRps.RpsSubstituido.Numero;
                        objTcTcRps.InfRps.RpsSubstituido.Serie = this.objLoteRps.Rps[i].InfRps.RpsSubstituido.Serie;
                        objTcTcRps.InfRps.RpsSubstituido.Tipo = this.objLoteRps.Rps[i].InfRps.RpsSubstituido.Tipo;
                    }
                    #endregion

                    #region Serviço
                    objTcTcRps.InfRps.Servico = new TcDadosServico();
                    objTcTcRps.InfRps.Servico.Valores = new TcValores();

                    objTcTcRps.InfRps.Servico.Valores.ValorServicos = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorServicos;
                    objTcTcRps.InfRps.Servico.Valores.ValorDeducoes = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorDeducoes;
                    objTcTcRps.InfRps.Servico.Valores.ValorCsll = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorCsll;
                    objTcTcRps.InfRps.Servico.Valores.ValorPis = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorPis;
                    objTcTcRps.InfRps.Servico.Valores.ValorCofins = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorCofins;
                    objTcTcRps.InfRps.Servico.Valores.IssRetido = this.objLoteRps.Rps[i].InfRps.Servico.Valores.IssRetido;
                    objTcTcRps.InfRps.Servico.Valores.ValorInss = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorInss;
                    objTcTcRps.InfRps.Servico.Valores.ValorIr = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorIr;
                    objTcTcRps.InfRps.Servico.Valores.ValorIss = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorIss;
                    objTcTcRps.InfRps.Servico.Valores.OutrasRetencoes = this.objLoteRps.Rps[i].InfRps.Servico.Valores.OutrasRetencoes;
                    objTcTcRps.InfRps.Servico.Valores.BaseCalculo = this.objLoteRps.Rps[i].InfRps.Servico.Valores.BaseCalculo;
                    objTcTcRps.InfRps.Servico.Valores.Aliquota = this.objLoteRps.Rps[i].InfRps.Servico.Valores.Aliquota;
                    objTcTcRps.InfRps.Servico.Valores.ValorLiquidoNfse = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorLiquidoNfse;
                    objTcTcRps.InfRps.Servico.Valores.ValorIssRetido = this.objLoteRps.Rps[i].InfRps.Servico.Valores.ValorIssRetido;
                    objTcTcRps.InfRps.Servico.Valores.DescontoCondicionado = this.objLoteRps.Rps[i].InfRps.Servico.Valores.DescontoCondicionado;
                    objTcTcRps.InfRps.Servico.Valores.DescontoIncondicionado = this.objLoteRps.Rps[i].InfRps.Servico.Valores.DescontoIncondicionado;

                    objTcTcRps.InfRps.Servico.ItemListaServico = this.objLoteRps.Rps[i].InfRps.Servico.ItemListaServico;
                    objTcTcRps.InfRps.Servico.CodigoTributacaoMunicipio = this.objLoteRps.Rps[i].InfRps.Servico.CodigoTributacaoMunicipio;
                    objTcTcRps.InfRps.Servico.CodigoCnae = this.objLoteRps.Rps[i].InfRps.Servico.CodigoCnae;
                    objTcTcRps.InfRps.Servico.CodigoMunicipio = this.objLoteRps.Rps[i].InfRps.Servico.CodigoMunicipio;
                    objTcTcRps.InfRps.Servico.Discriminacao = this.objLoteRps.Rps[i].InfRps.Servico.Discriminacao;

                    #endregion

                    #region Dados Adicionais
                    objTcTcRps.InfRps.Prestador = new tcIdentificacaoPrestador();
                    objTcTcRps.InfRps.Prestador.Cnpj = this.objLoteRps.Rps[i].InfRps.Prestador.Cnpj;

                    objTcTcRps.InfRps.Prestador.InscricaoMunicipal = this.objLoteRps.Rps[i].InfRps.Prestador.InscricaoMunicipal;

                    objTcTcRps.InfRps.Tomador = new tcDadosTomador();

                    objTcTcRps.InfRps.Tomador.IdentificacaoTomador = new tcIdentificacaoTomador();
                    if (this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.CpfCnpj != null)
                    {
                        if (this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "")
                        {
                            objTcTcRps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj = new TcCpfCnpj();
                            objTcTcRps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj = this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj;
                        }
                        else if (this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf != "")
                        {
                            objTcTcRps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj = new TcCpfCnpj();
                            objTcTcRps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf = this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf;
                        }
                    }
                    objTcTcRps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal = this.objLoteRps.Rps[i].InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal;
                    objTcTcRps.InfRps.Tomador.RazaoSocial = this.objLoteRps.Rps[i].InfRps.Tomador.RazaoSocial;

                    if (this.objLoteRps.Rps[i].InfRps.Tomador.Endereco != null)
                    {
                        objTcTcRps.InfRps.Tomador.Endereco = new TcEndereco();

                        objTcTcRps.InfRps.Tomador.Endereco.Endereco = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Endereco;
                        objTcTcRps.InfRps.Tomador.Endereco.Numero = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Numero;
                        objTcTcRps.InfRps.Tomador.Endereco.Complemento = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Complemento;
                        objTcTcRps.InfRps.Tomador.Endereco.Bairro = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Bairro;
                        objTcTcRps.InfRps.Tomador.Endereco.Uf = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Uf;
                        objTcTcRps.InfRps.Tomador.Endereco.CodigoMunicipio = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.CodigoMunicipio;
                        objTcTcRps.InfRps.Tomador.Endereco.Cep = this.objLoteRps.Rps[i].InfRps.Tomador.Endereco.Cep;
                    }

                    if (this.objLoteRps.Rps[i].InfRps.Tomador.Contato != null)
                    {
                        objTcTcRps.InfRps.Tomador.Contato = new TcContato();

                        objTcTcRps.InfRps.Tomador.Contato.Telefone = this.objLoteRps.Rps[i].InfRps.Tomador.Contato.Telefone;
                        objTcTcRps.InfRps.Tomador.Contato.Email = this.objLoteRps.Rps[i].InfRps.Tomador.Contato.Email;
                    }


                    if (this.objLoteRps.Rps[i].InfRps.IntermediarioServico != null)
                    {
                        objTcTcRps.InfRps.IntermediarioServico = new TcIdentificacaoIntermediarioServico();
                        objTcTcRps.InfRps.IntermediarioServico.RazaoSocial = this.objLoteRps.Rps[i].InfRps.IntermediarioServico.RazaoSocial;
                        objTcTcRps.InfRps.IntermediarioServico.InscricaoMunicipal = this.objLoteRps.Rps[i].InfRps.IntermediarioServico.InscricaoMunicipal;


                        if (this.objLoteRps.Rps[i].InfRps.IntermediarioServico.CpfCnpj != null)
                        {
                            if (this.objLoteRps.Rps[i].InfRps.IntermediarioServico.CpfCnpj.Cnpj != "")
                            {
                                objTcTcRps.InfRps.IntermediarioServico.CpfCnpj = new TcCpfCnpj();
                                objTcTcRps.InfRps.IntermediarioServico.CpfCnpj.Cnpj = this.objLoteRps.Rps[i].InfRps.IntermediarioServico.CpfCnpj.Cnpj;
                            }
                            else if (this.objLoteRps.Rps[i].InfRps.IntermediarioServico.CpfCnpj.Cpf != "")
                            {
                                objTcTcRps.InfRps.IntermediarioServico.CpfCnpj = new TcCpfCnpj();
                                objTcTcRps.InfRps.IntermediarioServico.CpfCnpj.Cpf = this.objLoteRps.Rps[i].InfRps.IntermediarioServico.CpfCnpj.Cpf;
                            }
                        }
                    }

                    if (this.objLoteRps.Rps[i].InfRps.ConstrucaoCivil != null)
                    {
                        objTcTcRps.InfRps.ConstrucaoCivil = new tcDadosConstrucaoCivil();
                        objTcTcRps.InfRps.ConstrucaoCivil.Art = this.objLoteRps.Rps[i].InfRps.ConstrucaoCivil.Art;
                        objTcTcRps.InfRps.ConstrucaoCivil.CodigoObra = this.objLoteRps.Rps[i].InfRps.ConstrucaoCivil.CodigoObra;
                    }

                    #endregion

                    obj.Rps.Add(objTcTcRps);

                }
                this.objLoteRpsAlter = obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        public void GerarArquivoXml2(tcLoteRps objLoteRpd)
        {
            try
            {
                List <string> ListaNfes = new List <string>();
                XDocument     xdoc      = new XDocument();
                XNamespace    pf        = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd";


                XContainer conEnviarLoteRpsEnvio = (new XElement(pf + "EnviarLoteRpsEnvio", new XAttribute("xmlns", "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd")));

                XContainer conLoteRps = null;
                conLoteRps = (new XElement(pf + "LoteRps", new XAttribute("Id", Convert.ToInt32(objLoteRpd.NumeroLote)),
                                           new XElement(pf + "NumeroLote", objLoteRpd.NumeroLote.ToString()),
                                           new XElement(pf + "Cnpj", objLoteRpd.Cnpj.ToString()),
                                           new XElement(pf + "InscricaoMunicipal", objLoteRpd.InscricaoMunicipal.ToString()),
                                           new XElement(pf + "QuantidadeRps", objLoteRpd.QuantidadeRps.ToString())));

                XContainer conListaRps             = (new XElement(pf + "ListaRps"));
                XContainer conRps                  = (new XElement(pf + "Rps"));
                XContainer conInfRps               = null;
                XContainer conSubstituto           = null;
                XContainer conServico              = null;
                XContainer conPrestador            = null;
                XContainer conTomador              = null;
                XContainer conIntermediarioServico = null;
                XContainer conConstrucaoCivil      = null;


                belAssinaXml Assinatura = new belAssinaXml();

                foreach (TcRps rps in objLoteRpd.Rps)
                {
                    #region IdentificacaoRps conRps
                    try
                    {
                        conInfRps = (new XElement(pf + "InfRps", new XElement(pf + "IdentificacaoRps",
                                                                              new XElement(pf + "Numero", rps.InfRps.IdentificacaoRps.Numero),
                                                                              new XElement(pf + "Serie", rps.InfRps.IdentificacaoRps.Serie),
                                                                              new XElement(pf + "Tipo", rps.InfRps.IdentificacaoRps.Tipo)),
                                                  new XElement(pf + "DataEmissao", daoUtil.GetDateServidor().Date.ToString("yyyy-MM-ddTHH:mm:ss")),
                                                  new XElement(pf + "NaturezaOperacao", rps.InfRps.NaturezaOperacao),
                                                  ((rps.InfRps.RegimeEspecialTributacao != 0) ? new XElement(pf + "RegimeEspecialTributacao", rps.InfRps.RegimeEspecialTributacao) : null),
                                                  new XElement(pf + "OptanteSimplesNacional", rps.InfRps.OptanteSimplesNacional),
                                                  new XElement(pf + "IncentivadorCultural", rps.InfRps.IncentivadorCultural),
                                                  new XElement(pf + "Status", rps.InfRps.Status)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IdentificacaoRps')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region RpsSubstituido
                    if (rps.InfRps.RpsSubstituido != null)
                    {
                        try
                        {
                            conSubstituto = (new XElement("RpsSubstituido",
                                                          new XElement("Numero", rps.InfRps.RpsSubstituido.Numero),
                                                          new XElement("Serie", rps.InfRps.RpsSubstituido.Serie),
                                                          new XElement("Tipo", rps.InfRps.RpsSubstituido.Tipo)));
                        }
                        catch (Exception x)
                        {
                            throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('RpsSubstituido')- "
                                                + Environment.NewLine + "XML_Detalhes: "
                                                + Environment.NewLine + x.Message);
                        }
                    }

                    #endregion

                    #region Servico
                    try
                    {
                        conServico = (new XElement(pf + "Servico", new XElement(pf + "Valores",
                                                                                new XElement(pf + "ValorServicos", rps.InfRps.Servico.Valores.ValorServicos.ToString("#0.00").Replace(",", ".")),
                                                                                ((rps.InfRps.Servico.Valores.ValorDeducoes != 0) ? new XElement(pf + "ValorDeducoes", rps.InfRps.Servico.Valores.ValorDeducoes.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorPis != null) ? new XElement(pf + "ValorPis", rps.InfRps.Servico.Valores.ValorPis.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorCofins != null) ? new XElement(pf + "ValorCofins", rps.InfRps.Servico.Valores.ValorCofins.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorInss != null) ? new XElement(pf + "ValorInss", rps.InfRps.Servico.Valores.ValorInss.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorIr != null) ? new XElement(pf + "ValorIr", rps.InfRps.Servico.Valores.ValorIr.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorCsll != null) ? new XElement(pf + "ValorCsll", rps.InfRps.Servico.Valores.ValorCsll.ToString("#0.00").Replace(",", ".")) : null),
                                                                                new XElement(pf + "IssRetido", rps.InfRps.Servico.Valores.IssRetido),
                                                                                ((rps.InfRps.Servico.Valores.ValorIss != null) ? new XElement(pf + "ValorIss", rps.InfRps.Servico.Valores.ValorIss.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorIssRetido != null) ? new XElement(pf + "ValorIssRetido", rps.InfRps.Servico.Valores.ValorIssRetido.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.OutrasRetencoes != 0) ? new XElement(pf + "OutrasRetencoes", rps.InfRps.Servico.Valores.OutrasRetencoes.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.BaseCalculo != 0) ? new XElement(pf + "BaseCalculo", rps.InfRps.Servico.Valores.BaseCalculo.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.Aliquota != null) ? new XElement(pf + "Aliquota", (rps.InfRps.Servico.Valores.Aliquota / 100).ToString("#0.0000").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.ValorLiquidoNfse != 0) ? new XElement(pf + "ValorLiquidoNfse", rps.InfRps.Servico.Valores.ValorLiquidoNfse.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.DescontoCondicionado != 0) ? new XElement(pf + "DescontoCondicionado", rps.InfRps.Servico.Valores.DescontoCondicionado.ToString("#0.00").Replace(",", ".")) : null),
                                                                                ((rps.InfRps.Servico.Valores.DescontoIncondicionado != 0) ? new XElement(pf + "DescontoIncondicionado", rps.InfRps.Servico.Valores.DescontoIncondicionado.ToString("#0.00").Replace(",", ".")) : null)),
                                                   new XElement(pf + "ItemListaServico", rps.InfRps.Servico.ItemListaServico),
                                                   ((rps.InfRps.Servico.CodigoCnae != "") ? new XElement(pf + "CodigoCnae", rps.InfRps.Servico.CodigoCnae) : null),
                                                   (((rps.InfRps.Servico.CodigoTributacaoMunicipio != "") && (rps.InfRps.Servico.CodigoTributacaoMunicipio != "0")) ? new XElement(pf + "CodigoTributacaoMunicipio", rps.InfRps.Servico.CodigoTributacaoMunicipio) : null),
                                                   new XElement(pf + "Discriminacao", rps.InfRps.Servico.Discriminacao),
                                                   new XElement(pf + "CodigoMunicipio", rps.InfRps.Servico.CodigoMunicipio)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Servico')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Prestador
                    try
                    {
                        conPrestador = (new XElement(pf + "Prestador", new XElement(pf + "Cnpj", rps.InfRps.Prestador.Cnpj),
                                                     ((rps.InfRps.Prestador.InscricaoMunicipal != "") ? new XElement(pf + "InscricaoMunicipal", rps.InfRps.Prestador.InscricaoMunicipal) : null)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Prestador')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region Tomador
                    try
                    {
                        //conTomador = (new XElement(pf + "Tomador", ((rps.InfRps.Tomador.IdentificacaoTomador != null) ? new XElement(pf + "IdentificacaoTomador", new XElement(pf + "CpfCnpj",
                        //                                                                                       new XElement(pf + (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? "Cnpj" : "Cpf"), (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj : rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf))),
                        //                                            (rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal != "" ? (new XElement(pf + "InscricaoMunicipal", rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal)) : null)) : null),
                        //                                            new XElement(pf + "RazaoSocial", rps.InfRps.Tomador.RazaoSocial),
                        //                                            new XElement(pf + "Endereco",
                        //                                                               new XElement(pf + "Endereco", rps.InfRps.Tomador.Endereco.Endereco),
                        //                                                               new XElement(pf + "Numero", rps.InfRps.Tomador.Endereco.Numero),
                        //                                                              (rps.InfRps.Tomador.Endereco.Complemento != "" ? new XElement(pf + "Complemento", rps.InfRps.Tomador.Endereco.Complemento) : null),
                        //                                                               new XElement(pf + "Bairro", rps.InfRps.Tomador.Endereco.Bairro),
                        //                                                               new XElement(pf + "CodigoMunicipio", rps.InfRps.Tomador.Endereco.CodigoMunicipio),
                        //                                                               new XElement(pf + "Uf", rps.InfRps.Tomador.Endereco.Uf),
                        //                                                               new XElement(pf + "Cep", rps.InfRps.Tomador.Endereco.Cep))));

                        conTomador = (new XElement(pf + "Tomador", ((rps.InfRps.Tomador.IdentificacaoTomador != null) ? new XElement(pf + "IdentificacaoTomador", new XElement(pf + "CpfCnpj",
                                                                                                                                                                               new XElement(pf + (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? "Cnpj" : "Cpf"), (rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj != "" ? rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cnpj : rps.InfRps.Tomador.IdentificacaoTomador.CpfCnpj.Cpf))),
                                                                                                                                     (rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal != "" ? (new XElement(pf + "InscricaoMunicipal", rps.InfRps.Tomador.IdentificacaoTomador.InscricaoMunicipal)) : null)) : null),
                                                   new XElement(pf + "RazaoSocial", rps.InfRps.Tomador.RazaoSocial),
                                                   new XElement(pf + "Endereco",
                                                                new XElement(pf + "Endereco", rps.InfRps.Tomador.Endereco.Endereco),
                                                                new XElement(pf + "Numero", rps.InfRps.Tomador.Endereco.Numero),
                                                                (rps.InfRps.Tomador.Endereco.Complemento != "" ? new XElement(pf + "Complemento", rps.InfRps.Tomador.Endereco.Complemento) : null),
                                                                new XElement(pf + "Bairro", rps.InfRps.Tomador.Endereco.Bairro),
                                                                new XElement(pf + "CodigoMunicipio", rps.InfRps.Tomador.Endereco.CodigoMunicipio),
                                                                new XElement(pf + "Uf", rps.InfRps.Tomador.Endereco.Uf),
                                                                new XElement(pf + "Cep", rps.InfRps.Tomador.Endereco.Cep)),
                                                   ((rps.InfRps.Tomador.Contato.Telefone != "" || rps.InfRps.Tomador.Contato.Email != "") ?
                                                    (new XElement(pf + "Contato",
                                                                  ((rps.InfRps.Tomador.Contato.Telefone != "") ? new XElement(pf + "Telefone", rps.InfRps.Tomador.Contato.Telefone) : null),
                                                                  ((rps.InfRps.Tomador.Contato.Email != "") ? new XElement(pf + "Email", rps.InfRps.Tomador.Contato.Email) : null))) : null)));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('Tomador')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }

                    #endregion

                    #region IntermediarioServico
                    try
                    {
                        if (rps.InfRps.IntermediarioServico != null)
                        {
                            conIntermediarioServico = (new XElement(pf + "IntermediarioServico", new XElement(pf + "RazaoSocial", rps.InfRps.IntermediarioServico.RazaoSocial),
                                                                    new XElement(pf + "CpfCnpj", (new XElement((rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? "Cnpj" : "Cpf"), (rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj != null ? rps.InfRps.IntermediarioServico.CpfCnpj.Cnpj : rps.InfRps.IntermediarioServico.CpfCnpj.Cpf)))),
                                                                    new XElement(pf + "InscricaoMunicipal", rps.InfRps.IntermediarioServico.InscricaoMunicipal)));
                        }
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('IntermediarioServico')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    #region ConstrucaoCivil

                    try
                    {
                        if (rps.InfRps.ConstrucaoCivil != null)
                        {
                            if ((rps.InfRps.ConstrucaoCivil.CodigoObra != "") && (rps.InfRps.ConstrucaoCivil.Art != ""))
                            {
                                conConstrucaoCivil = (new XElement(pf + "ConstrucaoCivil", new XElement(pf + "CodigoObra", rps.InfRps.ConstrucaoCivil.CodigoObra),
                                                                   new XElement(pf + "Art", rps.InfRps.ConstrucaoCivil.Art)));
                            }
                        }
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota : " + rps.InfRps.IdentificacaoRps.Numero + "Erro na geração do XML, Regiao:('ConstrucaoCivil')- "
                                            + Environment.NewLine + "XML_Detalhes: "
                                            + Environment.NewLine + x.Message);
                    }
                    #endregion

                    try
                    {
                        if (conSubstituto != null)
                        {
                            conInfRps.Add(conSubstituto);
                        }
                        conInfRps.Add(conServico);
                        conInfRps.Add(conPrestador);
                        conInfRps.Add(conTomador);
                        if (conIntermediarioServico != null)
                        {
                            conInfRps.Add(conIntermediarioServico);
                        }
                        if (conConstrucaoCivil != null)
                        {
                            conInfRps.Add(conConstrucaoCivil);
                        }
                        conRps.Add(conInfRps);


                        conListaRps.Add(conRps);


                        //Salva o Rps;
                        XDocument     xdocsalvanfesemlot = new XDocument(conRps);
                        string        sPasta             = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "");
                        string        sNomeArquivo       = rps.InfRps.DataEmissao.ToString("MM/yy").Replace("/", "") + rps.InfRps.IdentificacaoRps.Serie + rps.InfRps.IdentificacaoRps.Numero;
                        DirectoryInfo dPastaData         = new DirectoryInfo(Pastas.ENVIO + "\\Servicos\\" + sPasta);
                        if (!dPastaData.Exists)
                        {
                            dPastaData.Create();
                        }
                        xdocsalvanfesemlot.Save(Pastas.ENVIO + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml");

                        conRps = (new XElement("Rps"));
                    }
                    catch (Exception x)
                    {
                        throw new Exception("Nota de Sequência - " + "sNota" + "Erro ao assinar a nfe de sequencia " + "sNota" + x.Message);
                    }
                }

                conLoteRps.Add(conListaRps);
                conEnviarLoteRpsEnvio.Add(conLoteRps);
                //Assina Arquivo
                string nfes = Assinatura.ConfigurarArquivo(conEnviarLoteRpsEnvio.ToString(), "LoteRps", Acesso.cert_NFs);
                sXmlLote = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + nfes;
                //Grava
                string       sPathLote = Pastas.ENVIO + "\\Servicos\\" + "Lote_" + objLoteRpd.NumeroLote + ".xml";
                StreamWriter sw        = new StreamWriter(sPathLote);
                sw.Write(sXmlLote);
                sw.Close();

                #region Valida_Xml


                try
                {
                    if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES)
                    {
                        belValidaXml.ValidarXml("http://www.ginfes.com.br/servico_enviar_lote_rps_envio_v03.xsd", Pastas.SCHEMA_NFSE + "\\servico_enviar_lote_rps_envio_v03.xsd", sPathLote);
                    }
                    else
                    {
                        belValidaXml.ValidarXml("http://www.nfe.com.br/WSNacional/XSD/1/nfse_municipal_v01.xsd", Pastas.SCHEMA_NFSE + "\\TIPLAN\\nfse_municipal_v01.xsd", sPathLote);
                    }
                }
                catch (XmlException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                catch (XmlSchemaException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 7
0
        public tcLoteRps BuscaDadosNFes(List <belPesquisaNotas> objListaNotas)
        {
            try
            {
                tcLoteRps objLoteRps = new tcLoteRps();

                objLoteRps.Rps = new List <TcRps>();
                foreach (belPesquisaNotas Nota in objListaNotas)
                {
                    TcRps objTcRps = new TcRps();

                    #region IdentificacaoRps - TcIdentificacaoRps

                    beltcIdentificacaoRps objbeltcIdentificacaoRps = new beltcIdentificacaoRps();
                    objTcRps.InfRps = new TcInfRps();

                    objTcRps.InfRps.DataEmissao = daoUtil.GetDateServidor();
                    objTcRps.InfRps.Status      = 1;//Normal;

                    DataTable dt = BuscaDadosNota(Nota.sCD_NFSEQ);
                    foreach (DataRow dr in dt.Rows)
                    {
                        objTcRps.InfRps.NaturezaOperacao       = Convert.ToInt16(dr["cd_natureza_oper_nfse"].ToString());
                        objTcRps.InfRps.OptanteSimplesNacional = (dr["st_simples"].ToString().Equals("S") ? 1 : 2);
                        objTcRps.InfRps.IncentivadorCultural   = (dr["st_insentivador_cultural"].ToString().Equals("S") ? 1 : 2);
                        if (objTcRps.InfRps.OptanteSimplesNacional == 1)
                        {
                            objTcRps.InfRps.RegimeEspecialTributacao = Convert.ToInt16(dr["RegimeEspecialTributacao"].ToString());
                        }
                        else
                        {
                            objTcRps.InfRps.RegimeEspecialTributacao = 0;
                        }
                    }

                    objTcRps.InfRps.IdentificacaoRps = objbeltcIdentificacaoRps.BuscatcIdentificacaoRps(Nota.sCD_NFSEQ);

                    #endregion

                    #region   Servico - TcDadosServico

                    belServico objbelServico = new belServico();
                    objTcRps.InfRps.Servico = objbelServico.RetornaDadosServico(Nota.sCD_NFSEQ, objTcRps.InfRps.NaturezaOperacao);

                    #endregion

                    #region   Prestador - tcIdentificacaoPrestador

                    belPrestador objbelPrestador = new belPrestador();
                    objTcRps.InfRps.Prestador     = objbelPrestador.RettcIdentificacaoPrestador(Nota.sCD_NFSEQ);
                    objLoteRps.Cnpj               = objTcRps.InfRps.Prestador.Cnpj;
                    objLoteRps.InscricaoMunicipal = objTcRps.InfRps.Prestador.InscricaoMunicipal;

                    #endregion

                    #region Tomador - TcDadosTomador

                    belTomador objbelTomador = new belTomador();
                    objTcRps.InfRps.Tomador = objbelTomador.RettcDadosTomador(Nota.sCD_NFSEQ);

                    #endregion

                    #region  ConstrucaoCivil - TcDadosContrucaoCivil - Tratado na Visualização da Nota

                    if (Acesso.NM_EMPRESA.Equals("AENGE"))
                    {
                        belConstrucaoCivil objbelConstrucaoCivil = new belConstrucaoCivil();
                        objTcRps.InfRps.ConstrucaoCivil = objbelConstrucaoCivil.RettcDadosConstrucaoCivil(Nota.sCD_NFSEQ);
                    }
                    #endregion

                    objLoteRps.Rps.Add(objTcRps);
                }
                daoUtil objdaoUtil = new daoUtil();
                objLoteRps.NumeroLote    = objdaoUtil.RetornaProximoValorGenerator("GEN_LOTE_NFES", 15);
                objLoteRps.QuantidadeRps = objLoteRps.Rps.Count;

                return(objLoteRps);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 8
0
 public belRecepcao(string sLoteXml, tcLoteRps objLoteRpsAlter)
 {
     this.sLoteXml        = sLoteXml;
     this.objLoteRpsAlter = objLoteRpsAlter;
     TransmitirLote();
 }
Esempio n. 9
0
 public void LimpaRecibo(tcLoteRps objListaLote)
 {
     StringBuilder sSql = new StringBuilder();
     try
     {
         for (int i = 0; i < objListaLote.Rps.Count; i++)
         {
             ApagaRecibo(objLoteRpsAlter.Rps[i].InfRps.IdentificacaoRps.Nfseq);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 10
0
 public belRecepcao(string sLoteXml, tcLoteRps objLoteRpsAlter)
 {
     this.sLoteXml = sLoteXml;
     this.objLoteRpsAlter = objLoteRpsAlter;
     TransmitirLote();
 }