Exemplo n.º 1
0
            /// <summary>
            /// Calculate the customer discount.
            /// </summary>
            /// <param name="pricingDataManager">Provides data access to the calculation.</param>
            /// <param name="salesTransaction">The sales transaction.</param>
            /// <param name="priceContext">Context for the pricing calculation.</param>
            public void CalcCustomerDiscount(
                IPricingDataAccessor pricingDataManager,
                SalesTransaction salesTransaction,
                PriceContext priceContext)
            {
                // Fetch all discount trade agreements if the data manager supports it
                List <TradeAgreement>        lineTradeAgreements      = null;
                List <TradeAgreement>        multiLineTradeAgreements = null;
                List <TradeAgreement>        totalTradeAgreements     = null;
                HashSet <string>             items           = new HashSet <string>(salesTransaction.PriceCalculableSalesLines.Select(sl => sl.ItemId).Distinct(), StringComparer.OrdinalIgnoreCase);
                IEnumerable <TradeAgreement> tradeAgreements = pricingDataManager.ReadDiscountTradeAgreements(items, priceContext.CustomerAccount, priceContext.ActiveDate, priceContext.ActiveDate, priceContext.CurrencyCode, QueryResultSettings.AllRecords) as IEnumerable <TradeAgreement>;

                lineTradeAgreements      = new List <TradeAgreement>();
                multiLineTradeAgreements = new List <TradeAgreement>();
                totalTradeAgreements     = new List <TradeAgreement>();
                foreach (var agreement in tradeAgreements)
                {
                    if (agreement.Relation == PriceDiscountType.LineDiscountSales)
                    {
                        lineTradeAgreements.Add(agreement);
                    }
                    else if (agreement.Relation == PriceDiscountType.MultilineDiscountSales)
                    {
                        multiLineTradeAgreements.Add(agreement);
                    }
                    else if (agreement.Relation == PriceDiscountType.EndDiscountSales)
                    {
                        totalTradeAgreements.Add(agreement);
                    }
                }

                // Calculate line discount
                var lineDiscountCalculator = new LineDiscountCalculator(this.DiscountParameters, priceContext);

                salesTransaction = lineDiscountCalculator.CalcLineDiscount(lineTradeAgreements, salesTransaction);

                // Calculate multiline discount
                var multilineDiscountCalculator = new MultilineDiscountCalculator(this.DiscountParameters, priceContext);

                salesTransaction = multilineDiscountCalculator.CalcMultiLineDiscount(multiLineTradeAgreements, salesTransaction);

                // Calculate total discount
                var totalDiscountCalculator = new TotalDiscountCalculator(this.DiscountParameters, priceContext);

                salesTransaction = totalDiscountCalculator.CalcTotalCustomerDiscount(totalTradeAgreements, salesTransaction);
            }
Exemplo n.º 2
0
            private void CalculateTotalManualDiscount(SalesTransaction transaction, PriceContext priceContext)
            {
                TotalDiscountCalculator totalDiscountCalculator = new TotalDiscountCalculator(this.DiscountParameters, priceContext);

                totalDiscountCalculator.CalculateTotalManualDiscount(transaction);
            }