예제 #1
0
            /// <summary>
            /// Calculates all of the discounts for the transactions.
            /// </summary>
            /// <param name="pricingDataManager">Provides data access to the calculation.</param>
            /// <param name="transaction">The sales transaction.</param>
            /// <param name="priceContext">The price context.</param>
            internal void CalculateDiscount(
                IPricingDataAccessor pricingDataManager,
                SalesTransaction transaction,
                PriceContext priceContext)
            {
                if (transaction == null)
                {
                    throw new ArgumentNullException("transaction");
                }

                bool priceLock = false;

                PricingEngine.PopulateProductIds(pricingDataManager, priceContext, transaction);

                // if prices aren't locked on transaction, compute automatic discounts
                if (!priceLock)
                {
                    // Clear all the periodic discounts
                    ClearDiscountLinesOfType(transaction, null);

                    // Now calculate the discounts.
                    DiscountCalculator calculator = new DiscountCalculator(transaction, priceContext, pricingDataManager);
                    calculator.CalculateDiscounts(transaction);

                    // Calculation of customer discount
                    // should pass in "sales rounding" rule
                    if (!string.IsNullOrEmpty(transaction.CustomerId))
                    {
                        // Calculation of customer discount
                        this.CalcCustomerDiscount(pricingDataManager, transaction, priceContext); // should pass in "sales rounding" rule
                    }
                }

                // this is manual total discount, it should always be calculated
                // technically, this should be a different rounding rule for sales rounding
                this.CalculateLineManualDiscount(transaction, priceContext);

                this.CalculateTotalManualDiscount(transaction, priceContext);

                Discount.CalculateLoyaltyManualDiscount(transaction, priceContext);
            }