Beispiel #1
0
        public dynamic BuscarSaldoCD(DateTime DT_REFERENCIA, int SQ_CONTRATO_TRABALHO, int SQ_PLANO_PREVIDENCIAL, int CD_PESSOA)
        {
            var saldoIndividual = base.BuscarIndividualPorPlanoDataReferenciaPessoa(DateTime.Now, SQ_PLANO_PREVIDENCIAL, CD_PESSOA, "E");
            var saldoPatronal   = base.BuscarIndividualPorPlanoDataReferenciaPessoa(DateTime.Now, SQ_PLANO_PREVIDENCIAL, CD_PESSOA, "D");

            var plano = new PlanoVinculadoProxy().BuscarPorContratoTrabalhoPlano(SQ_CONTRATO_TRABALHO, SQ_PLANO_PREVIDENCIAL);

            var indice = new IndiceProxy().BuscarPorCdIndice(plano.CD_INDICE_VALORIZACAO);

            var valorSaldoIndividual = saldoIndividual.QT_COTA_CONTRIBUICAO ?? 0;
            var valorsaldoPatronal   = saldoPatronal.QT_COTA_CONTRIBUICAO ?? 0;

            var valorContribIndividalAtualizado = (valorSaldoIndividual) * indice.First().VL_INDICE.Value;
            var valorContribPatronalAtualizado  = (valorsaldoPatronal) * indice.First().VL_INDICE.Value;
            var valorTotal    = valorContribIndividalAtualizado + valorContribPatronalAtualizado;
            var rentabilidade = valorTotal - (saldoIndividual.VL_CONTRIBUICAO + saldoPatronal.VL_CONTRIBUICAO);

            return(new
            {
                SaldoIndividual = saldoIndividual.VL_CONTRIBUICAO,
                SaldoPatronal = saldoPatronal.VL_CONTRIBUICAO,
                Total = (saldoIndividual.VL_CONTRIBUICAO + saldoPatronal.VL_CONTRIBUICAO) + rentabilidade,
                Rentabilidade = rentabilidade
            });
        }
