public decimal Calculate(CancellationRule cancellationRule)
        {
            decimal penalty = 0;

            List <CancellationRuleCondition>           cancellationRuleConditions = GetActiveCancellationRuleConditions(cancellationRule.Id, DateTime.Now);
            CancellationRuleConditionPenaltyCalculator cancellationRuleConditionPenaltyCalculator = new CancellationRuleConditionPenaltyCalculator(_maxCancellationBeforeArrivalValue, _logger);

            foreach (CancellationRuleCondition cancellationRuleCondition in cancellationRuleConditions)
            {
                if (cancellationRuleCondition.PenaltyCalcMode != CancellationPenaltyCalcMode.NoPenalty)
                {
                    penalty += cancellationRuleConditionPenaltyCalculator.Calculate(cancellationRuleCondition, _avgBooking);
                }
            }

            return(penalty);
        }
Esempio n. 2
0
        public decimal Calculate(CancellationRule cancellationRule)
        {
            decimal penalty = 0;

            if (CheckForNotEnabledSpecialOffers(cancellationRule))
            {
                _logger.Warning($"CheckForNotEnabledSpecialOffers");
                return(penalty);
            }

            if (cancellationRule.DisplayStatus == CancellationRuleDisplayStatus.None)
            {
                _logger.Warning($"CancellationRuleDisplayStatus.None");
                return(penalty);
            }

            List <CancellationRuleCondition> cancellationRuleConditions = GetActiveCancellationRuleConditions(cancellationRule.Id, DateTime.Now);
//            int maxCancellationBeforeArrivalValue = Math.Max(cancellationRuleConditions.Max(condition => condition.CancellationBeforeArrivalUnit == TimeUnit.Day ? condition.CancellationBeforeArrivalValue * 24 : condition.CancellationBeforeArrivalValue ), cancellationRuleConditions.Max(condition => condition.CancellationBeforeArrivalUnit == TimeUnit.Day ? condition.CancellationBeforeArrivalValueMax * 24 : condition.CancellationBeforeArrivalValueMax ) );
//            _logger.Info($"\tMaxCancellationBeforeArrivalValue={maxCancellationBeforeArrivalValue}" );
            CancellationRuleConditionPenaltyCalculator cancellationRuleConditionPenaltyCalculator = new CancellationRuleConditionPenaltyCalculator(_maxCancellationBeforeArrivalValue, _logger);

            foreach (CancellationRuleCondition cancellationRuleCondition in cancellationRuleConditions)
            {
                if (cancellationRuleCondition.PenaltyCalcMode != CancellationPenaltyCalcMode.NoPenalty
                    // && cancellationRuleConditionPenaltyCalculator.IsConditionActualForDate( cancellationRuleCondition, now, referencePointDateTime )
                    )
                {
                    penalty += cancellationRuleConditionPenaltyCalculator.Calculate(cancellationRuleCondition, _avgBooking);
                }
            }

            penalty = penalty / cancellationRuleConditions.Count;

            _logger.Info($"\tCancellationRule penalty={penalty}");
            return(penalty);
        }