コード例 #1
0
        private VariationDefinitionParams GetVariationDefinitionParams(PriceCalculationParameters parameters)
        {
            var defaultParamsString = configurationService.GetEffective("offer/price-calculation/default-parameters").Result;
            var defaultParams       = (VariationDefinitionParams)CaseUtil.ConvertFromJsonToObject(defaultParamsString, typeof(VariationDefinitionParams));
            var defParams           = new VariationDefinitionParams
            {
                Channel  = parameters.Channel ?? defaultParams.Channel,
                Amount   = parameters.Amount,
                Currency = parameters.Currency
            };

            defParams.CustomerSegment     = parameters.CustomerSegment ?? defaultParams.CustomerSegment;
            defParams.RiskScore           = parameters.RiskScore ?? defaultParams.RiskScore;
            defParams.PartOfBundle        = parameters.PartOfBundle ?? defaultParams.PartOfBundle;
            defParams.CollateralModel     = parameters.CollateralModel ?? defaultParams.CollateralModel;
            defParams.HasCampaignInculded = parameters.Campaign != null;
            defParams.DebtToIncome        = parameters.DebtToIncome ?? defaultParams.DebtToIncome;
            defParams.CustomerValue       = parameters.CustomerValue ?? defaultParams.CustomerValue;
            defParams.CreditRating        = parameters.CreditRating ?? defaultParams.CreditRating;
            var bundledComponentns = parameters.AdditionalProperties ?? defaultParams.AdditionalProperties;

            defParams.AdditionalProperties = new Dictionary <string, JToken>();
            var jsonData = JsonConvert.SerializeObject(bundledComponentns);

            if (jsonData.Equals("{}"))
            {
                Console.WriteLine(
                    new System.Diagnostics.StackTrace().ToString()
                    );
            }
            foreach (var item in bundledComponentns)
            {
                defParams.AdditionalProperties.Add("bundledComponent_" + item.Key, item.Value);
            }
            try
            {
                defParams.Term = Utility.GetMonthsFromPeriod(parameters.Term);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                defParams.Term = 0;
            }
            return(defParams);
        }
コード例 #2
0
        public async Task <dynamic> GetGenericParamsForDmn(VariationDefinitionParams definitionParams, string variationConfigurationUrl = "")
        {
            try
            {
                string checkConfig = await configurationService.GetEffective(variationConfigurationUrl);

                dynamic responseForDmn = null;
                if (!string.IsNullOrEmpty(checkConfig))
                {
                    List <KeyValuePair <string, StringValues> > query = _httpContextAccessor.HttpContext.Request.Query.ToList();
                    var     body = _httpContextAccessor.HttpContext.Request.Body;
                    dynamic originalBody;
                    var     newBody = _httpContextAccessor.HttpContext.Request.Body;
                    newBody.Seek(0, System.IO.SeekOrigin.Begin);
                    using (var streamReader = new StreamReader(newBody, Encoding.UTF8, true, 1024, true))
                    {
                        string bodyRead = streamReader.ReadToEnd();
                        originalBody = JObject.Parse(bodyRead);
                    }
                    _httpContextAccessor.HttpContext.Request.Body.Position = 0;
                    Dictionary <string, string> dict = query.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());

                    using (var scope = _serviceProvider.CreateScope())
                    {
                        var _dmnRequestExtender = scope.ServiceProvider.GetRequiredService <DmnRequestExtender>();
                        responseForDmn = await _dmnRequestExtender.DmnRequestExtenderResponse(variationConfigurationUrl, dict, originalBody);
                    }

                    var defParamse = JObject.FromObject(definitionParams);

                    foreach (var rp in defParamse)
                    {
                        responseForDmn.Add(rp.Key.ToString(), rp.Value);
                    }
                }
                return(responseForDmn);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, "Get generic params for dmn variations error");
                return(null);
            }
        }
