/// <summary>
        /// Frees the goods for quantity row price.
        /// </summary>
        /// <param name="quantity">The quantity.</param>
        /// <param name="priceWithoutDiscount">The price without discount.</param>
        /// <returns></returns>
        public int FreeGoodsForQuantityRowPrice(int quantity, double priceWithoutDiscount)
        {
            int             freeGoods = 0;
            UPSEPricingBase scale     = this.HasQuantityBoundaries ? this.ScaleForQuantity(quantity) : this.ScaleForRowPrice(priceWithoutDiscount);

            if (scale != null)
            {
                freeGoods = scale.FreeGoods;
            }

            return(freeGoods > 0 ? freeGoods : this.FreeGoods);
        }
        /// <summary>
        /// Units the price for quantity row price.
        /// </summary>
        /// <param name="quantity">The quantity.</param>
        /// <param name="priceWithoutDiscount">The price without discount.</param>
        /// <returns></returns>
        public double UnitPriceForQuantityRowPrice(int quantity, double priceWithoutDiscount)
        {
            double          unitPrice = 0;
            UPSEPricingBase scale     = this.HasQuantityBoundaries ? this.ScaleForQuantity(quantity) : this.ScaleForRowPrice(priceWithoutDiscount);

            if (scale != null)
            {
                unitPrice = scale.UnitPrice;
            }

            return(unitPrice != 0 ? unitPrice : this.UnitPrice);
        }
 /// <summary>
 /// Adds the scale.
 /// </summary>
 /// <param name="scale">The scale.</param>
 public void AddScale(UPSEPricingBase scale)
 {
     if (this.scales == null)
     {
         this.scales = new List <UPSEPricingBase> {
             scale
         };
     }
     else
     {
         this.scales.Add(scale);
     }
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UPSEPricingBase"/> class.
        /// </summary>
        /// <param name="pricingBase">The pricing base.</param>
        /// <param name="minusPrice">The minus price.</param>
        public UPSEPricingBase(UPSEPricingBase pricingBase, double minusPrice)
        {
            if (!pricingBase.HasPriceBoundaries)
            {
                throw new InvalidOperationException("HasPriceBoundaries is false");
            }

            if (pricingBase.MaxEndPrice > 0 && minusPrice >= pricingBase.MaxEndPrice)
            {
                throw new InvalidOperationException("Check failed");
            }

            if (pricingBase.MaxEndPrice > 0)
            {
                this.MaxEndPrice = pricingBase.MaxEndPrice - minusPrice;
            }
            else
            {
                this.MaxEndPrice = pricingBase.MaxEndPrice;
            }

            if (pricingBase.MinEndPrice > minusPrice)
            {
                this.MinEndPrice = pricingBase.MinEndPrice - minusPrice;
            }
            else
            {
                this.MinEndPrice = 0;
            }

            this.HasDiscount           = pricingBase.HasDiscount;
            this.Discount              = pricingBase.Discount;
            this.HasFreeGoods          = pricingBase.HasFreeGoods;
            this.FreeGoods             = pricingBase.FreeGoods;
            this.HasQuantityBoundaries = false;
            this.HasPriceBoundaries    = true;
            this.HasUnitPrice          = pricingBase.HasUnitPrice;
            this.UnitPrice             = pricingBase.UnitPrice;
            this.RecordIdentification  = pricingBase.RecordIdentification;
            this.DataDictionary        = pricingBase.DataDictionary;
            this.Pricing   = pricingBase.Pricing;
            this.Currency  = pricingBase.Currency;
            this.BaseScale = pricingBase;
        }
        /// <summary>
        /// Discounts the information for quantity row price.
        /// </summary>
        /// <param name="quantity">The quantity.</param>
        /// <param name="priceWithoutDiscount">The price without discount.</param>
        /// <returns></returns>
        public UPSEPricingDiscountInfo DiscountInfoForQuantityRowPrice(int quantity, double priceWithoutDiscount)
        {
            UPSEPricingBase scale = this.HasQuantityBoundaries ? this.ScaleForQuantity(quantity) : this.ScaleForRowPrice(priceWithoutDiscount);

            double discount = 0;

            if (scale != null)
            {
                discount = scale.Discount;
            }

            if (discount == 0)
            {
                discount = this.Discount;
            }

            if (scale != null)
            {
                if (scale.HasQuantityBoundaries)
                {
                    return(new UPSEPricingDiscountInfo(discount, scale.MinQuantity, this.MaxQuantity));
                }

                if (priceWithoutDiscount > 0 && quantity != 0)
                {
                    double unitPrice   = priceWithoutDiscount / quantity;
                    int    minQuantity = (int)Math.Ceiling(scale.MinEndPrice / unitPrice);
                    int    maxQuantity = (int)Math.Floor(scale.MaxEndPrice / unitPrice);
                    return(new UPSEPricingDiscountInfo(discount, minQuantity, maxQuantity));
                }

                if (priceWithoutDiscount == 0)
                {
                    return(new UPSEPricingDiscountInfo(discount, true));
                }
            }
            else if (this.HasQuantityBoundaries)
            {
                int minQuantityForDiscount = this.MinQuantityForScale();
                if (minQuantityForDiscount > 0 && quantity < minQuantityForDiscount)
                {
                    return(new UPSEPricingDiscountInfo(discount, 0, minQuantityForDiscount - 1));
                }

                int maxQuantityForDiscount = this.MaxQuantityForScale();
                if (quantity > maxQuantityForDiscount)
                {
                    return(new UPSEPricingDiscountInfo(discount, maxQuantityForDiscount + 1, -1));
                }
            }
            else if (priceWithoutDiscount == 0)
            {
                return(new UPSEPricingDiscountInfo(discount, true));
            }
            else if (quantity != 0)
            {
                double minEndPrice = this.MinRowPriceForScale();
                if (priceWithoutDiscount < minEndPrice)
                {
                    double unitPrice   = priceWithoutDiscount / quantity;
                    int    minQuantity = (int)Math.Ceiling(minEndPrice / unitPrice);
                    return(new UPSEPricingDiscountInfo(discount, 0, minQuantity - 1));
                }

                double maxEndPrice = this.MaxRowPriceForScale();
                if (priceWithoutDiscount > maxEndPrice)
                {
                    double unitPrice   = priceWithoutDiscount / quantity;
                    int    maxQuantity = (int)Math.Floor(maxEndPrice / unitPrice);
                    return(new UPSEPricingDiscountInfo(discount, maxQuantity + 1, -1));
                }
            }

            return(new UPSEPricingDiscountInfo(discount, false));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPSEBundlePricingScale"/> class.
 /// </summary>
 /// <param name="pricingBase">The pricing base.</param>
 /// <param name="minusPrice">The minus price.</param>
 public UPSEBundlePricingScale(UPSEPricingBase pricingBase, double minusPrice)
     : base(pricingBase, minusPrice)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPSEBundlePricingScale"/> class.
 /// </summary>
 /// <param name="pricingBase">The pricing base.</param>
 /// <param name="minusQuantity">The minus quantity.</param>
 public UPSEBundlePricingScale(UPSEPricingBase pricingBase, int minusQuantity)
     : base(pricingBase, minusQuantity)
 {
 }