public async Task <ExposureInfo> getCalculatedExposure(ExposureInfo exposureInfo)
        {
            try
            {
                exposureInfo.Calculated            = new Dictionary <string, Currency>();
                exposureInfo.CurrencyExchangeRates = new Dictionary <string, decimal>();
                var targetCurrency = _configurationService.GetEffective("offer/exposure/target-currency", "EUR").Result;
                var calculatedFieldsExposureConfig = await _configurationService.GetEffective <ListConfigurationCalculateExposure>("offer/exposure/calculated-fields", "");

                if (calculatedFieldsExposureConfig != null)
                {
                    decimal calculatedValue  = 0;
                    var     conversionMethod = _configurationService.GetEffective("offer/exposure/currency-conversion-method", "Buy to middle").Result;
                    foreach (ConfigurationCalculateExposure calcConfig in calculatedFieldsExposureConfig.ConfigurationCalculateExposure)
                    {
                        var allSoruces = calcConfig.Sources.Split(",");
                        foreach (var src in allSoruces)
                        {
                            object value = typeof(ExposureInfo).GetProperty(src.Trim()).GetValue(exposureInfo);
                            if (value != null)
                            {
                                ExposureList listEposure = (ExposureList)value;
                                foreach (var exposure in listEposure.Exposures)
                                {
                                    if (calcConfig.RiskCategories.Contains(exposure.RiskCategory))
                                    {
                                        var dv = typeof(Exposure).GetProperty(calcConfig.Column).GetValue(exposure);
                                        //if (!exposure.Currency.Equals(calcConfig.Currency))
                                        //{
                                        //    dv = new CurrencyConverter().CurrencyConvert((decimal)dv, exposure.Currency, calcConfig.Currency,
                                        //        DateTime.Today.ToString("o", CultureInfo.InvariantCulture), conversionMethod);
                                        //}
                                        calculatedValue += (decimal)dv;
                                    }
                                }
                            }
                        }
                        decimal convertedValue = new CurrencyConverter().CurrencyConvert(calculatedValue, targetCurrency, calcConfig.Currency,
                                                                                         DateTime.Today.ToString("o", CultureInfo.InvariantCulture), conversionMethod);
                        exposureInfo.Calculated.TryAdd(calcConfig.Name, new Currency()
                        {
                            Code = calcConfig.Currency, Amount = convertedValue
                        });
                        if (!calcConfig.Currency.Equals(targetCurrency))
                        {
                            exposureInfo.CurrencyExchangeRates.TryAdd(calcConfig.Currency, Math.Round(calculatedValue / convertedValue, 4));
                        }
                        calculatedValue = 0;
                    }
                }
                return(exposureInfo);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, "An error occured while calculating exposure extended fields");
                return(null);
            }
        }
