public IActionResult Get()
        {
            try
            {
                var funcionario = new FuncionarioProxy().BuscarPorCodEntid(CodEntid);
                var plano       = new PlanoVinculadoProxy().BuscarPorFundacaoEmpresaMatricula(funcionario.CD_FUNDACAO, funcionario.CD_EMPRESA, Matricula).First();

                return(Json(new DependenteProxy().BuscarPorFundacaoInscricaoPlano(funcionario.CD_FUNDACAO, funcionario.NUM_INSCRICAO, plano.CD_PLANO)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo 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;
            }
        }
        public IActionResult Criar([FromBody] MensagemEntidade mensagem)
        {
            try
            {
                var funcionarioProxy = new FuncionarioProxy();

                mensagem.CD_EMPRESA    = mensagem.CD_EMPRESA == string.Empty ? null : mensagem.CD_EMPRESA;
                mensagem.CD_PLANO      = mensagem.CD_PLANO == string.Empty ? null : mensagem.CD_PLANO;
                mensagem.CD_SIT_PLANO  = mensagem.CD_SIT_PLANO == string.Empty ? null : mensagem.CD_SIT_PLANO;
                mensagem.NUM_MATRICULA = mensagem.NUM_MATRICULA.Replace("_", "").PadLeft(9, '0');

                if (!mensagem.DTA_EXPIRACAO.HasValue)
                {
                    mensagem.DTA_EXPIRACAO = null;
                }
                else
                {
                    mensagem.DTA_EXPIRACAO = mensagem.DTA_EXPIRACAO;
                }

                if (string.IsNullOrEmpty(mensagem.NUM_MATRICULA))
                {
                    mensagem.COD_ENTID = null;
                }
                else
                {
                    mensagem.COD_ENTID = funcionarioProxy.BuscarPorMatricula(mensagem.NUM_MATRICULA).COD_ENTID;
                }

                mensagem.DTA_MENSAGEM = DateTime.Now;

                // Se opção de enviar e-mail for habilitada
                if (mensagem.IND_EMAIL == DMN_SIM_NAO.SIM)
                {
                    var listaDestinatarios = funcionarioProxy.BuscarPorPesquisa(mensagem.CD_FUNDACAO, mensagem.CD_EMPRESA, mensagem.CD_PLANO, mensagem.CD_SIT_PLANO, mensagem.NUM_MATRICULA, string.Empty, string.Empty);

                    foreach (var destinatario in listaDestinatarios)
                    {
                        var dadosDestinatario = funcionarioProxy.BuscarDadosPorCodEntid(destinatario.COD_ENTID.ToString());

                        if (string.IsNullOrEmpty(dadosDestinatario.DadosPessoais.EMAIL_AUX))
                        {
                            throw new Exception("Não existe email cadastrado para seu usuário contacte o administrador do sistema.");
                        }

                        try
                        {
                            var emailConfig = AppSettings.Get().Email;
                            EnvioEmail.Enviar(emailConfig, dadosDestinatario.DadosPessoais.EMAIL_AUX, mensagem.TXT_TITULO, mensagem.TXT_CORPO);
                        }
                        catch (Exception e)
                        {
                            throw new Exception("Erro ao enviar o token por email. Contacte o administrador do sistema." + e.Message);
                        }
                    }
                }

                new MensagemProxy().Insert(mensagem);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }