Example #1
0
        public bool InserirPessoaDocumento(decimal CodigoDocumento, long CodigoPessoa, int TipoPessoa)
        {
            if (CodigoPessoa == 0)
            {
                return(true);
            }

            try
            {
                AbrirConexao();

                string strCamposPessoa  = "CD_DOCUMENTO";
                string strValoresPessoa = "@v25";

                strCamposPessoa  += ", TP_PESSOA";
                strValoresPessoa += ", @v26";

                strCamposPessoa  += ", CD_PESSOA";
                strValoresPessoa += ", @v27";

                strCamposPessoa  += ", RAZ_SOCIAL";
                strValoresPessoa += ", @v28";

                strCamposPessoa  += ", INSCRICAO";
                strValoresPessoa += ", @v29";

                strCamposPessoa  += ", INS_ESTADUAL";
                strValoresPessoa += ", @v30";

                strCamposPessoa  += ", TELEFONE_1";
                strValoresPessoa += ", @v31";

                strCamposPessoa  += ", EMAIL_NFE";
                strValoresPessoa += ", @v32";

                strCamposPessoa  += ", EMAIL";
                strValoresPessoa += ", @v33";

                strCamposPessoa  += ", LOGRADOURO";
                strValoresPessoa += ", @v34";

                strCamposPessoa  += ", NR_ENDERECO";
                strValoresPessoa += ", @v35";

                strCamposPessoa  += ", COMPLEMENTO";
                strValoresPessoa += ", @v36";

                strCamposPessoa  += ", CD_CEP";
                strValoresPessoa += ", @v37";

                strCamposPessoa  += ", CD_MUNICIPIO";
                strValoresPessoa += ", @v38";

                strCamposPessoa  += ", CD_BAIRRO";
                strValoresPessoa += ", @v39";

                strCamposPessoa  += ", DS_BAIRRO";
                strValoresPessoa += ", @v40";

                strCamposPessoa  += ", EMAIL_NFSE";
                strValoresPessoa += ", @v41";

                strSQL = "insert into PESSOA_DO_DOCUMENTO (" + strCamposPessoa + ") values (" + strValoresPessoa + "); SELECT SCOPE_IDENTITY();";

                Cmd = new SqlCommand(strSQL, Con);


                PessoaDAL pessoaDAL = new PessoaDAL();
                Pessoa    pessoa    = new Pessoa();
                pessoa = pessoaDAL.PesquisarPessoa(CodigoPessoa);

                PessoaContatoDAL pesCttDAL = new PessoaContatoDAL();
                Pessoa_Contato   pesCtt    = new Pessoa_Contato();
                pesCtt = pesCttDAL.PesquisarPessoaContato(CodigoPessoa, 1);

                PessoaEnderecoDAL pesEndDAL = new PessoaEnderecoDAL();
                Pessoa_Endereco   pesEnd    = new Pessoa_Endereco();
                pesEnd = pesEndDAL.PesquisarPessoaEndereco(CodigoPessoa, 1);

                PessoaInscricaoDAL pesInsDAL = new PessoaInscricaoDAL();
                Pessoa_Inscricao   pesIns    = new Pessoa_Inscricao();
                pesIns = pesInsDAL.PesquisarPessoaInscricao(CodigoPessoa, 1);

                Cmd.Parameters.AddWithValue("@v25", CodigoDocumento);
                Cmd.Parameters.AddWithValue("@v26", TipoPessoa);
                Cmd.Parameters.AddWithValue("@v27", CodigoPessoa);
                Cmd.Parameters.AddWithValue("@v28", pessoa.NomePessoa);
                Cmd.Parameters.AddWithValue("@v29", pesIns._NumeroInscricao);
                Cmd.Parameters.AddWithValue("@v30", pesIns._NumeroIERG);
                Cmd.Parameters.AddWithValue("@v31", pesCtt._Fone1);
                Cmd.Parameters.AddWithValue("@v32", pesCtt._MailNFE);
                Cmd.Parameters.AddWithValue("@v33", pesCtt._Mail1);
                Cmd.Parameters.AddWithValue("@v34", pesEnd._Logradouro);
                Cmd.Parameters.AddWithValue("@v35", pesEnd._NumeroLogradouro);
                Cmd.Parameters.AddWithValue("@v36", pesEnd._Complemento);
                Cmd.Parameters.AddWithValue("@v37", pesEnd._CodigoCEP);
                Cmd.Parameters.AddWithValue("@v38", pesEnd._CodigoMunicipio);
                Cmd.Parameters.AddWithValue("@v39", pesEnd._CodigoBairro);
                Cmd.Parameters.AddWithValue("@v40", pesEnd._DescricaoBairro);
                Cmd.Parameters.AddWithValue("@v41", pesCtt._MailNFSE);
                Cmd.ExecuteNonQuery();

                return(true);
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0)                 // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao Incluir pessoa do documento: " + ex.Message.ToString());
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar Pessoa do documento: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
Example #2
0
        public bool AtualizarPessoaDocumento(decimal CodigoDocumento, long CodigoPessoa, int TipoPessoa)
        {
            try
            {
                AbrirConexao();

                strSQL = "update PESSOA_DO_DOCUMENTO set TP_PESSOA = @v26," +
                         "CD_PESSOA = @v27," +
                         "RAZ_SOCIAL = @v28," +
                         "INSCRICAO = @v29," +
                         "INS_ESTADUAL = @v30," +
                         "TELEFONE_1 = @v31," +
                         "EMAIL_NFE = @v32," +
                         "EMAIL = @v33," +
                         "LOGRADOURO = @v34," +
                         "NR_ENDERECO = @v35," +
                         "COMPLEMENTO = @v36," +
                         "CD_CEP = @v37," +
                         "CD_MUNICIPIO = @v38," +
                         "CD_BAIRRO = @v39," +
                         "DS_BAIRRO = @v40," +
                         "EMAIL_NFSE = @v41 where CD_DOCUMENTO = @v25 AND TP_PESSOA = @v26";
                Cmd = new SqlCommand(strSQL, Con);

                PessoaDAL pessoaDAL = new PessoaDAL();
                Pessoa    pessoa    = new Pessoa();
                pessoa = pessoaDAL.PesquisarPessoa(CodigoPessoa);

                PessoaContatoDAL pesCttDAL = new PessoaContatoDAL();
                Pessoa_Contato   pesCtt    = new Pessoa_Contato();
                pesCtt = pesCttDAL.PesquisarPessoaContato(CodigoPessoa, 1);

                PessoaEnderecoDAL pesEndDAL = new PessoaEnderecoDAL();
                Pessoa_Endereco   pesEnd    = new Pessoa_Endereco();
                pesEnd = pesEndDAL.PesquisarPessoaEndereco(CodigoPessoa, 1);

                PessoaInscricaoDAL pesInsDAL = new PessoaInscricaoDAL();
                Pessoa_Inscricao   pesIns    = new Pessoa_Inscricao();
                pesIns = pesInsDAL.PesquisarPessoaInscricao(CodigoPessoa, 1);

                Cmd.Parameters.AddWithValue("@v25", CodigoDocumento);
                Cmd.Parameters.AddWithValue("@v26", TipoPessoa);
                Cmd.Parameters.AddWithValue("@v27", CodigoPessoa);
                Cmd.Parameters.AddWithValue("@v28", pessoa.NomePessoa);
                Cmd.Parameters.AddWithValue("@v29", pesIns._NumeroInscricao);
                Cmd.Parameters.AddWithValue("@v30", pesIns._NumeroIERG);
                Cmd.Parameters.AddWithValue("@v31", pesCtt._Fone1);
                Cmd.Parameters.AddWithValue("@v32", pesCtt._MailNFE);
                Cmd.Parameters.AddWithValue("@v33", pesCtt._Mail1);
                Cmd.Parameters.AddWithValue("@v34", pesEnd._Logradouro);
                Cmd.Parameters.AddWithValue("@v35", pesEnd._NumeroLogradouro);
                Cmd.Parameters.AddWithValue("@v36", pesEnd._Complemento);
                Cmd.Parameters.AddWithValue("@v37", pesEnd._CodigoCEP);
                Cmd.Parameters.AddWithValue("@v38", pesEnd._CodigoMunicipio);
                Cmd.Parameters.AddWithValue("@v39", pesEnd._CodigoBairro);
                Cmd.Parameters.AddWithValue("@v40", pesEnd._DescricaoBairro);
                Cmd.Parameters.AddWithValue("@v41", pesCtt._MailNFSE);

                Cmd.ExecuteNonQuery();
                return(true);
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0)                 // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:                             // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao Incluir PESSOA DO DOCUMENTO: " + ex.Message.ToString());
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar PESSOA DO DOCUMENTO" + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
Example #3
0
        public static ImpostoProdutoDocumento PreencherImpostosProdutoDocumento(ProdutoDocumento p, long intCodigoEmpresa, long longCodigoPessoa, int intCodigoTipoOperacao, int intCodigoAplicacaoUso, decimal decValorFrete, bool CalcularImpostos)
        {
            try
            {
                if (intCodigoTipoOperacao == 0)
                {
                    return(null);
                }

                ImpostoProdutoDocumento imp = new ImpostoProdutoDocumento();

                PIS    pis    = new PIS();
                PISDAL pisDAL = new PISDAL();

                COFINS    cofins    = new COFINS();
                COFINSDAL cofinsDAL = new COFINSDAL();

                RegFisIPI      ipi    = new RegFisIPI();
                RegraFisIPIDAL ipiDAL = new RegraFisIPIDAL();

                RegFisIcms    regICMS    = new RegFisIcms();
                RegFisIcmsDAL regICMSDAL = new RegFisIcmsDAL();

                TipoOperacao    tpOP    = new TipoOperacao();
                TipoOperacaoDAL tpOPDAL = new TipoOperacaoDAL();
                tpOP = tpOPDAL.PesquisarTipoOperacao(intCodigoTipoOperacao);

                Produto    produto    = new Produto();
                ProdutoDAL produtoDAL = new ProdutoDAL();
                produto = produtoDAL.PesquisarProduto(p.CodigoProduto);

                int CodigoPISUtilizado    = 0;
                int CodigoCOFINSUtilizado = 0;

                switch (tpOP.CodigoPrecedenciaImpostoPIS_COFINS)
                {
                case 159:
                    Pessoa    pessoa    = new Pessoa();
                    PessoaDAL pessoaDAL = new PessoaDAL();
                    if (produto.CodigoPIS != 0 || produto.CodigoCOFINS != 0)
                    {
                        pessoa = pessoaDAL.PesquisarPessoa(longCodigoPessoa);
                    }

                    //PIS
                    if (produto.CodigoPIS == 0)    //SE NÃO EXISTIR PIS NO PRODUTO
                    {
                        if (pessoa.CodigoPIS == 0)
                        {
                            CodigoPISUtilizado = tpOP.CodigoPIS;    //SE NÃO EXISTIR PIS NO PESSOA E PRODUTO
                        }
                        else
                        {
                            CodigoPISUtilizado = pessoa.CodigoPIS;
                        }
                    }
                    else
                    {
                        CodigoPISUtilizado = produto.CodigoPIS;
                    }
                    //FIM PIS

                    //COFINS
                    if (produto.CodigoCOFINS == 0)    //SE NÃO EXISTIR COFINS NO PRODUTO
                    {
                        if (pessoa.CodigoCOFINS == 0)
                        {
                            CodigoCOFINSUtilizado = tpOP.CodigoCOFINS;    //SE NÃO EXISTIR COFINS NO PESSOA E PRODUTO
                        }
                        else
                        {
                            CodigoCOFINSUtilizado = pessoa.CodigoCOFINS;
                        }
                    }
                    else
                    {
                        CodigoCOFINSUtilizado = produto.CodigoCOFINS;
                    }
                    //FIM COFINS

                    break;

                case 160:
                    //PIS
                    //FIM PIS

                    //COFINS
                    //FIM COFINS
                    break;
                }

                if (CodigoPISUtilizado != 0)
                {
                    pis = pisDAL.PesquisarPISIndice(CodigoPISUtilizado);
                }

                if (CodigoCOFINSUtilizado != 0)
                {
                    cofins = cofinsDAL.PesquisarCOFINSIndice(CodigoCOFINSUtilizado);
                }

                regICMS = regICMSDAL.ExecutaSP_BUSCA_REGRA_ICMS(intCodigoTipoOperacao, intCodigoEmpresa, longCodigoPessoa, intCodigoAplicacaoUso);

                imp.CodigoDocumento        = p.CodigoDocumento;
                imp.CodigoProdutoDocumento = p.CodigoItem;

                if (regICMS != null)
                {
                    imp.ValorMVA_Saida       = regICMS.MVAOriginal;
                    imp.ValorMVA_Entrada     = regICMS.MVAEntrada;
                    imp.PercentualICMS       = RetornaPercentualICMS(regICMS);
                    imp.ValorBaseCalculoICMS = p.ValorTotalItem;
                }

                //testar se exite IPI
                imp.ValorBaseCalculoIPI = p.ValorTotalItem;
                imp.PercentualIPI       = 5;

                if (pis != null)
                {
                    imp.ValorBaseCalculoPIS = p.ValorTotalItem;
                    imp.PercentualPIS       = Convert.ToDecimal(pis.ValorPIS);
                }

                if (cofins != null)
                {
                    imp.ValorBaseCalculoCOFINS = p.ValorTotalItem;
                    imp.PercentualCOFINS       = Convert.ToDecimal(cofins.ValorCOFINS);
                }


                if (CalcularImpostos)
                {
                    imp.ValorICMS   = Habil_Impostos.CalcularICMS(p.ValorTotalItem, imp.PercentualICMS, regICMS);
                    imp.ValorIPI    = Habil_Impostos.CalcularIPI(p.ValorTotalItem, imp.PercentualIPI);
                    imp.ValorPIS    = Habil_Impostos.CalcularPIS(p.ValorTotalItem, imp.PercentualPIS);
                    imp.ValorCOFINS = Habil_Impostos.CalcularCOFINS(p.ValorTotalItem, imp.PercentualCOFINS);
                }

                return(imp);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao calcular impostos: " + ex.Message.ToString());
            }
        }