Пример #2
0
        public async Task <ExposureList> GetExposureOnExternalApplications(string customerNumber)
        {
            try
            {
                var exposureList = new ExposureList
                {
                    Exposures = new List <Exposure>(),
                    TotalApprovedAmountInTargetCurrency = 0
                };
                var dataSourceConfig = await _configurationService.GetEffective <ExposureDataSourceConfiguration>("offer/exposure/other-sources", "");

                if (dataSourceConfig == null || dataSourceConfig.Count == 0)
                {
                    return(exposureList);
                }
                var taskList = new List <Task <ExposureInfo> >();
                foreach (var dataSource in dataSourceConfig)
                {
                    taskList.Add(GetDataSourceExposure(dataSource, customerNumber));
                }
                var externalExposures = await Task.WhenAll(taskList);

                foreach (var exposure in externalExposures)
                {
                    if (exposure?.NewExposureInOtherApplications?.Exposures != null)
                    {
                        _logger.LogDebug("Adding {NumOfExternalExposures} external exposures", exposure.NewExposureInOtherApplications.Exposures.Count());
                        exposureList.Exposures.AddRange(exposure.NewExposureInOtherApplications.Exposures);
                        exposureList.TotalApprovedAmountInTargetCurrency += exposure.NewExposureInOtherApplications.TotalApprovedAmountInTargetCurrency;
                    }
                    else
                    {
                        _logger.LogDebug("exposure?.NewExposureInOtherApplications?.Exposures is null");
                    }
                }
                return(exposureList);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
        public static void Configure(IMapperConfigurationExpression cfg, IServiceProvider serviceProvider)
        {
            #region Party
            cfg.CreateMap <EmploymentData, EmploymentDataAllDataView>()
            .ForMember(dest => dest.ContinousWorkPeriod, opt => opt.Ignore())
            .ForMember(dest => dest.EmploymentCount, opt => opt.Ignore())
            .ForAllOtherMembers(o => o.Condition((source) => true));

            cfg.CreateMap <Party, PartyAllDataView>()
            .Include <IndividualParty, IndividualPartyAllDataView>()
            .Include <OrganizationParty, OrganizationPartyAllDataView>()
            .ForMember(dest => dest.RelationshipCount, opt => opt.Ignore())
            .AfterMap((src, dest) =>
            {
                #region Exposure
                if (src.Application?.ExposureInfo != null)
                {
                    var exposure     = src.Application.ExposureInfo;
                    var riskCategory = ConfigurationRiskCategoryList(serviceProvider);
                    // CB exposure
                    var cbExposureForParty = new ExposureList
                    {
                        Exposures = exposure.CreditBureauExposure?.Exposures?
                                    .Where(e => e.PartyId == src.CustomerNumber)
                                    .ToList()
                    };
                    cbExposureForParty.TotalApprovedAmountInTargetCurrency = cbExposureForParty.
                                                                             Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureApprovedInTargetCurrency) ?? 0;
                    cbExposureForParty.TotalOutstandingAmountInTargetCurrency = cbExposureForParty.
                                                                                Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureOutstandingAmountInTargetCurrency) ?? 0;

                    // Current exposure
                    var currentExposureForParty = new ExposureList
                    {
                        Exposures = exposure.CurrentExposure?.Exposures?
                                    .Where(e => e.PartyId == src.CustomerNumber)
                                    .ToList()
                    };
                    currentExposureForParty.TotalApprovedAmountInTargetCurrency = currentExposureForParty.
                                                                                  Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureApprovedInTargetCurrency) ?? 0;
                    currentExposureForParty.TotalOutstandingAmountInTargetCurrency = currentExposureForParty.
                                                                                     Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureOutstandingAmountInTargetCurrency) ?? 0;

                    // new Expposure in other Apps
                    var newInOtherForParty = new ExposureList
                    {
                        Exposures = exposure.NewExposureInOtherApplications?.Exposures?
                                    .Where(e => e.PartyId == src.CustomerNumber)
                                    .ToList()
                    };
                    newInOtherForParty.TotalApprovedAmountInTargetCurrency = newInOtherForParty.
                                                                             Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureApprovedInTargetCurrency) ?? 0;
                    newInOtherForParty.TotalOutstandingAmountInTargetCurrency = newInOtherForParty.
                                                                                Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureOutstandingAmountInTargetCurrency) ?? 0;

                    // New Exposure in current App
                    var newInCurrentForParty = new ExposureList
                    {
                        Exposures = exposure.NewExposureInCurrentApplication?.Exposures?
                                    .Where(e => e.PartyId == src.CustomerNumber)
                                    .ToList()
                    };
                    newInCurrentForParty.TotalApprovedAmountInTargetCurrency = newInCurrentForParty.
                                                                               Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureApprovedInTargetCurrency) ?? 0;
                    newInCurrentForParty.TotalOutstandingAmountInTargetCurrency = newInCurrentForParty.
                                                                                  Exposures?.Where(x => riskCategory.Contains(x.RiskCategory)).Sum(e => e.ExposureOutstandingAmountInTargetCurrency) ?? 0;

                    Dictionary <string, Currency> calc = new Dictionary <string, Currency>();
                    foreach (var item in exposure.Calculated)
                    {
                        string newKey = item.Key.Replace(' ', '-').ToLower();
                        calc.TryAdd(newKey, item.Value);
                    }

                    dest.Exposure = new ExposureInfo
                    {
                        CreditBureauExposure            = cbExposureForParty,
                        CurrentExposure                 = currentExposureForParty,
                        NewExposureInOtherApplications  = newInOtherForParty,
                        NewExposureInCurrentApplication = newInCurrentForParty,
                        TotalCbApprovedExposureAmount   = cbExposureForParty.TotalApprovedAmountInTargetCurrency + newInOtherForParty.TotalApprovedAmountInTargetCurrency + newInCurrentForParty.TotalApprovedAmountInTargetCurrency,
                        TotalCbOutstandingAmount        = cbExposureForParty.TotalOutstandingAmountInTargetCurrency + newInOtherForParty.TotalOutstandingAmountInTargetCurrency + newInCurrentForParty.TotalOutstandingAmountInTargetCurrency,
                        TotalExposureApprovedAmount     = currentExposureForParty.TotalApprovedAmountInTargetCurrency + newInOtherForParty.TotalApprovedAmountInTargetCurrency + newInCurrentForParty.TotalApprovedAmountInTargetCurrency,
                        TotalExposureOutstandingAmount  = currentExposureForParty.TotalOutstandingAmountInTargetCurrency + newInOtherForParty.TotalOutstandingAmountInTargetCurrency + newInCurrentForParty.TotalOutstandingAmountInTargetCurrency,
                        TotalExposureCurrency           = exposure.TotalExposureCurrency,
                        Calculated            = calc,
                        CurrencyExchangeRates = exposure.CurrencyExchangeRates
                    };
                }
                #endregion

                if (src is IndividualParty individualParty && individualParty.FinancialProfile != null)
                {
                    var destFinancialProfile = (dest as IndividualPartyAllDataView).AsIndividual.FinancialProfile;
                    destFinancialProfile     = destFinancialProfile ?? new FinancialData
                    {
                        ExpenseInfo = new List <Expense>(),
                        IncomeInfo  = new List <Income>()
                    };
                    destFinancialProfile.TotalExpenses = CalculateTotal(destFinancialProfile.ExpenseInfo, serviceProvider);
                    destFinancialProfile.TotalIncomes  = CalculateTotal(destFinancialProfile.IncomeInfo, serviceProvider);
                }
            })
            .ForAllOtherMembers(o => o.Condition((source) => true));

            cfg.CreateMap <IndividualParty, IndividualPartyAllDataView>()
            .AfterMap((src, dest) =>
            {
                dest.AsIndividual = Mapper.Map <AsIndividualPartyView>(src);
            })
            .ForAllOtherMembers(o => o.Condition((source) => true));

            cfg.CreateMap <FinancialProfile, FinancialData>()
            .ForMember(dest => dest.TotalExpenses, opt => opt.MapAtRuntime())
            .ForMember(dest => dest.TotalIncomes, opt => opt.MapAtRuntime())
            .ForAllOtherMembers(o => o.Condition((source) => true));

            cfg.CreateMap <IndividualParty, AsIndividualPartyView>()
            .ForMember(dest => dest.Age, opt => opt.Ignore())
            .ForMember(dest => dest.AgeInMonths, opt => opt.Ignore())
            .ForMember(dest => dest.FinancialProfile, opt => opt.MapAtRuntime())
            .ForAllOtherMembers(o => o.Condition((source) => true));

            cfg.CreateMap <EmploymentData, EmploymentDataAllDataView>();

            cfg.CreateMap <OrganizationParty, OrganizationPartyAllDataView>()
            .AfterMap((src, dest) =>
            {
                dest.AsOrganization = Mapper.Map <AsOrganizationPartyView>(src);
            });

            cfg.CreateMap <OrganizationParty, AsOrganizationPartyView>();
            #endregion

            #region Application
            cfg.CreateMap <OfferApplication, ApplicationAllDataView>()
            .ForMember(dest => dest.OrganizationUnit, opt => opt.MapFrom(obj => obj.OrganizationUnitCode))
            .ForMember(dest => dest.Channel, opt => opt.MapFrom(obj => obj.ChannelCode))
            .ForMember(dest => dest.InvolvedPartyCount, opt => opt.Ignore())
            .ForAllOtherMembers(o => o.Condition((source) => true));
            #endregion

            #region ArrangementRequest
            cfg.CreateMap <ArrangementRequest, ArrangementRequestAllDataView>()
            .Include <CardAccessArrangementRequest, CardAccessArrangementRequestAllDataView>()
            .Include <CreditFacilityRequest, CreditFacilityRequestAllDataView>()
            .Include <CreditCardFacilityRequest, CreditCardFacilityRequestAllDataView>()
            .Include <CurrentAccountRequest, CurrentAccountRequestAllDataView>()
            .Include <DemandDepositRequest, DemandDepositRequestAllDataView>()
            .Include <ElectronicAccessArrangementRequest, ElectronicAccessArrangementRequestAllDataView>()
            .Include <OverdraftFacilityRequest, OverdraftFacilityRequestAllDataView>()
            .Include <TermDepositRequest, TermDepositRequestAllDataView>()
            .Include <TermLoanRequest, TermLoanRequestAllDataRequest>()
            .Include <SecuritiesArrangementRequest, SecuritiesArrangementRequestAllDataView>()
            .Include <OtherProductArrangementRequest, OtherProductArrangementRequestAllDataView>()
            .Include <AbstractArrangementRequest, AbstractArrangementRequestAllDataView>()
            .Include <CreditLineRequest, CreditLineRequestAllDataView>()
            .ForMember(dest => dest.ProductFamily, opt => opt.MapFrom(obj => obj.ProductSnapshot.FamilyName))
            .AfterMap((src, dest) =>
            {
                if (!src.ArrangementKind.HasValue || !(new List <ArrangementKind> {
                    ArrangementKind.CreditCardFacility, ArrangementKind.OverdraftFacility, ArrangementKind.TermLoan
                }).Contains(src.ArrangementKind.Value))
                {
                    return;
                }
                dest.Calculation = new CalculationAllDataView
                {
                    CalculationDate       = src.CalculationDate,
                    InstallmentPlan       = src.InstallmentPlan,
                    NumberOfInstallments  = src.NumberOfInstallments,
                    OverrideProductLimits = src.OverrideProductLimits,
                    Periods                         = src.Periods,
                    TotalDisbursement               = 0,
                    TotalAnnuity                    = 0,
                    TotalCashCollateral             = 0,
                    TotalDiscountedNetCashFlow      = 0,
                    TotalExpenses                   = 0,
                    TotalExpensesInDomesticCurrency = 0,
                    TotalFeeAmount                  = 0,
                    TotalInterest                   = 0,
                    TotalNetCashFlow                = 0,
                    TotalPrincipal                  = 0,
                    TotalRepaymentAmount            = 0
                };
                foreach (InstallmentPlanApp row in src.InstallmentPlan)
                {
                    dest.Calculation.TotalDisbursement          += row.Disbursement;
                    dest.Calculation.TotalAnnuity               += row.Annuity;
                    dest.Calculation.TotalPrincipal             += row.PrincipalRepayment;
                    dest.Calculation.TotalInterest              += row.InterestRepayment;
                    dest.Calculation.TotalExpenses              += (row.Fee + row.OtherExpenses);
                    dest.Calculation.TotalCashCollateral        += row.CashCollateral;
                    dest.Calculation.TotalNetCashFlow           += row.NetCashFlow;
                    dest.Calculation.TotalDiscountedNetCashFlow += row.DiscountedNetCashFlow;
                    dest.Calculation.TotalRepaymentAmount       += (row.Fee + row.InterestRepayment + row.PrincipalRepayment + row.OtherExpenses);
                }

                if (dest.Conditions?.MainInterestRate != null && dest.Conditions.MainInterestRate.IsFixed)
                {
                    dest.Calculation.InterestRateVariability = "fixed";
                }
                else
                {
                    dest.Calculation.InterestRateVariability = "variable";
                }

                if (dest.Conditions?.MainInterestRate != null && dest.Conditions.MainInterestRate.IsCompound)
                {
                    dest.Calculation.CalculationMethod = "compound";
                }
                else
                {
                    dest.Calculation.CalculationMethod = "simple";
                }
            });

            cfg.CreateMap <CardAccessArrangementRequest, CardAccessArrangementRequestAllDataView>();
            cfg.CreateMap <CreditFacilityRequest, CreditFacilityRequestAllDataView>();
            cfg.CreateMap <CreditCardFacilityRequest, CreditCardFacilityRequestAllDataView>();
            cfg.CreateMap <CurrentAccountRequest, CurrentAccountRequestAllDataView>();
            cfg.CreateMap <DemandDepositRequest, DemandDepositRequestAllDataView>();
            cfg.CreateMap <ElectronicAccessArrangementRequest, ElectronicAccessArrangementRequestAllDataView>();
            cfg.CreateMap <OverdraftFacilityRequest, OverdraftFacilityRequestAllDataView>();
            cfg.CreateMap <TermDepositRequest, TermDepositRequestAllDataView>();
            cfg.CreateMap <TermLoanRequest, TermLoanRequestAllDataRequest>()
            .ForMember(dest => dest.FinanceServiceDetails, opt => opt.MapFrom(obj => new FinanceServiceDetails
            {
                Amount                   = obj.Amount,
                Napr                     = obj.Napr,
                Eapr                     = obj.Eapr,
                Term                     = obj.Term,
                Annuity                  = obj.Annuity,
                DownpaymentAmount        = obj.DownpaymentAmount,
                DownpaymentPercentage    = obj.DownpaymentPercentage,
                InvoiceAmount            = obj.InvoiceAmount,
                AmountInDomesticCurrency = obj.AmountInDomesticCurrency
            }))
            .ForMember(dest => dest.CurrentValues, opt => opt.MapFrom(obj => new CurrentValues
            {
                Amount                = obj.Amount,
                Annuity               = obj.Annuity,
                DownpaymentAmount     = obj.DownpaymentAmount,
                DownpaymentPercentage = obj.DownpaymentPercentage,
                InvoiceAmount         = obj.InvoiceAmount,
                Napr = obj.Napr,
                Eapr = obj.Eapr,
                Term = obj.Term,
                AmountInDomesticCurrency = obj.AmountInDomesticCurrency
            }));
            cfg.CreateMap <SecuritiesArrangementRequest, SecuritiesArrangementRequestAllDataView>();
            cfg.CreateMap <OtherProductArrangementRequest, OtherProductArrangementRequestAllDataView>();
            cfg.CreateMap <AbstractArrangementRequest, AbstractArrangementRequestAllDataView>();
            cfg.CreateMap <CreditLineRequest, CreditLineRequestAllDataView>();
            cfg.CreateMap <FinanceServiceArrangementRequest, FinanceServiceRequestAllDataView>();

            cfg.CreateMap <Conditions, ConditionsAllDataView>();
            cfg.CreateMap <PricingCondition, PricingConditionAllDataView>()
            .Include <FeeCondition, FeeConditionAllDataView>()
            .Include <InterestRateCondition, InterestRateConditionAllDataView>();
            cfg.CreateMap <FeeCondition, FeeConditionAllDataView>();
            cfg.CreateMap <InterestRateCondition, InterestRateConditionAllDataView>()
            .AfterMap((src, dest) =>
            {
                dest.IsMain = string.IsNullOrEmpty(src.Periods);
            });

            cfg.CreateMap <PricingCondition, PricingConditionAllDataView>();
            #endregion
        }
