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