public async Task <RootAgencyAccommodationBookingSettings> GetAccommodationBookingSettings(int agentAgencyId)
        {
            return(new()
            {
                CancellationPolicyProcessSettings = new CancellationPolicyProcessSettings
                {
                    PolicyStartDateShift = await GetPolicyDateShift()
                }
            });


            async Task <TimeSpan> GetPolicyDateShift()
            {
                var contractKind = await _context.Agencies
                                   .Where(c => c.Id == agentAgencyId)
                                   .Join(_context.Agencies,
                                         a => a.Ancestors.Any()
                            ? a.Ancestors[0]
                            : a.Id,
                                         ra => ra.Id,
                                         (agency, rootAgency) => rootAgency)
                                   .Select(c => c.ContractKind)
                                   .SingleOrDefaultAsync();

                return(contractKind switch
                {
                    ContractKind.CashPayments => TimeSpan.FromDays(-3),
                    ContractKind.CreditPayments => TimeSpan.FromDays(-1),
                    ContractKind.CreditCardPayments => TimeSpan.FromDays(-1),
                    null => DefaultPolicyDateShift,
                    _ => throw new ArgumentOutOfRangeException(nameof(contractKind), contractKind, "Unknown contract kind")
                });
 public AccommodationBookingSettings(List <Suppliers> enabledConnectors,
                                     AprMode aprMode,
                                     PassedDeadlineOffersMode passedDeadlineOffersMode,
                                     bool isSupplierVisible,
                                     CancellationPolicyProcessSettings cancellationPolicyProcessSettings,
                                     bool isDirectContractFlagVisible,
                                     SearchFilters additionalSearchFilters)
 {
     CancellationPolicyProcessSettings = cancellationPolicyProcessSettings;
     IsDirectContractFlagVisible       = isDirectContractFlagVisible;
     EnabledConnectors        = enabledConnectors;
     AprMode                  = aprMode;
     PassedDeadlineOffersMode = passedDeadlineOffersMode;
     IsSupplierVisible        = isSupplierVisible;
     AdditionalSearchFilters  = additionalSearchFilters;
 }
        public static RoomContractSet Process(RoomContractSet roomContractSet, DateTime checkInDate,
                                              CancellationPolicyProcessSettings cancellationPolicyProcessSettings)
        {
            var roomContractSetDeadline = DeadlinePolicyProcessor.Process(roomContractSet.Deadline, checkInDate, cancellationPolicyProcessSettings);
            var shiftedRoomContracts    = new List <RoomContract>();

            foreach (var roomContract in roomContractSet.Rooms)
            {
                var roomContractDeadline = DeadlinePolicyProcessor.Process(roomContract.Deadline, checkInDate, cancellationPolicyProcessSettings);
                shiftedRoomContracts.Add(SetDeadline(roomContract, roomContractDeadline));
            }

            return(new RoomContractSet(id: roomContractSet.Id,
                                       isDirectContract: roomContractSet.IsDirectContract,
                                       isAdvancePurchaseRate: roomContractSet.IsAdvancePurchaseRate,
                                       isPackageRate: roomContractSet.IsPackageRate,
                                       rate: roomContractSet.Rate,
                                       deadline: roomContractSetDeadline,
                                       rooms: shiftedRoomContracts,
                                       supplier: roomContractSet.Supplier,
                                       tags: roomContractSet.Tags));
Beispiel #4
0
        public static Deadline Process(Deadline deadline, DateTime checkInDate, CancellationPolicyProcessSettings cancellationPolicyProcessSettings)
        {
            var shiftValue = cancellationPolicyProcessSettings.PolicyStartDateShift;

            // This value cannot be positive because we cannot shift deadlines to future, only to the past
            shiftValue = shiftValue > TimeSpan.Zero
                ? TimeSpan.Zero
                : shiftValue;

            if (deadline.Date == default(DateTimeOffset))
            {
                throw new ArgumentException($"Deadline date '{deadline.Date}' is invalid", nameof(deadline.Date));
            }

            if (checkInDate == default(DateTime))
            {
                throw new ArgumentException($"Check in date '{checkInDate}' is invalid", nameof(checkInDate));
            }

            var shiftedDeadlineDate = ShiftDate(deadline.Date, checkInDate, shiftValue);
            List <CancellationPolicy> shiftedPolicies = new List <CancellationPolicy>();

            foreach (var policy in deadline.Policies)
            {
                if (policy.FromDate == default)
                {
                    throw new ArgumentException($"Policy date '{policy.FromDate}' is invalid", nameof(policy.FromDate));
                }

                var shiftedPolicyDate = ShiftDate(policy.FromDate, checkInDate, shiftValue);
                var percentage        = Math.Round(policy.Percentage, 2, MidpointRounding.AwayFromZero);
                shiftedPolicies.Add(new CancellationPolicy(shiftedPolicyDate, percentage));
            }

            var shiftedDeadline = new Deadline(shiftedDeadlineDate, shiftedPolicies, deadline.Remarks, deadline.IsFinal);

            return(shiftedDeadline);
        }
Beispiel #5
0
        private AccommodationBookingSettings MergeSettings(Maybe<AgentAccommodationBookingSettings> agentSettings,
            Maybe<AgencyAccommodationBookingSettings> agencySettings, RootAgencyAccommodationBookingSettings rootAgencySettings)
        {
            var agentSettingsValue = agentSettings.HasValue 
                ? agentSettings.Value
                : null;
            var agencySettingsValue = agencySettings.HasValue 
                ? agencySettings.Value
                : null;

            List<Suppliers> enabledConnectors = agentSettingsValue?.EnabledSuppliers ?? agencySettingsValue?.EnabledSuppliers ?? _supplierOptions.EnabledSuppliers;
            AprMode? aprMode = agentSettingsValue?.AprMode ?? agencySettingsValue?.AprMode ?? DefaultAprMode;
            PassedDeadlineOffersMode? passedDeadlineOffersMode = agentSettingsValue?.PassedDeadlineOffersMode ?? agencySettingsValue?.PassedDeadlineOffersMode ??
                DefaultPassedDeadlineOffersMode;

            bool isSupplierVisible = agentSettingsValue?.IsSupplierVisible == true || agencySettingsValue?.IsSupplierVisible == true;
            bool isDirectContractFlagVisible = agentSettingsValue?.IsDirectContractFlagVisible == true || agencySettingsValue?.IsDirectContractFlagVisible == true;

            SearchFilters additionalSearchFilters = agentSettingsValue?.AdditionalSearchFilters ?? default;

            var cancellationPolicyProcessSettings = rootAgencySettings.CancellationPolicyProcessSettings;

            if (agencySettings.HasValue && agencySettings.Value.CustomDeadlineShift.HasValue)
            {
                cancellationPolicyProcessSettings = new CancellationPolicyProcessSettings
                {
                    PolicyStartDateShift = TimeSpan.FromDays(agencySettings.Value.CustomDeadlineShift.Value)
                };
            }

            return new AccommodationBookingSettings(enabledConnectors: enabledConnectors,
                aprMode: aprMode.Value,
                passedDeadlineOffersMode: passedDeadlineOffersMode.Value,
                isSupplierVisible: isSupplierVisible,
                cancellationPolicyProcessSettings: cancellationPolicyProcessSettings,
                isDirectContractFlagVisible: isDirectContractFlagVisible,
                additionalSearchFilters: additionalSearchFilters);
        }
 public static List <RoomContractSet> Process(List <RoomContractSet> roomContractSet, DateTime checkInDate, CancellationPolicyProcessSettings cancellationPolicyProcessSettings)
 {
     return(roomContractSet
            .Select(r => Process(r, checkInDate, cancellationPolicyProcessSettings))
            .ToList());
 }