Пример #1
0
        /// <summary>
        /// Gets the product totals.
        /// </summary>
        /// <typeparam name="TTotals">The type of the totals.</typeparam>
        /// <typeparam name="TProduct">The type of the product.</typeparam>
        /// <typeparam name="TCurrency">The type of the currency.</typeparam>
        /// <param name="product">The product.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns>The product prices list.</returns>
        public virtual TTotals GetProductTotals <TTotals, TProduct, TCurrency>(TProduct product, TCurrency currency, uint quantity)
            where TProduct : ProductBaseData
            where TTotals : DomainModel.Prices.Totals
            where TCurrency : Currency
        {
            Assert.ArgumentNotNull(product, "product");
            Assert.ArgumentNotNull(currency, "currency");

            TTotals productTotals = Context.Entity.Resolve <TTotals>();

            if (quantity < 1)
            {
                return(productTotals);
            }

            IDictionary <string, decimal> priceMatrix = new Dictionary <string, decimal>
            {
                { "NormalPrice", this.GetPriceMatrixPrice(product, "Normalprice") },
                { "MemberPrice", this.GetPriceMatrixPrice(product, "Memberprice") }
            };

            decimal vat = decimal.Zero;

            if (product is Product)
            {
                vat = this.GetVat(product as Product);
            }

            DomainModel.Prices.Totals totals = this.GetProductTotals(priceMatrix, vat, quantity);

            ICurrencyConverter <TTotals, TCurrency> currencyConverter = Context.Entity.Resolve <ICurrencyConverter <TTotals, TCurrency> >();

            return(currencyConverter.Convert(totals as TTotals, currency));
        }
Пример #2
0
        /// <summary>
        /// Gets the product totals.
        /// </summary>
        /// <param name="priceMatrix">The price matrix.</param>
        /// <param name="vat">The vat.</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns>
        /// The product totals.
        /// </returns>
        protected virtual DomainModel.Prices.Totals GetProductTotals(IDictionary <string, decimal> priceMatrix, decimal vat, uint quantity)
        {
            Assert.IsNotNull(this.priceCalculatorFactory, "Price Calculation Factory cannot be null.");

            PriceCalculator calculator = this.priceCalculatorFactory.CreateCalculator();

            DomainModel.Prices.Totals totals = calculator.Calculate(priceMatrix, vat, quantity);

            return(totals);
        }
Пример #3
0
        public override DomainModel.Prices.Totals Calculate([NotNull] IDictionary <string, decimal> priceMatrix, decimal vat, uint quantity)
        {
            Assert.ArgumentNotNull(priceMatrix, "priceMatrix");

            decimal price       = priceMatrix[this.PriceKey];
            decimal normalPrice = priceMatrix["NormalPrice"];
            decimal memberPrice = priceMatrix["MemberPrice"];

            if (price == decimal.Zero)
            {
                price = normalPrice;
            }

            if (memberPrice == decimal.Zero)
            {
                memberPrice = normalPrice;
            }

            DomainModel.Prices.Totals totals = this.TotalsFactory.Create();

            totals.PriceExVat  = price;
            totals.PriceIncVat = price * (1 + vat);
            totals.MemberPrice = memberPrice;
            totals.VAT         = vat;

            if (quantity == 0)
            {
                return(totals);
            }

            totals.TotalPriceExVat  = totals.PriceExVat * quantity;
            totals.TotalPriceIncVat = totals.PriceIncVat * quantity;

            totals.TotalVat = totals.TotalPriceIncVat - totals.TotalPriceExVat;

            totals.DiscountExVat  = (normalPrice - price) * quantity;
            totals.DiscountIncVat = totals.DiscountExVat * (1 + vat);

            totals.PossibleDiscountExVat  = (price - memberPrice) * quantity;
            totals.PossibleDiscountIncVat = totals.PossibleDiscountExVat * (1 + vat);

            return(totals);
        }