コード例 #3
0
        public Task <string> GetEffective(string key, string defaultValue = null)
        {
            string res;

            switch (key)
            {
            case "offer/currency-conversion-method":
                res = "Buy to middle";
                break;

            case "offer/price-calculation/default-parameters":
                var defaultParameters = new VariationDefinitionParams
                {
                    CollateralModel = "co-debtor",
                    CustomerSegment = "professional"
                };
                res = JsonConvert.SerializeObject(defaultParameters);
                break;

            case "offer/price-calculation/bundle-variation-group":
                res = "product-bundling-discount";
                break;

            default:
                if (defaultValue != null)
                {
                    res = defaultValue;
                    break;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            return(Task.FromResult(res));
        }
コード例 #4
0
        private async Task <ResolvedFeesResult> CalculateFees(PriceCalculationParameters calculationParameters, VariationDefinitionParams definitionParams)
        {
            // TODO Include all fee parameters (limits and percentage) in DMN and in calculation
            var result = new ResolvedFeesResult
            {
                ResultChanged = false
            };

            if (calculationParameters.Fees != null)
            {
                var arrFees = calculationParameters.Fees;
                result.Fees = new List <FeeCondition>();
                foreach (FeeCondition fee in arrFees)
                {
                    if (fee == null || fee.EffectiveDate > DateTime.Today ||
                        (fee.Currencies != null && !fee.Currencies.Contains(calculationParameters.Currency)))
                    {
                        continue;
                    }
                    var newFee = fee.Copy();
                    newFee = ResolveFeeBenefits(calculationParameters, newFee);
                    newFee = ResolveFeeOptions(calculationParameters, newFee);

                    if (!string.IsNullOrEmpty(newFee.VariationsDefinitionDMN))
                    {
                        var newVars = await priceCalculationService.ResolveFeeVariationDmn(newFee.VariationsDefinitionDMN, definitionParams, newFee.VariationsDefinition);;
                        if (newVars != null && newVars.Count > 0)
                        {
                            if (newFee.Variations != null || newFee.Variations.Count > 0)
                            {
                                newFee.Variations = newFee.Variations.Where(nv => nv.Origin != PriceVariationOrigins.Product).ToList();
                            }
                            else
                            {
                                newFee.Variations = new List <FeeVariation>();
                            }

                            newFee.Variations.AddRange(newVars);
                        }
                    }

                    var calculatedFixedAmount = newFee.CalculatedFixedAmount;
                    var calculatedLowerLimit  = newFee.CalculatedLowerLimit;
                    var calculatedUpperLimit  = newFee.CalculatedUpperLimit;
                    var calculatedPercentage  = newFee.CalculatedPercentage;
                    var calculatedFee         = SolveFeeCondition(newFee);
                    if (calculatedFee.CalculatedPercentage != calculatedPercentage || calculatedFee.CalculatedFixedAmount != calculatedFixedAmount ||
                        calculatedFee.CalculatedLowerLimit != calculatedLowerLimit || calculatedFee.CalculatedUpperLimit != calculatedUpperLimit)
                    {
                        result.ResultChanged = true;
                    }
                    result.Fees.Add(calculatedFee);
                }
            }
            return(result);
        }
コード例 #5
0
        private async Task <ResolvedRatesResult> CalculateInterestRates(PriceCalculationParameters calculationParameters, VariationDefinitionParams definitionParams)
        {
            var bundleVariationGroup = await configurationService
                                       .GetEffective("offer/price-calculation/bundle-variation-group", "PRODUCT-BUNDLING-DISCOUNT");

            bundleVariationGroup = bundleVariationGroup.ToLower();

            var result = new ResolvedRatesResult
            {
                ResultChanged = false
            };

            if (calculationParameters.InterestRates != null)
            {
                result.Rates = new List <InterestRateCondition>();
                var     arrRates = calculationParameters.InterestRates;
                decimal napr     = -1;
                foreach (InterestRateCondition rate in arrRates)
                {
                    var oldCalculatedRate = rate.CalculatedRate;
                    if (
                        // check if rate is defined at all
                        rate == null ||
                        // check if rate is effective on request date
                        rate.EffectiveDate > calculationParameters.RequestDate ||
                        // check if rate is defined for main currency
                        (rate.Currencies != null && !rate.Currencies.Contains(calculationParameters.Currency)) ||
                        // check if rate is defined for scheduled periods (if scheduled periods exist at all)
                        (string.IsNullOrEmpty(rate.Periods) &&
                         calculationParameters.ScheduledPeriods != null && calculationParameters.ScheduledPeriods.Count() > 0)
                        ||
                        (!string.IsNullOrEmpty(rate.Periods) &&
                         (calculationParameters.ScheduledPeriods == null || calculationParameters.ScheduledPeriods.Count() == 0))
                        ||
                        (!string.IsNullOrEmpty(rate.Periods) &&
                         calculationParameters.ScheduledPeriods != null && calculationParameters.ScheduledPeriods.Count() > 0 &&
                         rate.Periods.Replace(" ", "").Split(",").Intersect(calculationParameters.ScheduledPeriods.Select(p => p.PeriodType)).Count() == 0))
                    {
                        continue;
                    }
                    if (calculationParameters.Amount.HasValue)
                    {
                        definitionParams.AmountInRuleCurrency = GetAmountInRuleCurrency(rate, calculationParameters.Currency,
                                                                                        calculationParameters.Amount.Value);
                    }

                    var newRate = rate.Copy();
                    newRate = ResolveRateBenefits(calculationParameters, newRate);
                    newRate = ResolveRateOptions(calculationParameters, newRate);

                    if (!string.IsNullOrEmpty(newRate.VariationsDefinitionDMN))
                    {
                        var newVars = await priceCalculationService.ResolveInterestRateVariationDmn(newRate.VariationsDefinitionDMN, definitionParams, newRate.VariationsDefinition);

                        if (newVars != null && newVars.Count > 0)
                        {
                            if (newRate.Variations != null || newRate.Variations.Count > 0)
                            {
                                newRate.Variations = newRate.Variations.Where(nv => nv.Origin != PriceVariationOrigins.Product).ToList();
                            }
                            else
                            {
                                newRate.Variations = new List <InterestRateVariation>();
                            }
                            newRate.Variations.AddRange(newVars);
                        }
                    }
                    if (!string.IsNullOrEmpty(newRate.UpperLimitVariationsDefinitionDMN))
                    {
                        var newVars = await priceCalculationService.ResolveInterestRateVariationDmn(newRate.UpperLimitVariationsDefinitionDMN, definitionParams, newRate.UpperLimitVariationsDefinition);

                        if (newVars != null && newVars.Count > 0)
                        {
                            if (newRate.UpperLimitVariations != null || newRate.UpperLimitVariations.Count > 0)
                            {
                                newRate.UpperLimitVariations = newRate.UpperLimitVariations.Where(nv => nv.Origin != PriceVariationOrigins.Product).ToList();
                            }
                            else
                            {
                                newRate.UpperLimitVariations = new List <InterestRateVariation>();
                            }
                            newRate.UpperLimitVariations.AddRange(newVars);
                        }
                    }
                    if (!string.IsNullOrEmpty(newRate.LowerLimitVariationsDefinitionDMN))
                    {
                        var newVars = await priceCalculationService.ResolveInterestRateVariationDmn(newRate.LowerLimitVariationsDefinitionDMN, definitionParams, newRate.LowerLimitVariationsDefinition);

                        if (newVars != null && newVars.Count > 0)
                        {
                            if (newRate.LowerLimitVariations != null || newRate.LowerLimitVariations.Count > 0)
                            {
                                newRate.LowerLimitVariations = newRate.LowerLimitVariations.Where(nv => nv.Origin != PriceVariationOrigins.Product).ToList();
                            }
                            else
                            {
                                newRate.LowerLimitVariations = new List <InterestRateVariation>();
                            }
                            newRate.LowerLimitVariations.AddRange(newVars);
                        }
                    }

                    var newPrice = GetPrice(newRate, calculationParameters.RequestDate ?? DateTime.Today);
                    if (newPrice != oldCalculatedRate)
                    {
                        result.ResultChanged = true;
                    }

                    var rateWoBundle = GetInterestRateWithoutBundle(newRate, bundleVariationGroup, calculationParameters.RequestDate);
                    if (rateWoBundle > 0)
                    {
                        newRate.RateWithoutBundle = rateWoBundle;
                    }

                    if (newRate.Variations.Any(v => v.Origin == PriceVariationOrigins.SalesDiscount))
                    {
                        newRate.Variations.Reverse();
                    }

                    result.Rates.Add(newRate);
                    if (newRate.Kind == InterestRateKinds.RegularInterest && napr < 0)
                    {
                        napr        = newRate.CalculatedRate;
                        result.Napr = napr;
                    }
                }
            }
            return(result);
        }
コード例 #6
0
        public Task <List <InterestRateVariation> > ResolveInterestRateVariationDmn(string dmnContent, VariationDefinitionParams definitionParams, string variationDefinition = "")
        {
            var list = new List <InterestRateVariation>();

            switch (dmnContent)
            {
            default:
                break;
            }
            return(Task.FromResult(list));
        }
コード例 #7
0
 public Task <List <FeeVariation> > ResolveFeeVariationDmn(string dmnContent, VariationDefinitionParams definitionParams, string variationDefinition = "")
 {
     throw new NotImplementedException();
 }
コード例 #8
0
        public async Task <List <InterestRateVariation> > ResolveInterestRateVariationDmn(string dmnContent, VariationDefinitionParams definitionParams, string variationDefinition = "")
        {
            var responseForDmn = await GetGenericParamsForDmn(definitionParams, variationDefinition.Replace(".dmn", "-configuration"));

            var decisionRequest = new DecisionRequest
            {
                Data           = responseForDmn ?? definitionParams,
                RuleDefinition = dmnContent
            };
            var resolvedDmn = await ResolveVariationDmn(decisionRequest);

            var variations = resolvedDmn.ToInterestRateVariations();

            if (variations != null)
            {
                foreach (InterestRateVariation interestRateVariation in variations)
                {
                    interestRateVariation.Origin = PriceVariationOrigins.Product;
                }
            }
            return(variations);
        }
コード例 #9
0
        //Za prosledjen fee, napravi feeVariation koji u odnosuna definition ubaci tu kalkulaciju
        public Task <List <FeeVariation> > ResolveFeeVariationDmn(string dmnContent, VariationDefinitionParams definitionParams)
        {
            var list = new List <FeeVariation>();

            switch (dmnContent)
            {
            case ("product/price-variations/fee-in-range-upper.dmn"):
                list.Add(CreateFeeVariation((decimal)0.89, 179));
                break;

            case ("product/price-variations/fee-in-range-lower.dmn"):
                list.Add(CreateFeeVariation((decimal) - 0.08, -179));
                break;

            case ("product/price-variations/fee-under-range.dmn"):
                list.Add(CreateFeeVariation((decimal) - 0.1, -181));
                break;

            case ("product/price-variations/fee-over-range.dmn"):
                list.Add(CreateFeeVariation(1, 181));
                break;

            case ("product/price-variations/multiple-fee-var-in-range-upper.dmn"):
                list.Add(CreateFeeVariation((decimal)0.49, 100));
                list.Add(CreateFeeVariation((decimal)0.40, 79));
                break;

            case ("product/price-variations/multiple-fee-var-in-range-lower.dmn"):
                list.Add(CreateFeeVariation((decimal) - 0.03, -100));
                list.Add(CreateFeeVariation((decimal) - 0.05, -79));
                break;

            case ("product/price-variations/multiple-fee-var-under-range.dmn"):
                list.Add(CreateFeeVariation((decimal) - 0.06, -100));
                list.Add(CreateFeeVariation((decimal) - 0.04, -81));
                break;

            case ("product/price-variations/multiple-fee-var-over-range.dmn"):
                list.Add(CreateFeeVariation((decimal)0.4, 200));
                list.Add(CreateFeeVariation((decimal)0.6, 200));
                break;

            //iterative_cases
            case ("product/price-variations/iterative-fee-in-range-upper.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal)0.88, 178));
                    break;
                }
                list.Add(CreateFeeVariation((decimal)0.89, 179));
                break;

            case ("product/price-variations/iterative-fee-in-range-lower.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal) - 0.07, -178));
                    break;
                }
                list.Add(CreateFeeVariation((decimal) - 0.08, -179));
                break;

            case ("product/price-variations/iterative-fee-under-range.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal) - 0.09, -180));
                    break;
                }
                list.Add(CreateFeeVariation((decimal) - 0.1, -181));
                break;

            case ("product/price-variations/iterative-fee-over-range.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal)1.01, 182));
                    break;
                }
                list.Add(CreateFeeVariation(1, 181));
                break;

            case ("product/price-variations/iterative-multiple-fee-var-in-range-upper.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal)0.48, 100));
                    list.Add(CreateFeeVariation((decimal)0.40, 78));
                    break;
                }
                list.Add(CreateFeeVariation((decimal)0.49, 100));
                list.Add(CreateFeeVariation((decimal)0.40, 79));
                break;

            case ("product/price-variations/iterative-multiple-fee-var-in-range-lower.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal) - 0.03, -100));
                    list.Add(CreateFeeVariation((decimal) - 0.04, -78));
                    break;
                }
                list.Add(CreateFeeVariation((decimal) - 0.03, -100));
                list.Add(CreateFeeVariation((decimal) - 0.05, -79));
                break;

            case ("product/price-variations/iterative-multiple-fee-var-under-range.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal) - 0.07, -101));
                    list.Add(CreateFeeVariation((decimal) - 0.04, -81));
                    break;
                }
                list.Add(CreateFeeVariation((decimal) - 0.06, -100));
                list.Add(CreateFeeVariation((decimal) - 0.04, -81));
                break;

            case ("product/price-variations/iterative-multiple-fee-var-over-range.dmn"):
                if (feeCounter > 0)
                {
                    list.Add(CreateFeeVariation((decimal)0.5, 200));
                    list.Add(CreateFeeVariation((decimal)0.6, 201));
                    break;
                }
                list.Add(CreateFeeVariation((decimal)0.4, 200));
                list.Add(CreateFeeVariation((decimal)0.6, 200));
                break;
            }
            feeCounter = feeCounter + 1;
            return(Task.FromResult(list));
        }
コード例 #10
0
        public Task <List <InterestRateVariation> > ResolveInterestRateVariationDmn(string dmnContent, VariationDefinitionParams definitionParams)
        {
            var list = new List <InterestRateVariation>();
            {
                switch (dmnContent)
                {
                case ("product/price-variations/int-rate-remove.dmn"):
                    list.Add(CreateIntRateVariation(-1));
                    break;

                case ("product/price-variations/int-rate-remove2.dmn"):
                    list.Add(CreateIntRateVariation(-2));
                    break;

                case ("product/price-variations/int-rate-add.dmn"):
                    list.Add(CreateIntRateVariation(1));
                    break;

                case ("product/price-variations/int-rate-add2.dmn"):
                    list.Add(CreateIntRateVariation(2));
                    break;

                case ("product/price-variations/int-rate-add-two-variations.dmn"):
                    list.Add(CreateIntRateVariation(1));
                    list.Add(CreateIntRateVariation(2));
                    break;

                //iterative
                case ("product/price-variations/iterative-int-rate-remove.dmn"):
                    if (intrateCounter > 0)
                    {
                        list.Add(CreateIntRateVariation((decimal) - 0.99));
                        break;
                    }
                    list.Add(CreateIntRateVariation(-1));
                    break;

                case ("product/price-variations/iterative-int-rate-remove2.dmn"):
                    if (intrateCounter > 0)
                    {
                        list.Add(CreateIntRateVariation((decimal) - 1.99));
                        break;
                    }
                    list.Add(CreateIntRateVariation(-2));
                    break;

                case ("product/price-variations/iterative-int-rate-add.dmn"):
                    if (intrateCounter > 0)
                    {
                        list.Add(CreateIntRateVariation((decimal)0.99));
                        break;
                    }
                    list.Add(CreateIntRateVariation(1));
                    break;

                case ("product/price-variations/iterative-int-rate-add2.dmn"):
                    if (intrateCounter > 0)
                    {
                        list.Add(CreateIntRateVariation(2));
                        break;
                    }
                    list.Add(CreateIntRateVariation(2));
                    break;

                case ("product/price-variations/iterative-int-rate-add-two-variations.dmn"):
                    if (intrateCounter > 0)
                    {
                        list.Add(CreateIntRateVariation(1));
                        list.Add(CreateIntRateVariation(2));
                        break;
                    }
                    list.Add(CreateIntRateVariation(1));
                    list.Add(CreateIntRateVariation(2));
                    break;
                }
                intrateCounter = intrateCounter + 1;
                return(Task.FromResult(list));
            }
        }