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));
            }
        }
Ejemplo n.º 2
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;
            }
        }