Ejemplo n.º 1
0
            private static ReadOnlyCollection <PeriodicDiscount> GetRetailDiscounts(
                IEnumerable <SalesLine> salesLines,
                PriceContext priceContext,
                IPricingDataAccessor pricingDataManager,
                QueryResultSettings settings)
            {
                // don't do lookup if there aren't any price groups to search by
                HashSet <string> allPriceGroups = PriceContextHelper.GetAllPriceGroupsForDiscount(priceContext);

                if (allPriceGroups.Count == 0)
                {
                    return(new ReadOnlyCollection <PeriodicDiscount>(new PeriodicDiscount[0]));
                }

                var items = salesLines.Select(l => new ItemUnit
                {
                    ItemId = l.ItemId,
                    VariantInventoryDimensionId = l.InventoryDimensionId ?? string.Empty,
                    UnitOfMeasure = Discount.GetUnitOfMeasure(l),
                });

                ReadOnlyCollection <PeriodicDiscount> discounts =
                    pricingDataManager.ReadRetailDiscounts(items, allPriceGroups, priceContext.ActiveDate, priceContext.ActiveDate, priceContext.CurrencyCode, settings) as ReadOnlyCollection <PeriodicDiscount>;

                ReadOnlyCollection <PeriodicDiscount> validDiscounts =
                    discounts.Where(d => InternalValidationPeriod.ValidateDateAgainstValidationPeriod((DateValidationType)d.DateValidationType, d.ValidationPeriod, d.ValidFromDate, d.ValidToDate, priceContext.ActiveDate)).AsReadOnly();

                return(validDiscounts);
            }
Ejemplo n.º 2
0
            private static bool IsAdjustmentActiveOnSalesLine(
                SalesLine line,
                PriceAdjustment adjustment,
                DateTimeOffset defaultDate)
            {
                var activeDate = line.SalesDate ?? defaultDate;

                return(InternalValidationPeriod.ValidateDateAgainstValidationPeriod(
                           (DateValidationType)adjustment.DateValidationType,
                           adjustment.ValidationPeriod,
                           adjustment.ValidFromDate,
                           adjustment.ValidToDate,
                           activeDate));
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Gets list of discount lines corresponding to products.
            /// </summary>
            /// <param name="items">The collection of products.</param>
            /// <param name="priceContext">The pricing context.</param>
            /// <param name="pricingDataManager">The Pricing data manager.</param>
            /// <param name="settings">Query Settings.</param>
            /// <returns>List of discounts.</returns>
            /// <remarks>The method returns flattened list of discounts which roughly speaking means: it returns 1 line per each possible discount for every product.</remarks>
            private static ReadOnlyCollection <PeriodicDiscount> GetRetailDiscountsAndLines(
                IEnumerable <ItemUnit> items,
                PriceContext priceContext,
                IPricingDataAccessor pricingDataManager,
                QueryResultSettings settings)
            {
                // don't do lookup if there aren't any price groups to search by
                HashSet <string> allPriceGroups = PriceContextHelper.GetAllPriceGroupsForDiscount(priceContext);

                if (allPriceGroups.Count == 0)
                {
                    return(new ReadOnlyCollection <PeriodicDiscount>(new PeriodicDiscount[0]));
                }

                ReadOnlyCollection <PeriodicDiscount> discounts =
                    pricingDataManager.ReadRetailDiscounts(items, allPriceGroups, priceContext.ActiveDate, priceContext.ActiveDate, priceContext.CurrencyCode, settings) as ReadOnlyCollection <PeriodicDiscount>;

                ReadOnlyCollection <PeriodicDiscount> validDiscounts = discounts.Where(p => InternalValidationPeriod.ValidateDateAgainstValidationPeriod((DateValidationType)p.DateValidationType, p.ValidationPeriod, p.ValidFromDate, p.ValidToDate, priceContext.ActiveDate)).AsReadOnly();

                return(validDiscounts);
            }