Example #1
0
        public tcLoteRps BuscaDadosNFes(List<string> sListaNotas)
        {
            belConnection cx = new belConnection();            
            try
            {                
                objLoteRps = new tcLoteRps();

                objLoteRps.Rps = new List<TcRps>();
                foreach (string sNota in sListaNotas)
                {
                    TcRps objTcRps = new TcRps();

                    //IdentificacaoRps - TcIdentificacaoRps
                    daotcIdentificacaoRps objdaotcIdentificacaoRps = new daotcIdentificacaoRps();
                    objTcRps.InfRps = new TcInfRps();

                    StringBuilder sQuery = new StringBuilder();
                    sQuery.Append("SELECT   coalesce (tpdoc.cd_natureza_oper_nfse,'1')cd_natureza_oper_nfse , ");
                    sQuery.Append("coalesce (empresa.st_simples,'')st_simples , ");
                    sQuery.Append("coalesce (empresa.cd_regime_trib_especial,'0')RegimeEspecialTributacao , ");
                    sQuery.Append("coalesce (empresa.st_insentivador_cultural,'N')st_insentivador_cultural from nf ");
                    sQuery.Append("inner join tpdoc on nf.cd_tipodoc = tpdoc.cd_tipodoc ");
                    sQuery.Append("inner join empresa on empresa.cd_empresa = nf.cd_empresa ");
                    sQuery.Append(" where nf.cd_nfseq = '" + sNota + "' and ");
                    sQuery.Append(" nf.cd_empresa = '" + belStatic.codEmpresaNFe + "'");

                    FbCommand Command = new FbCommand(sQuery.ToString(), cx.get_Conexao());
                    cx.Open_Conexao();
                    Command.ExecuteNonQuery();
                    FbDataReader dr = Command.ExecuteReader();
                    dr.Read();

                    
                    objTcRps.InfRps.DataEmissao = HLP.Util.Util.GetDateServidor();
                    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);

                    objTcRps.InfRps.Status = 1;//Normal;

                    if (objTcRps.InfRps.OptanteSimplesNacional == 1)
                    {
                        objTcRps.InfRps.RegimeEspecialTributacao = Convert.ToInt16(dr["RegimeEspecialTributacao"].ToString());
                    }
                    else
                    {
                        objTcRps.InfRps.RegimeEspecialTributacao = 0;
                    }


                    objTcRps.InfRps.IdentificacaoRps = objdaotcIdentificacaoRps.BuscatcIdentificacaoRps(cx.get_Conexao(), sNota);


                    //RpsSubstituido - TcIdentificacaoRps // Método tratado na visualização da Nota;
                    //daoRpsSubstituido objdaoRpsSubstituido = new daoRpsSubstituido();
                    //objTcRps.InfRps.RpsSubstituido = objdaoRpsSubstituido.RetornaIdentificacaoRpds(Conn, sNota);

                    //Servico - TcDadosServico
                    daoServico objdaoServico = new daoServico();
                    objTcRps.InfRps.Servico = objdaoServico.RetornaDadosServico(cx.get_Conexao(), sNota, objTcRps.InfRps.NaturezaOperacao);


                    //Prestador - tcIdentificacaoPrestador
                    daoPrestador objdaoPrestador = new daoPrestador();
                    objTcRps.InfRps.Prestador = objdaoPrestador.RettcIdentificacaoPrestador(cx.get_Conexao(), sNota);
                    objLoteRps.Cnpj = objTcRps.InfRps.Prestador.Cnpj; // Tag Pai;
                    objLoteRps.InscricaoMunicipal = objTcRps.InfRps.Prestador.InscricaoMunicipal; //Tag Pai;


                    //Tomador - TcDadosTomador
                    daoTomador objdaoTomador = new daoTomador();
                    objTcRps.InfRps.Tomador = objdaoTomador.RettcDadosTomador(cx.get_Conexao(), sNota);

                    //IntermediarioServico - tcIdentificacaoIntermediarioServico  //Tratado na visualização da Nota
                    //daoIntermediarioServico objdaoIntermediarioServico = new daoIntermediarioServico();
                    //objTcRps.InfRps.IntermediarioServico = objdaoIntermediarioServico.RettcIdentificacaoIntermediarioServico(Conn, sNota);

                    //ConstrucaoCivil - TcDadosContrucaoCivil - Tratado na Visualização da Nota
                    if (belStatic.sNomeEmpresa.Equals("AENGE"))
                    {
                        daoConstrucaoCivil objdaoConstrucaoCivil = new daoConstrucaoCivil();
                        objTcRps.InfRps.ConstrucaoCivil = objdaoConstrucaoCivil.RettcDadosConstrucaoCivil(cx.get_Conexao(), sNota);                       
                    }
                    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;
            }
            finally
            {
                cx.Close_Conexao();
            }
        }
Example #2
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;
            }
        }