Пример #4
0
 private async Task <bool> CalculateExposuresForApplication(OfferApplication application, ExposureList exposureList)
 {
     try
     {
         if (application.ArrangementRequests == null)
         {
             application = await _applicationRepository.GetAsync(application.ApplicationId, "arrangement-requests");
         }
         var checkBalanceList       = _configurationService.GetEffective("offer/exposure/balance-arrangement-kinds", "term-loan").Result;
         var creditArrangementTypes = EnumUtils.GetEnumPropertiesForListString <ArrangementKind>("term-loan,overdraft-facility,credit-facility,credit-card-facility");
         var arrangements           = application.ArrangementRequests
                                      .Where(x => (x.Enabled ?? false) &&
                                             creditArrangementTypes.Contains(x.ArrangementKind.GetValueOrDefault()))
                                      .ToList();
         foreach (var arr in arrangements)
         {
             // due to abovementioned and selected arrangement kinds we can do this
             var financial  = (FinanceServiceArrangementRequest)arr;
             var termMonths = 0;
             if (!string.IsNullOrEmpty(financial.Term) && financial.Term.StartsWith("P"))
             {
                 termMonths = Utility.GetMonthsFromPeriod(financial.Term);
             }
             else if (!string.IsNullOrEmpty(financial.Term))
             {
                 termMonths = Convert.ToInt32(financial.Term);
             }
             string   riskCategory = ResolveRiskCategory(arr.ArrangementKind);
             Exposure exp          = new Exposure
             {
                 PartyId         = application.CustomerNumber,
                 CustomerName    = application.CustomerName,
                 ArrangementKind = arr.ArrangementKind,
                 Term            = financial.Term != null ? "P" + termMonths / 12 + "Y" + termMonths % 12 + "M" : "P0M",
                 isBalance       = checkBalanceList.Contains(StringExtensions.ToKebabCase(arr.ArrangementKind.ToString())) ? true : false,
                 AccountNumber   = arr.ApplicationNumber + "/" + arr.ArrangementRequestId,
                 Currency        = financial.Currency,
                 ExposureApprovedInSourceCurrency          = financial.Amount,
                 AnnuityInSourceCurrency                   = financial.TotalAnnuity,
                 ExposureOutstandingAmountInSourceCurrency = financial.Amount,
                 RiskCategory = riskCategory
             };
             if (arr.ArrangementKind == ArrangementKind.TermLoan)
             {
                 var termLoan = (TermLoanRequest)arr;
                 exp.AnnuityInSourceCurrency = termLoan.Annuity;
             }
             exposureList.Exposures.Add(exp);
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e, "CalculateExposuresForApplication exception");
         throw e;
     }
     return(true);
 }