Beispiel #2
0
        public dynamic BuscarSaldoBD(DateTime DT_REFERENCIA, int SQ_CONTRATO_TRABALHO, int SQ_PLANO_PREVIDENCIAL, int CD_PESSOA)
        {
            // Busca valor bruto da reserva individual
            var lista           = base.BuscarBrutoPorPlanoReferenciaPessoa(DT_REFERENCIA, SQ_PLANO_PREVIDENCIAL, CD_PESSOA).ToList();
            var valIndiceFaceb1 = new IndiceProxy().BuscarUltimoPorCdIndice("FACEB I").VL_INDICE;

            var brutoReservaIndividual = lista.Sum(x => (x.QT_COTA_CONTRIBUICAO * x.VL_RESGATE / 100) * valIndiceFaceb1);

            // Busca taxa adm
            var taxaAdm = BuscarTaxaAdm(DT_REFERENCIA, SQ_PLANO_PREVIDENCIAL, SQ_CONTRATO_TRABALHO).QT_COTA_CONTRIBUICAO *valIndiceFaceb1;

            var contribuicoesAntes2011 = BuscarAutopatrocinioPorReferenciaAnterior(new DateTime(2011, 12, 31), SQ_PLANO_PREVIDENCIAL, SQ_CONTRATO_TRABALHO).QT_COTA_CONTRIBUICAO *valIndiceFaceb1;
            var contribuicoesApos2011  = BuscarAutopatrocinioPorReferenciaApos(new DateTime(2011, 12, 31), SQ_PLANO_PREVIDENCIAL, SQ_CONTRATO_TRABALHO).QT_COTA_CONTRIBUICAO *valIndiceFaceb1;

            var reservaIndividual = brutoReservaIndividual - taxaAdm;
            var autopatrocinio    = (contribuicoesApos2011 * 0.9M) + contribuicoesAntes2011;

            if (autopatrocinio == null)
            {
                autopatrocinio = 0;
            }

            return(new
            {
                ReservaIndividual = reservaIndividual,
                SaldoContaAutopatrocinio = autopatrocinio,
                Resgate = (reservaIndividual * 1.35M) + autopatrocinio,
                Portabilidade = (reservaIndividual * 2M) + autopatrocinio
            });
        }
        public IActionResult BuscarPorPlano(string cdPlano)
        {
            try
            {
                var plano     = new PlanoVinculadoProxy().BuscarPorFundacaoEmpresaMatriculaPlano(CdFundacao, CdEmpresa, Matricula, cdPlano);
                var histSaldo = new HistSaldoProxy().BuscarPorFundacaoEmpresaPlanoEspecieNumAnoProcesso(CdFundacao, CdEmpresa, cdPlano,
                                                                                                        plano.ProcessoBeneficio.CD_ESPECIE, plano.ProcessoBeneficio.NUM_PROCESSO, plano.ProcessoBeneficio.ANO_PROCESSO);

                var empresaPlano = new EmpresaPlanosProxy().BuscarPorFundacaoEmpresaPlano(CdFundacao, CdEmpresa, cdPlano);
                var indice       = new IndiceProxy().BuscarUltimoPorCodigo(empresaPlano.IND_RESERVA_POUP);

                var dataCota = indice.VALORES.First().DT_IND;

                var valorIndice = indice.BuscarValorEm(dataCota);

                var totalCotas = histSaldo.First().SALDO_ATUAL;
                var total      = totalCotas * valorIndice;

                return(Json(new
                {
                    TotalCotas = totalCotas,
                    Valor = total,
                    Parcela = histSaldo.First().QTD
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        decimal CalcularINSSHipotetico(int sqPlano)
        {
            var indiceProxy = new IndiceProxy();

            var dtFim = DateTime.Now.AddMonths(-1).DefinirDia(1);
            var dtIni = dtFim.AddMonths(-36);

            var indiceINPC = indiceProxy.BuscarPorCdIndicePeriodo("INPC", dtIni, dtFim);

            var fatores = new List <KeyValuePair <DateTime, decimal> >();

            var fatorAnterior = 1M;

            foreach (var indice in indiceINPC)
            {
                var fator = (fatorAnterior * (1 + indice.VL_INDICE.Value / 100)).Arredonda(6);
                fatores.Add(new KeyValuePair <DateTime, decimal>(indice.DT_INIC_VALIDADE, fator));
                fatorAnterior = fator;
            }

            var indiceTETOPREV     = indiceProxy.BuscarPorCdIndice("TETOPREV");
            var salarios           = new SalarioContribuicaoProxy().BuscarPorContratoTrabalhoPlanoPeriodo(SqContratoTrabalho, sqPlano, dtIni, dtFim);
            var salariosCorrigidos = new List <KeyValuePair <DateTime, decimal> >();

            foreach (var salario in salarios)
            {
                var dtReferencia = salario.DT_REFERENCIA;
                var teto         = indiceTETOPREV.FirstOrDefault(x => x.DT_INIC_VALIDADE <= dtReferencia);

                if (teto == null)
                {
                    throw new Exception($"Índice TETOPREV não encontrado para a referência {dtReferencia.ToString("dd/MM/yyyy")}");
                }

                if (!salario.VL_BASE_PREVIDENCIA.HasValue)
                {
                    throw new Exception($"Salário de contribuição não encontrado na data de {salario.DT_REFERENCIA}");
                }

                var valor = Math.Min(salario.VL_BASE_PREVIDENCIA.Value, teto.VL_INDICE.Value);
                var fator = fatores.First(x => x.Key <= dtReferencia);

                valor = valor * fator.Value;

                salariosCorrigidos.Add(new KeyValuePair <DateTime, decimal>(dtReferencia, valor));
            }

            var inssHipotetico = salariosCorrigidos.Sum(x => x.Value) / 36;

            inssHipotetico = Math.Min(inssHipotetico, indiceTETOPREV.First().VL_INDICE.Value);
            return(inssHipotetico);
        }
        public decimal BuscarTaxaJurosComIndice()
        {
            DateTime dtIndice;
            decimal  taxaJuros = TaxaConcessao.TX_JUROS.Value;

            if ((TaxaConcessao.COD_IND != "") & (TaxaConcessao.IND_CALC_PREST_CONC == DMN_SN.SIM))
            {
                if (TaxaConcessao.IND_DEFAZAGEM == DMN_SN.SIM &&
                    TaxaConcessao.IND_MESES_DEFAZAGEM > 0)
                {
                    dtIndice = DateTime.Today.AddMonths(-1 * (int)TaxaConcessao.IND_MESES_DEFAZAGEM);
                }
                else
                {
                    dtIndice = DateTime.Today;
                }

                dtIndice = dtIndice.UltimoDiaDoMes();

                var indice = new IndiceProxy().BuscarPorCodigo(TaxaConcessao.COD_IND);

                decimal vlIndice = 0;
                if (indice == null)
                {
                    return(taxaJuros);
                }
                else
                {
                    if (TaxaConcessao.TIPO_IND == "V")
                    {
                        vlIndice = (indice.ObtemVariacaoEm(dtIndice) / 100) + 1;
                    }
                    else
                    {
                        vlIndice = (indice.ObtemValorEm(dtIndice) / 100) + 1;
                    }
                }

                return(((vlIndice * ((taxaJuros / 100) + 1)) - 1) * 100);
            }
            else
            {
                return(taxaJuros);
            }
        }
        public decimal CalcularPrestacao(decimal valorLiquido, decimal taxaJuros, decimal prazo, decimal valorAtualizacao, decimal carencia)
        {
            decimal valorPrestacao = 0;

            if (Modalidade.RESULTADO_CORRE == "A")
            {
                decimal saldo         = 0;
                decimal saldoAnterior = valorLiquido + valorAtualizacao;
                decimal jurosAxuliar  = 0;

                for (int z = 0; z < carencia; z++)
                {
                    var dataIndice     = DateTime.Today.AddMonths(-2 + z);
                    var indiceCorrecao = new IndiceProxy().BuscarVariacaoEm("IPCA", dataIndice);

                    jurosAxuliar = (saldoAnterior * (taxaJuros / 100)).Arredonda(2);
                    saldo        = (saldoAnterior + jurosAxuliar).Arredonda(2);

                    if (Modalidade.CD_MODAL == 2 && indiceCorrecao >= 0)
                    {
                        var correcao = (saldo * (indiceCorrecao / 100)).Arredonda(2);
                        saldo = (saldo + correcao).Arredonda(2);
                    }

                    saldoAnterior = saldo;
                }

                if (saldo > 0)
                {
                    saldo = saldo - (valorLiquido + valorAtualizacao);
                }

                valorPrestacao = ObtemUmaPrestacao((valorLiquido + valorAtualizacao + saldo), taxaJuros, prazo);
            }
            else
            {
                valorPrestacao = ObtemUmaPrestacao(valorLiquido, taxaJuros, prazo);
            }

            valorPrestacao = AplicaTaxas(valorPrestacao, 0, DMN_TP_COBRANCA_TX.COBRANCA_NA_PRESTACAO);

            return(valorPrestacao);
        }
        public decimal ObterFatorAtualizacao(DateTime dtCredito)
        {
            TimeSpan w_dif_dias;
            decimal  w_calc, w_fator;
            DateTime w_dt_ind, w_dt_aux;
            int      w_num_dias;

            w_calc  = 0;
            w_fator = 0;

            if ((Modalidade.PRORATA_TX_JUROS == DMN_SN.NAO) & (Modalidade.CORRIGIR) == DMN_SN.SIM)
            {
                if (Modalidade.DIA_CORRECAO == "U")
                {
                    w_num_dias = dtCredito.UltimoDiaDoMes().Day;
                }
                else
                {
                    w_num_dias = 30;
                }

                w_dt_aux = new DatasEmprestimo(Natureza).ObterDataAniversarioNatureza(dtCredito);

                w_dif_dias = w_dt_aux - dtCredito;
                //w_dif_dias = w_dt_aux - dtCredito;

                if (string.IsNullOrEmpty(Modalidade.IND_CORR_VL_SOLIC))
                {
                    w_calc   = (decimal)Math.Pow((double)((TaxaConcessao.TX_JUROS.Value / 100) + 1), (1 / (double)w_num_dias));
                    w_fator  = (decimal)Math.Pow((double)w_calc, w_dif_dias.Days);
                    w_fator -= 1;
                    //w_vl_corrigido = (ValorSolicitado * w_fator).Arredonda(2);
                }
                else
                {
                    /* if ((txConcessao.IND_DEFAZAGEM == DMN_SN.SIM) & (txConcessao.IND_MESES_DEFAZAGEM > 0))
                     *   w_dt_ind = dtCredito.AddMonths(-1 * (int)txConcessao.IND_MESES_DEFAZAGEM);
                     * else*/
                    w_dt_ind = dtCredito;

                    w_dt_ind = new DateTime(w_dt_ind.Year, w_dt_ind.Month, w_dt_ind.UltimoDiaDoMes().Day);

                    var indice = new IndiceProxy().BuscarPorCodigo(Modalidade.IND_CORR_VL_SOLIC);

                    if (indice == null)
                    {
                        throw new Exception("Não localizou o índice para a modalidade");
                    }
                    else
                    {
                        var utilizaDefazagem = TaxaConcessao.IND_CALC_PREST_CONC == DMN_SN.SIM &&
                                               TaxaConcessao.IND_DEFAZAGEM == DMN_SN.SIM;

                        int mesesDefazagem = utilizaDefazagem ?
                                             (int)TaxaConcessao.IND_MESES_DEFAZAGEM.Value : 0;

                        var variacao = indice.ObtemVariacaoEm(w_dt_ind.AddMonths(-mesesDefazagem));

                        if (TaxaConcessao.TIPO_IND == "V")
                        {
                            w_calc =
                                (decimal)
                                Math.Pow(
                                    (double)(((TaxaConcessao.TX_JUROS.Value / 100) + 1) * (1 + ((variacao) / 100))),
                                    (double)1 / w_num_dias);
                        }
                        else
                        {
                            w_calc =
                                (decimal)
                                Math.Pow((double)(((TaxaConcessao.TX_JUROS.Value / 100) + 1) * (1 + ((variacao) / 100))),
                                         (double)1 / w_num_dias);
                        }
                    }

                    w_fator = (decimal)Math.Pow((double)w_calc, w_dif_dias.Days);

                    // w_vl_corrigido = (ValorSolicitado * (w_fator - 1)).Arredonda(2);
                }
            }

            return(w_fator);
        }
Beispiel #8
0
        public static void PreencherSaldo(this SaldoContribuicoesEntidade saldo, List <FichaFinanceiraEntidade> contribuicoes, string cdFundacao, string cdEmpresa, string cdPlano, string numInscricao, string cdFundo = null, string dataSaldo = null)
        {
            //saldo.DataReferencia = DateTime.ParseExact($"01/{contribuicoes.First().MES_REF}/{contribuicoes.First().ANO_REF}", "dd/MM/yyyy", new CultureInfo("pt-BR"));
            saldo.DataReferencia = DateTime.Now;

            var func           = new FuncionarioProxy().BuscarPorInscricao(numInscricao);
            var plano          = new PlanoProxy().BuscarPorCodigo(cdPlano);
            var planoVinculado = new PlanoVinculadoProxy().BuscarPorFundacaoEmpresaMatriculaPlano(cdFundacao, cdEmpresa, func.NUM_MATRICULA, cdPlano);
            var empresaPlano   = new EmpresaPlanosProxy().BuscarPorFundacaoEmpresaPlano(cdFundacao, cdEmpresa, cdPlano);

            IndiceEntidade indice;

            if (plano.UTILIZA_PERFIL == "S")
            {
                var perfil = new PerfilInvestIndiceProxy().BuscarPorFundacaoEmpresaPlanoPerfilInvest(cdFundacao, cdEmpresa, cdPlano, planoVinculado.CD_PERFIL_INVEST.ToString());
                indice = new IndiceProxy().BuscarUltimoPorCodigo(perfil.CD_CT_RP);
            }
            else
            {
                indice = new IndiceProxy().BuscarPorCodigo(empresaPlano.IND_RESERVA_POUP);
            }

            var dataCota = indice.VALORES.First().DT_IND;

            if (dataSaldo != null)
            {
                dataCota = Convert.ToDateTime(dataSaldo);
            }


            var valorIndice = indice.BuscarValorEm(dataCota);

            if (cdFundo != null)
            {
                var fundoContrib = new FundoContribProxy().BuscarPorFundacaoPlanoFundo(cdFundacao, cdPlano, cdFundo);

                contribuicoes = contribuicoes.Select(contrib =>
                {
                    if (fundoContrib.Any(fundo => fundo.CD_TIPO_CONTRIBUICAO == contrib.CD_TIPO_CONTRIBUICAO))
                    {
                        contrib.FundoContrib = fundoContrib.First(x => x.CD_TIPO_CONTRIBUICAO == contrib.CD_TIPO_CONTRIBUICAO);
                        return(contrib);
                    }

                    return(null);
                })
                                .Where(x => x != null)
                                .ToList();
            }

            foreach (var contribuicao in contribuicoes)
            {
                var dataReferencia = new DateTime();

                try
                {
                    dataReferencia = new DateTime(Convert.ToInt32(contribuicao.ANO_REF), Convert.ToInt32(contribuicao.MES_REF), 1);
                }
                catch (Exception ex)
                { }

                if (dataReferencia <= dataCota)
                {
                    var valorCotaRPParticipante = 0M;
                    var valorCotaRPEmpresa      = 0M;

                    if (cdFundo != null)
                    {
                        switch (contribuicao.FundoContrib.CD_MANTENEDORA)
                        {
                        case DMN_MANTENEDORA.EMPRESA:
                            //valorCotaRPParticipante = contribuicao.QTD_COTA_RP_EMPRESA ?? 0;
                            valorCotaRPEmpresa = contribuicao.QTD_COTA_RP_EMPRESA ?? 0;
                            break;

                        case DMN_MANTENEDORA.PARTICIPANTE:
                            valorCotaRPParticipante = contribuicao.QTD_COTA_RP_PARTICIPANTE ?? 0;
                            //valorCotaRPEmpresa = contribuicao.QTD_COTA_RP_PARTICIPANTE ?? 0;
                            break;

                        case DMN_MANTENEDORA.AMBOS:
                            valorCotaRPParticipante = (contribuicao.QTD_COTA_RP_PARTICIPANTE ?? 0) + (contribuicao.QTD_COTA_RP_EMPRESA ?? 0);
                            valorCotaRPEmpresa      = (contribuicao.QTD_COTA_RP_PARTICIPANTE ?? 0) + (contribuicao.QTD_COTA_RP_EMPRESA ?? 0);
                            break;
                        }
                    }
                    else
                    {
                        valorCotaRPParticipante = contribuicao.QTD_COTA_RP_PARTICIPANTE ?? 0;
                        valorCotaRPEmpresa      = contribuicao.QTD_COTA_RP_EMPRESA ?? 0;
                    }

                    if (contribuicao.CD_OPERACAO == "C")
                    {
                        saldo.QuantidadeCotasParticipante += valorCotaRPParticipante;
                    }
                    else
                    {
                        saldo.QuantidadeCotasParticipante -= valorCotaRPParticipante;
                    }

                    if (contribuicao.CD_OPERACAO == "C")
                    {
                        saldo.QuantidadeCotasPatrocinadora += valorCotaRPEmpresa;
                    }
                    else
                    {
                        saldo.QuantidadeCotasPatrocinadora -= valorCotaRPEmpresa;
                    }
                }

                saldo.ValorParticipante  = saldo.QuantidadeCotasParticipante * valorIndice;
                saldo.ValorPatrocinadora = saldo.QuantidadeCotasPatrocinadora * valorIndice;
                saldo.DataCota           = dataCota;
                saldo.ValorCota          = valorIndice;
            }
        }