private bool CanBuy_eLearningRule(MyHLShoppingCart hlCart)
        {
            bool   retVal       = true;
            var    session      = SessionInfo.GetSessionInfo(hlCart.DistributorID, hlCart.Locale);
            string trainingCode = HLConfigManager.Configurations.ShoppingCartConfiguration.TrainingCode;

            if (session.DsTrainings == null)
            {
                session.DsTrainings = DistributorOrderingProfileProvider.GetTrainingList(hlCart.DistributorID, hlCart.CountryCode);
            }

            if (session.DsTrainings != null && session.DsTrainings.Count > 0 && session.DsTrainings.Exists(t => t.TrainingCode == trainingCode && !t.TrainingFlag))
            {
                var     currentLimits       = PurchasingLimitProvider.GetCurrentPurchasingLimits(hlCart.DistributorID);
                decimal currentVolumePoints = hlCart.VolumeInCart;

                var currentItem = CatalogProvider.GetCatalogItem(hlCart.CurrentItems[0].SKU, Country);
                currentVolumePoints += currentItem.VolumePoints * hlCart.CurrentItems[0].Quantity;
                if (currentLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                {
                    currentVolumePoints += (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                }

                if (currentVolumePoints > HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV)
                {
                    retVal = false;
                }
            }


            return(retVal);
        }
        public void PerformTaxationRules(Order_V01 order, string locale)
        {
            if (null != order)
            {
                var limits = order.PurchasingLimits as PurchasingLimits_V01;
                if (null == limits)
                {
                    limits =
                        PurchasingLimitProvider.GetCurrentPurchasingLimits(order.DistributorID);
                    order.PurchasingLimits = limits;
                }
                if (null == limits)
                {
                    //Log an error here - can't tax this, it is invalid for IT if we don't have Limits created
                }
                else
                {
                    //Add suplemental items for Incaricato VAT and INPS calcs
                    limits.Items = new SupplementalItems();
                    limits.Items.Add("ConsignmentWitholdingRate", new List <decimal>(new[] { 0.1794M }));
                    //Both A1 and B1
                    limits.Items.Add("FlatFreightRate", new List <decimal>(new[] { 0.045M }));
                    if (!string.IsNullOrEmpty(limits.PurchaseSubType) && limits.PurchaseSubType.Equals("A1"))
                    //VAT Registered
                    {
                        DistributorOrderingProfile distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(order.DistributorID, Country);
                        //Calcualte the INPS contribution for A1
                        if (distributorOrderingProfile.YTDEarnings > limits.MaxEarningsLimit &&
                            distributorOrderingProfile.YTDEarnings <=
                            HLConfigManager.Configurations.DOConfiguration.MaxTaxableEarnings)
                        {
                            var taxIds = DistributorOrderingProfileProvider.GetTinList(order.DistributorID, true);
                            if (taxIds.Count > 0 &&
                                taxIds.Where(
                                    p =>
                                    p.IDType.Key.Equals("IEVA") & p.IDType.Key.Equals("ITIN") &
                                    p.IDType.Key.Equals("ITSS")).Count() > 0)
                            {
                                limits.Items.Add("INPSContributionRate", new List <decimal>(new[] { 0.0442M }));
                            }
                            else
                            {
                                limits.Items.Add("INPSContributionRate", new List <decimal>(new[] { 0.0695M }));
                            }
                        }
                        else
                        {
                            limits.Items.Add("INPSContributionRate", new List <decimal>(new[] { 0M }));
                        }
                        limits.Items.Add("VATReimbursementRate", new List <decimal>(new[] { 0.20M }));
                    }
                }

                CheckforMultipleDuplicateLinkedSkus(order);
            }
        }
        private void DisplayRemainingValues(string DSSubType, bool Refresh)
        {
            PurchasingLimits_V01 limits = new PurchasingLimits_V01();

            ShoppingCart.EmailValues.RemainingVolume = string.Empty;

            if (string.IsNullOrEmpty(DSSubType))
            {
                limits = PurchasingLimitProvider.GetCurrentPurchasingLimits(DistributorID);
            }
            else
            {
                limits = PurchasingLimitProvider.GetPurchasingLimits(DistributorID, DSSubType);
            }
            if (FOPEnabled)
            {
                trRemainingVal.Visible = limits.RemainingVolume > -1;
            }
            else
            {
                trRemainingVal.Visible = PurchasingLimitManager(ShoppingCart.DistributorID).PurchasingLimitsRestriction != PurchasingLimitRestrictionType.MarketingPlan;
            }

            if (DSSubType == "RE")
            {
                //trRemainingVal.Visible = false;
                OnOrderSubTypeChanged(this, new OrderSubTypeEventArgs(ddl_DSSubType.SelectedItem.Value, true, false, Refresh));
            }

            lblRemainingValDisplay.Text = this.GetLocalResourceObject("RemainingVolume").ToString();
            if (ShoppingCart != null && limits != null)
            {
                decimal totalDue  = TotalsExcludeAPF(ShoppingCart, this.CountryCode);
                decimal remaining = decimal.Zero;
                if (FOPEnabled)
                {
                    decimal cartVolume = (limits.LimitsRestrictionType == LimitsRestrictionType.PurchasingLimits) ? ShoppingCart.ProductPromoVolumeInCart : ShoppingCart.VolumeInCart;
                    remaining = (limits.LimitsRestrictionType == LimitsRestrictionType.PurchasingLimits) ? limits.RemainingVolume - totalDue : limits.RemainingVolume - cartVolume;
                }
                else
                {
                    remaining = limits.RemainingVolume - totalDue;
                }
                if (remaining < 0)
                {
                    remaining = 0;
                }
                this.lblRemainingVal.Text    = limits.PurchaseLimitType == PurchaseLimitType.Volume ? remaining.ToString("N2") : this.getAmountString(remaining);
                this.lblRemainingVal.Visible = limits.PurchaseLimitType != PurchaseLimitType.None;
            }
            if (trRemainingVal.Visible)
            {
                ShoppingCart.EmailValues.RemainingVolume = lblRemainingVal.Text;
            }
            OnOrderSubTypeChanged(this, new OrderSubTypeEventArgs(ddl_DSSubType.SelectedItem.Value, false, true, Refresh));
        }
        private void checkLimits(MyHLShoppingCart hlCart)
        {
            var currentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(hlCart.DistributorID);

            var    session      = SessionInfo.GetSessionInfo(hlCart.DistributorID, hlCart.Locale);
            string trainingCode = HLConfigManager.Configurations.ShoppingCartConfiguration.TrainingCode;

            if (session.DsTrainings == null || session.DsTrainings.Count == 0)
            {
                session.DsTrainings = DistributorOrderingProfileProvider.GetTrainingList(hlCart.DistributorID, hlCart.CountryCode);
            }
            if (session.DsTrainings != null && session.DsTrainings.Count > 0 &&
                session.DsTrainings.Exists(t => t.TrainingCode == trainingCode && !t.TrainingFlag))
            {
                //if is true the member place an order without taking the training and the limits shoud be applicable for only 1100
                if (currentLimits.RemainingVolume != currentLimits.maxVolumeLimit && !session.LimitsHasModified)
                {
                    var used     = (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                    var shouldbe = 1100 - used;
                    PurchaseLimitType limitType = PurchaseLimitType.Volume;
                    currentLimits.PurchaseLimitType = limitType;
                    if (currentLimits.RemainingVolume != shouldbe && shouldbe > 0 && !session.LimitsHasModified)
                    {
                        currentLimits.RemainingVolume = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume);
                        session.LimitsHasModified     = true;
                    }
                    string country = DistributorProfileModel.ProcessingCountryCode;
                    PurchasingLimitProvider.savePurchasingLimitsToCache(ConvertCurrentLimitsToSave(currentLimits), hlCart.DistributorID);
                    PurchasingLimitProvider.SavePurchaseLimitsToStore(country, hlCart.DistributorID);
                }
                //check for the members without limits and create
                else if (currentLimits.RemainingVolume == -1 && currentLimits.maxVolumeLimit == -1 && !session.LimitsHasModified)
                {
                    var currentLoggedInCounrtyCode      = Locale.Substring(3);
                    DistributorLoader distributorLoader = new DistributorLoader();
                    var distributorProfile = distributorLoader.Load(hlCart.DistributorID, currentLoggedInCounrtyCode);

                    var remainingVolume         = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - distributorProfile.PersonallyPurchasedVolume;
                    PurchaseLimitType limitType = PurchaseLimitType.Volume;
                    //PurchasingLimits_V01 newLimits = new PurchasingLimits_V01();
                    currentLimits.Month                 = currentLimits.Month;
                    currentLimits.LastRead              = DateTime.UtcNow;
                    currentLimits.RemainingVolume       = distributorProfile.PersonallyPurchasedVolume != 0 ? remainingVolume : 0;
                    currentLimits.LimitsRestrictionType = LimitsRestrictionType.PurchasingLimits;
                    currentLimits.PurchaseLimitType     = limitType;
                    currentLimits.LastRead              = DateTime.UtcNow;
                    currentLimits.maxVolumeLimit        = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV;
                    session.LimitsHasModified           = true;
                    string country = DistributorProfileModel.ProcessingCountryCode;
                    PurchasingLimitProvider.savePurchasingLimitsToCache(ConvertCurrentLimitsToSave(currentLimits), hlCart.DistributorID);
                    PurchasingLimitProvider.SavePurchaseLimitsToStore(country, hlCart.DistributorID);
                }
            }
        }
Пример #5
0
 public void RefreshVisibility(object sender, EventArgs e)
 {
     if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
     {
         if (null != _cart)
         {
             PurchasingLimits_V01 limits = PurchasingLimitProvider.GetCurrentPurchasingLimits(DistributorID);
             if (null != limits)
             {
                 if (limits.PurchaseType == OrderPurchaseType.Consignment)
                 {
                     pnlAPFIsDueWithinYear.Visible = false;
                     pnlAPFPaid.Visible            = false;
                 }
                 SetPanelsVisibility();
             }
         }
     }
 }
Пример #6
0
        public override Dictionary <int, PurchasingLimits_V01> GetPurchasingLimits(string distributorId, string TIN)
        {
            var codes = new List <string>(CountryType.AR.HmsCountryCodes);

            codes.Add(CountryType.AR.Key);
            var arCOP = codes.Contains(DistributorProfileModel.ProcessingCountryCode);

            var purchasingLimits = base.GetPurchasingLimits(distributorId, TIN);

            // inform UI to not show remaining info.
            var purchasingLimitManager = PurchasingLimitManager(distributorId);
            var currentLimits          = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);

            if (currentLimits.RemainingVolume == MaxAmount || !arCOP || currentLimits.maxVolumeLimit == -1)
            {
                purchasingLimitManager.PurchasingLimits.Values.AsQueryable()
                .ToList()
                .ForEach(pl => pl.PurchaseLimitType = PurchaseLimitType.None);
            }
            return(purchasingLimits);
        }
Пример #7
0
        private ShoppingCartRuleResult CartRetrievedRuleHandler(ShoppingCart_V01 cart,
                                                                ShoppingCartRuleResult result)
        {
            try
            {
                if (null != cart)
                {
                    if (APFDueProvider.IsAPFSkuPresent(cart.CartItems) &&
                        APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale))
                    {
                        var limits =
                            PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);
                        if (null != limits && null != limits.PurchaseSubType)
                        {
                            if (limits.PurchaseType == ServiceProvider.OrderSvc.OrderPurchaseType.Consignment)
                            //No consignment allowed when APFDue
                            {
                                if (limits.PurchaseSubType == "A1")
                                {
                                    limits.PurchaseSubType = "A2";
                                }
                                if (limits.PurchaseSubType == "B1")
                                {
                                    limits.PurchaseSubType = "B2";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("APFRules.it-IT.ProcessAPF DS:{0} locale:{2} ERR:{1}", cart.DistributorID, ex, Locale));
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        ///     The IShoppingCart Rule Interface implementation
        /// </summary>
        /// <param name="cart">The current Shopping Cart</param>
        /// <param name="reason">The Rule invoke Reason</param>
        /// <param name="Result">The Rule Results collection</param>
        /// <returns>The cumulative rule results - including the results of this iteration</returns>
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            var dpm = DistributorProfileModel;

            CurrentSession = (dpm != null)
                ? SessionInfo.GetSessionInfo(dpm.Id, Locale)
                : SessionInfo.GetSessionInfo(cart.DistributorID, Locale);
            string dsid = string.Empty;

            if (CurrentSession.IsReplacedPcOrder)
            {
                dsid = CurrentSession.ReplacedPcDistributorOrderingProfile != null && CurrentSession.ReplacedPcDistributorOrderingProfile.Id != null ? CurrentSession.ReplacedPcDistributorOrderingProfile.Id : cart.DistributorID;
            }
            else
            {
                dsid = cart.DistributorID;
            }
            //   OrderTotals_V01 totals = (OrderTotals_V01)(cart as MyHLShoppingCart).Totals;
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded || reason == ShoppingCartRuleReason.CartRetrieved)
            {
                var Cart           = cart as MyHLShoppingCart;
                var calcTheseItems = new List <ShoppingCartItem_V01>();

                var purchasingLimitManager = PurchasingLimitManager(dsid);
                var myhlCart = cart as MyHLShoppingCart;

                if (null == myhlCart)
                {
                    LoggerHelper.Error(
                        string.Format("{0} myhlCart is null {1}", Locale, dsid));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                PurchasingLimits_V01 PurchasingLimits =
                    PurchasingLimitProvider.GetCurrentPurchasingLimits(dsid);

                purchasingLimitManager.SetPurchasingLimits(PurchasingLimits);


                if (null == PurchasingLimits)
                {
                    LoggerHelper.Error(
                        string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                      dsid));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                var shoppingCart = cart as MyHLShoppingCart;
                if (shoppingCart == null)
                {
                    return(Result);
                }

                if (PurchasingLimits.MaxPCEarningsLimit == -1)
                {
                    return(Result);
                }
                DistributorOrderingProfile distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(cart.DistributorID, "CN");
                if ((CurrentSession.ReplacedPcDistributorOrderingProfile != null && CurrentSession.ReplacedPcDistributorOrderingProfile.IsPC) || (distributorOrderingProfile != null && distributorOrderingProfile.IsPC))
                {
                    if (cart.CurrentItems != null)
                    {
                        calcTheseItems.AddRange(from i in cart.CurrentItems
                                                where !APFDueProvider.IsAPFSku(i.SKU)
                                                select
                                                new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                         i.MinQuantity));
                    }
                    if (cart.CartItems != null)
                    {
                        calcTheseItems.AddRange(from i in cart.CartItems
                                                where !APFDueProvider.IsAPFSku(i.SKU)
                                                select
                                                new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                         i.MinQuantity));
                    }
                    var totals = Cart.Calculate(calcTheseItems, false) as OrderTotals_V01;

                    //OrderTotals_V01 totals = (OrderTotals_V01)(cart as MyHLShoppingCart).Totals;
                    if (totals != null && totals.DiscountedItemsTotal > purchasingLimitManager.MaxPersonalPCConsumptionLimit)
                    {
                        if (cart.CurrentItems.Count > 0)
                        {
                            var sessionInfo = SessionInfo.GetSessionInfo(cart.DistributorID, Locale);
                            if (sessionInfo != null && sessionInfo.ShoppingCart != null && sessionInfo.ShoppingCart.CurrentItems != null)
                            {
                                sessionInfo.ShoppingCart.CurrentItems.RemoveAll(x => x.SKU != null);
                            }
                            cart.CurrentItems.RemoveAll(s => s.SKU != null);
                        }
                        Result.Result = RulesResult.Failure;
                        Result.AddMessage(
                            string.Format(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                    "ErrorMessageToPCWhenhittheFOPLimits").ToString(),
                                purchasingLimitManager.MaxPersonalPCConsumptionLimit));
                    }
                    else
                    {
                        var ruleMessage = cart.RuleResults.FirstOrDefault(x => x.Messages != null && x.Messages.Count > 0 && x.RuleName == "PurchasingLimits Rules");
                        if (ruleMessage != null)
                        {
                            cart.RuleResults.Remove(ruleMessage);
                        }
                    }

                    cart.RuleResults.Add(Result);
                }
                else
                {
                    decimal DistributorRemainingVolumePoints = 0;
                    decimal NewVolumePoints = 0;


                    if (null == myhlCart)
                    {
                        LoggerHelper.Error(
                            string.Format("{0} myhlCart is null {1}", Locale, cart.DistributorID));
                        Result.Result = RulesResult.Failure;
                        return(Result);
                    }

                    DistributorRemainingVolumePoints = PurchasingLimits.RemainingVolume;
                    if (cart.CurrentItems != null && cart.CurrentItems.Count > 0)
                    {
                        var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                        if (currentItem != null)
                        {
                            NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;
                        }
                    }

                    if (NewVolumePoints > 0 || purchasingLimitManager.PurchasingLimitsRestriction == PurchasingLimitRestrictionType.MarketingPlan)
                    {
                        //if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                        {
                            if (PurchasingLimits.maxVolumeLimit == -1)
                            {
                                return(Result);
                            }
                            decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;

                            if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                            {
                                Result.Result = RulesResult.Failure;
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "VolumePointExceedsThresholdByIncreasingQuantity").ToString(),
                                        purchasingLimitManager.MaxPersonalPCConsumptionLimit));
                                cart.RuleResults.Add(Result);
                                //if (purchasingLimitManager.PurchasingLimitsRestriction ==
                                //    PurchasingLimitRestrictionType.MarketingPlan)
                                //    //MPE Thresholds
                                //{
                                //    if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                                //    {
                                //        Result.AddMessage(
                                //            string.Format(
                                //                HttpContext.GetGlobalResourceObject(
                                //                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                //                    "VolumePointExceedsThresholdByIncreasingQuantity").ToString(),
                                //                cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                                //    }
                                //else
                                //{
                                //    Result.AddMessage(
                                //        string.Format(
                                //            HttpContext.GetGlobalResourceObject(
                                //                string.Format("{0}_Rules", HLConfigManager.Platform),
                                //                "VolumePointExceedsThreshold").ToString(), cart.CurrentItems[0].SKU));
                                //}
                                //}
                                //else
                                //{
                                //    if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                                //    {
                                //        Result.AddMessage(
                                //            string.Format(
                                //                HttpContext.GetGlobalResourceObject(
                                //                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                //                    "VolumePointExceedsByIncreasingQuantity").ToString(),
                                //                cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                                //    }
                                //    else
                                //    {
                                //        Result.AddMessage(
                                //            string.Format(
                                //                HttpContext.GetGlobalResourceObject(
                                //                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                //                    "VolumePointExceeds").ToString(), cart.CurrentItems[0].SKU));
                                //    }
                                //}
                            }
                        }
                    }
                }
            }
            return(Result);
        }
        /// <summary>
        ///     The IShoppingCart Rule Interface implementation
        /// </summary>
        /// <param name="cart">The current Shopping Cart</param>
        /// <param name="reason">The Rule invoke Reason</param>
        /// <param name="Result">The Rule Results collection</param>
        /// <returns>The cumulative rule results - including the results of this iteration</returns>
        protected virtual ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                              ShoppingCartRuleReason reason,
                                                              ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var     purchasingLimitManager               = PurchasingLimitManager(cart.DistributorID);
                decimal DistributorRemainingVolumePoints     = 0;
                decimal DistributorRemainingDiscountedRetail = 0;
                //decimal CartVolumePoints = 0;
                decimal NewVolumePoints = 0;

                decimal DistributorRemainingEarnings = 0;
                //decimal CartEarnings = 0;
                decimal NewEarnings = 0;

                decimal Discount = 0;

                var myhlCart = cart as MyHLShoppingCart;

                if (null == myhlCart)
                {
                    LoggerHelper.Error(
                        string.Format("{0} myhlCart is null {1}", Locale, cart.DistributorID));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                PurchasingLimits_V01 PurchasingLimits =
                    PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

                purchasingLimitManager.SetPurchasingLimits(PurchasingLimits);


                if (null == PurchasingLimits)
                {
                    LoggerHelper.Error(
                        string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                      cart.DistributorID));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                DistributorRemainingVolumePoints         =
                    DistributorRemainingDiscountedRetail = PurchasingLimits.RemainingVolume;
                DistributorRemainingEarnings             = PurchasingLimits.RemainingEarnings;

                var distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(cart.DistributorID,
                                                                                               Country);
                Discount = Convert.ToDecimal(distributorOrderingProfile.StaticDiscount);


                if (myhlCart.Totals != null && (myhlCart.Totals as OrderTotals_V01).DiscountPercentage != 0.0M)
                {
                    Discount = (myhlCart.Totals as OrderTotals_V01).DiscountPercentage;
                }

                myhlCart.SetDiscountForLimits(Discount);

                var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                if (currentItem != null)
                {
                    if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.EventTicket)
                    {
                        PurchasingLimitProvider.GetPurchasingLimits(cart.DistributorID, "ETO");
                    }
                    else
                    {
                        NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;
                    }
                }

                if (NewVolumePoints > 0 || PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Earnings ||
                    purchasingLimitManager.PurchasingLimitsRestriction == PurchasingLimitRestrictionType.MarketingPlan)
                {
                    if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                    {
                        if (PurchasingLimits.maxVolumeLimit == -1)
                        {
                            return(Result);
                        }
                        decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;

                        if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            if (purchasingLimitManager.PurchasingLimitsRestriction ==
                                PurchasingLimitRestrictionType.MarketingPlan)
                            //MPE Thresholds
                            {
                                if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceedsThresholdByIncreasingQuantity").ToString(),
                                            cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                                }
                                else
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceedsThreshold").ToString(), cart.CurrentItems[0].SKU));
                                }
                            }
                            else
                            {
                                if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceedsByIncreasingQuantity").ToString(),
                                            cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                                }
                                else
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceeds").ToString(), cart.CurrentItems[0].SKU));
                                }
                            }
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.DiscountedRetail)
                    {
                        var myHlCart       = cart as MyHLShoppingCart;
                        var calcTheseItems = new List <ShoppingCartItem_V01>(cart.CartItems);
                        var existingItem   = cart.CartItems.Find(ci => ci.SKU == cart.CurrentItems[0].SKU);
                        if (null != existingItem)
                        {
                            existingItem.Quantity += cart.CurrentItems[0].Quantity;
                        }
                        else
                        {
                            calcTheseItems.Add(new ShoppingCartItem_V01(0, cart.CurrentItems[0].SKU,
                                                                        cart.CurrentItems[0].Quantity, DateTime.Now));
                        }
                        var totals = myhlCart.Calculate(calcTheseItems) as OrderTotals_V01;
                        if (null != existingItem)
                        {
                            existingItem.Quantity -= cart.CurrentItems[0].Quantity;
                        }
                        if (null == totals)
                        {
                            var message =
                                string.Format(
                                    "Purchasing Limits DiscountedRetail calculation failed due to Order Totals returning a null for Distributor {0}",
                                    cart.DistributorID);
                            LoggerHelper.Error(message);
                            throw new ApplicationException(message);
                        }
                        decimal newDiscountedRetail = 0.0M;

                        decimal dsicount = totals.DiscountPercentage;

                        var skus     = (from s in calcTheseItems where s.SKU != null select s.SKU).ToList();
                        var allItems = CatalogProvider.GetCatalogItems(skus, Country);
                        if (null != allItems && allItems.Count > 0)
                        {
                            newDiscountedRetail = (from t in totals.ItemTotalsList
                                                   from c in allItems.Values
                                                   where
                                                   (c as CatalogItem_V01).ProductType == ServiceProvider.CatalogSvc.ProductType.Product &&
                                                   c.SKU == (t as ItemTotal_V01).SKU
                                                   select(t as ItemTotal_V01).DiscountedPrice).Sum();
                        }

                        myhlCart.SetDiscountForLimits(totals.DiscountPercentage);

                        if (DistributorRemainingDiscountedRetail - newDiscountedRetail < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "DiscountedRetailExceedsByIncreasingQuantity").ToString(),
                                        cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                            }
                            else
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "DiscountedRetailExceeds").ToString(), cart.CurrentItems[0].SKU));
                            }
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Earnings &&
                             cart.OrderSubType == "B1")
                    {
                        NewEarnings += (currentItem.EarnBase) * cart.CurrentItems[0].Quantity * Discount / 100;

                        if (DistributorRemainingEarnings -
                            ((cart as MyHLShoppingCart).ProductEarningsInCart + NewEarnings) < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "EarningExceedsByIncreasingQuantity").ToString(),
                                        cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                            }
                            else
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform), "EarningExceeds")
                                        .ToString(), cart.CurrentItems[0].SKU));
                            }
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.ProductCategory)
                    {
                        if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "PurchaseLimitTypeProductCategory").ToString(), cart.CurrentItems[0].SKU));
                            cart.RuleResults.Add(Result);
                        }
                        else
                        {
                            if (DistributorRemainingVolumePoints -
                                ((cart as MyHLShoppingCart).VolumeInCart + NewVolumePoints) < 0)
                            {
                                Result.Result = RulesResult.Failure;
                                if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceedsThresholdByIncreasingQuantity").ToString(),
                                            cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                                }
                                else
                                {
                                    Result.AddMessage(
                                        string.Format(
                                            HttpContext.GetGlobalResourceObject(
                                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                                "VolumePointExceedsThreshold").ToString(), cart.CurrentItems[0].SKU));
                                }
                            }
                        }
                    }
                    else if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.TotalPaid)
                    {
                        Result.Result = RulesResult.Success;

                        var myHlCart       = cart as MyHLShoppingCart;
                        var calcTheseItems = new List <ShoppingCartItem_V01>();
                        calcTheseItems.AddRange(from i in cart.CartItems
                                                where !APFDueProvider.IsAPFSku(i.SKU)
                                                select
                                                new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                         i.MinQuantity));

                        var existingItem =
                            calcTheseItems.Find(ci => ci.SKU == cart.CurrentItems[0].SKU);
                        if (null != existingItem)
                        {
                            existingItem.Quantity += cart.CurrentItems[0].Quantity;
                        }
                        else
                        {
                            calcTheseItems.Add(new ShoppingCartItem_V01(0, cart.CurrentItems[0].SKU,
                                                                        cart.CurrentItems[0].Quantity, DateTime.Now));
                        }

                        // remove A and L type
                        var allItems =
                            CatalogProvider.GetCatalogItems(
                                (from s in calcTheseItems where s.SKU != null select s.SKU).ToList(), Country);
                        if (null != allItems && allItems.Count > 0)
                        {
                            var skuExcluded = (from c in allItems.Values
                                               where (c as CatalogItem_V01).ProductType != ServiceProvider.CatalogSvc.ProductType.Product
                                               select c.SKU);
                            calcTheseItems.RemoveAll(s => skuExcluded.Contains(s.SKU));
                        }

                        var totals = myhlCart.Calculate(calcTheseItems);
                        if (null == totals)
                        {
                            var message =
                                string.Format(
                                    "Purchasing Limits DiscountedRetail calculation failed due to Order Totals returning a null for Distributor {0}",
                                    cart.DistributorID);
                            LoggerHelper.Error(message);
                            throw new ApplicationException(message);
                        }
                        if (DistributorRemainingVolumePoints - (totals as OrderTotals_V01).AmountDue < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "DiscountedRetailExceedsByIncreasingQuantity").ToString(),
                                        cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                            }
                            else
                            {
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "DiscountedRetailExceeds").ToString(), cart.CurrentItems[0].SKU));
                            }
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else
                    {
                        Result.Result = RulesResult.Success;
                    }
                }
            }

            return(Result);
        }
        public ShoppingCartRuleResult checkVolumeLimits(MyHLShoppingCart cart, ShoppingCartRuleResult Result, string Locale, string Country)
        {
            decimal DistributorRemainingVolumePoints = 0;
            decimal NewVolumePoints = 0;

            IPurchasingLimitManagerFactory purchasingLimitManagerFactory = new PurchasingLimitManagerFactory();
            var purchasingLimitManager = purchasingLimitManagerFactory.GetPurchasingLimitManager(cart.DistributorID);

            var purchasingLimits =
                PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

            if (null == purchasingLimits)
            {
                LoggerHelper.Error(
                    string.Format("{0} PurchasingLimits could not be retrieved for distributor in checkVolumeLimits {1}", Locale,
                                  cart.DistributorID));
                Result.Result = RulesResult.Failure;
                return(Result);
            }

            purchasingLimitManager.SetPurchasingLimits(purchasingLimits);

            DistributorRemainingVolumePoints = purchasingLimits.RemainingVolume;

            var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);

            if (currentItem != null)
            {
                if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.EventTicket)
                {
                    PurchasingLimitProvider.GetPurchasingLimits(cart.DistributorID, "ETO");
                }
                else
                {
                    NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;
                }
            }

            if (NewVolumePoints > 0)
            {
                if (purchasingLimits.maxVolumeLimit == -1)
                {
                    return(Result);
                }
                decimal cartVolume = cart.VolumeInCart;

                if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                {
                    Result.Result = RulesResult.Failure;
                    var orderMonth = new OrderMonth(Country);
                    var msg        = HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform) ?? string.Empty, "VolumePointExceedsOnOrderMonth") as string;
                    msg = string.Format(msg, orderMonth.CurrentOrderMonth.ToString("MM-yyyy"), DistributorRemainingVolumePoints);
                    Result.AddMessage(msg);
                    var globalResourceObject =
                        HttpContext.GetGlobalResourceObject(
                            string.Format("{0}_Rules", HLConfigManager.Platform),
                            "DisgardCommonMessage");
                    if (globalResourceObject != null)
                    {
                        Result.AddMessage(globalResourceObject.ToString());
                    }
                    cart.RuleResults.Add(Result);
                }
            }
            return(Result);
        }
        //protected OrderMonth _orderMonth ;

        public virtual Dictionary <int, PurchasingLimits_V01> GetPurchasingLimits(string distributorId, string TIN)
        {
            try
            {
                //Fetch these records from Web Service

                var purchasingLimitManager = PurchasingLimitManager(distributorId);
                if (PurchasingLimitProvider.IsRestrictedByMarketingPlan(distributorId))
                {
                    purchasingLimitManager.PurchasingLimitsRestriction = PurchasingLimitRestrictionType.MarketingPlan;
                }
                int ordermonth = GetOrderMonth();

                purchasingLimitManager.SetPurchasingLimits(ordermonth);
                var currentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
                //Get the current Limits if the exist
                var storedLimits = PurchasingLimitProvider.GetPurchasingLimitsFromStore(Country,
                                                                                        distributorId);
                //Get the saved limits for the DS and country

                PurchasingLimits_V01 theLimits = null;
                bool shouldUpdateStore         = false;
                if (null != currentLimits && null != storedLimits && storedLimits.Id > 0) //Decide if we use the stored limits
                {
                    //if (null == currentLimits)
                    //{
                    //    currentLimits = storedLimits;
                    //}
                    storedLimits.MaxEarningsLimit = currentLimits.MaxEarningsLimit;
                    storedLimits.maxVolumeLimit   = currentLimits.maxVolumeLimit;

                    if (IsBlackoutPeriod() || storedLimits.OutstandingOrders > 0 ||
                        PurchasingLimitProvider.GetDistributorPurchasingLimitsSource(Country, distributorId) ==
                        DistributorPurchasingLimitsSourceType.InternetOrdering)
                    {
                        if (HLConfigManager.Configurations.DOConfiguration.PurchasingLimitRestrictionType ==
                            PurchasingLimitRestrictionType.Quarterly)
                        {
                            var lastCutoff = GetLastQuarterlyCutoff();
                            if (storedLimits.LastRead < lastCutoff)
                            {
                                storedLimits = currentLimits;
                                if (null != storedLimits)
                                {
                                    PurchasingLimitProvider.UpdatePurchasingLimits(storedLimits, distributorId, true);
                                }
                                theLimits = storedLimits;
                            }
                        }
                        else
                        {
                            theLimits = storedLimits;
                            PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId);
                        }
                    }
                    else
                    {
                        theLimits         = currentLimits;
                        shouldUpdateStore = true;
                    }
                }
                else
                {
                    theLimits = currentLimits;
                }

                if (null == theLimits) //We're bare and need the DS
                {
                    theLimits = new PurchasingLimits_V01();
                    var newLimits =
                        purchasingLimitManager.ReloadPurchasingLimits(ordermonth) as
                        PurchasingLimits_V01;

                    if (newLimits != null)
                    {
                        if (null != currentLimits) //if We're already init'ed resolve against current refreshed DS
                        {
                            if (currentLimits.RemainingVolume > newLimits.RemainingVolume)
                            {
                                currentLimits.RemainingVolume = newLimits.RemainingVolume;
                            }
                            if (currentLimits.RemainingEarnings > newLimits.RemainingEarnings)
                            {
                                currentLimits.RemainingEarnings = newLimits.RemainingEarnings;
                            }
                            currentLimits.MaxEarningsLimit = newLimits.MaxEarningsLimit;
                            currentLimits.maxVolumeLimit   = newLimits.maxVolumeLimit;
                            theLimits          = currentLimits;
                            theLimits.LastRead = DateTime.UtcNow;
                        }
                        else
                        {
                            //Probably first time in - refresh from DS.
                            theLimits.RemainingVolume   = newLimits.RemainingVolume;
                            theLimits.RemainingEarnings = newLimits.RemainingEarnings;
                            theLimits.MaxEarningsLimit  = newLimits.MaxEarningsLimit;
                            theLimits.maxVolumeLimit    = newLimits.maxVolumeLimit;
                            theLimits.LastRead          = DateTime.UtcNow;
                        }
                    }
                }

                if (null == storedLimits || shouldUpdateStore)
                {
                    PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId, true);
                }
                else
                {
                    PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId,
                                                                   ordermonth);
                }
                var theCurrentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
                var limitsType       = PurchaseLimitType.Volume;

                if (HLConfigManager.Configurations.DOConfiguration.PurchasingLimitRestrictionType ==
                    PurchasingLimitRestrictionType.MarketingPlan && theCurrentLimits.maxVolumeLimit < 0)
                {
                    limitsType = PurchaseLimitType.None;
                }

                if (DistributorIsExemptFromPurchasingLimits(distributorId) &&
                    PurchasingLimitManager(distributorId).PurchasingLimitsRestriction !=
                    PurchasingLimitRestrictionType.MarketingPlan)
                {
                    limitsType = PurchaseLimitType.None;
                }
                else
                {
                    limitsType = PurchaseLimitType.Volume;
                }
                purchasingLimitManager.PurchasingLimits.Values.AsQueryable()
                .ToList()
                .ForEach(pl => pl.PurchaseLimitType = limitsType);

                return(purchasingLimitManager.PurchasingLimits);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(
                    string.Format(
                        "Messages:{0},StackTrace:{1},Locale:{2},DistributorId{3},Purchasing Months:{4}",
                        ex.Message, ex.StackTrace, Locale, distributorId, GetOrderMonth()));
                return(null);
            }
        }
        public virtual bool PurchasingLimitsAreExceeded(string distributorId)
        {
            bool exceeded = false;

            if (!PurchasingLimitProvider.RequirePurchasingLimits(distributorId, Country))
            {
                return(exceeded);
            }

            var cart = ShoppingCartProvider.GetShoppingCart(distributorId, Locale, true);

            PurchasingLimits_V01 limits = null;

            if (HLConfigManager.Configurations.DOConfiguration.SaveDSSubType)
            {
                limits = PurchasingLimitProvider.GetPurchasingLimits(distributorId, cart.SelectedDSSubType);
            }
            else
            {
                limits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
            }
            if (null != cart && null != cart.Totals && cart.OrderCategory != ServiceProvider.CatalogSvc.OrderCategoryType.ETO)
            {
                bool restrictedByMarketingPlan = PurchasingLimitProvider.IsRestrictedByMarketingPlan(distributorId);
                if ((null != limits && (limits.PurchaseLimitType != PurchaseLimitType.None) ||
                     restrictedByMarketingPlan))
                {
                    if (limits.PurchaseType != OrderPurchaseType.Consignment ||
                        (limits.PurchaseType == OrderPurchaseType.Consignment && cart.OrderSubType == "B1"))
                    {
                        if (restrictedByMarketingPlan)
                        {
                            limits.PurchaseLimitType = (limits.maxVolumeLimit == -1)
                                                           ? PurchaseLimitType.None
                                                           : PurchaseLimitType.Volume;
                        }
                        else
                        {
                            limits.PurchaseLimitType = (limits.maxVolumeLimit == -1)
                                                           ? PurchaseLimitType.None
                                                           : limits.PurchaseLimitType;
                        }

                        switch (limits.PurchaseLimitType)
                        {
                        case PurchaseLimitType.Earnings:
                        {
                            exceeded = ((limits.RemainingEarnings - cart.ProductEarningsInCart) < 0);
                            break;
                        }

                        case PurchaseLimitType.Volume:
                        {
                            exceeded = ((limits.RemainingVolume - cart.VolumeInCart) < 0);
                            break;
                        }

                        case PurchaseLimitType.DiscountedRetail:
                        {
                            exceeded = ((limits.RemainingVolume - cart.ProductDiscountedRetailInCart) < 0);
                            break;
                        }

                        case PurchaseLimitType.TotalPaid:
                        {
                            if (null != cart.Totals)
                            {
                                exceeded = ((limits.RemainingVolume - (cart.Totals as OrderTotals_V01).AmountDue) < 0);
                            }
                            break;
                        }
                        }
                    }
                }
                //else if (ods.PurchasingLimitsRestriction == PurchasingLimitRestrictionType.MarketingPlan)
                //{
                //    exceeded = ((limits.RemainingVolume - cart.VolumeInCart) < 0);
                //}
            }

            return(exceeded);
        }
Пример #13
0
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    CatalogItem_V01 currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                    Result = base.PerformRules(cart, reason, Result);
                }
            }

            if (reason == ShoppingCartRuleReason.CartCreated && cart.CartItems.Any())
            {
                var currentLimits = base.GetPurchasingLimits(cart.DistributorID, string.Empty);
                var theLimits     = currentLimits[PurchasingLimitProvider.GetOrderMonth()];
                // If it's threshold volume point for all product types is counted
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(theLimits))
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
                else if (!DistributorIsExemptFromPurchasingLimits(cart.DistributorID))
                {
                    var     purchasingLimitManager               = PurchasingLimitManager(cart.DistributorID);
                    decimal DistributorRemainingVolumePoints     = 0;
                    decimal DistributorRemainingDiscountedRetail = 0;
                    var     myhlCart = cart as MyHLShoppingCart;
                    if (null == myhlCart)
                    {
                        LoggerHelper.Error(
                            string.Format("{0} myhlCart is null {1}", Locale, cart.DistributorID));
                        Result.Result = RulesResult.Failure;
                        return(Result);
                    }

                    PurchasingLimits_V01 PurchasingLimits =
                        PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

                    purchasingLimitManager.SetPurchasingLimits(PurchasingLimits);

                    if (null == PurchasingLimits)
                    {
                        LoggerHelper.Error(
                            string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                          cart.DistributorID));
                        Result.Result = RulesResult.Failure;
                        return(Result);
                    }

                    DistributorRemainingVolumePoints         =
                        DistributorRemainingDiscountedRetail = PurchasingLimits.RemainingVolume;

                    if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.Volume)
                    {
                        if (PurchasingLimits.maxVolumeLimit == -1)
                        {
                            return(Result);
                        }
                        decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;
                        if (DistributorRemainingVolumePoints - cartVolume < 0)
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                PlatformResources.GetGlobalResourceString("ErrorMessage",
                                                                          "NoCheckoutPurchaseLimitsExceeded"));
                            cart.RuleResults.Add(Result);
                        }
                    }
                    else
                    {
                        Result.Result = RulesResult.Success;
                    }
                }
                else
                {
                    Result = base.PerformRules(cart, reason, Result);
                }
            }
            return(Result);
        }
Пример #14
0
        private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                    ShoppingCartRuleReason reason,
                                                    ShoppingCartRuleResult Result)
        {
            if (cart == null)
            {
                return(Result);
            }

            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                string sku     = cart.CurrentItems[0].SKU.Trim();
                var    allowed = new List <string>();
                if (_IBPAllowedSubTypes.TryGetValue(sku, out allowed))
                {
                    string orderSubType = cart.OrderSubType;
                    if (string.IsNullOrEmpty(cart.OrderSubType))
                    {
                        var purchasingLimits =
                            PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);
                        if (null != purchasingLimits)
                        {
                            orderSubType = purchasingLimits.PurchaseSubType;
                        }
                    }
                    if (!allowed.Contains(orderSubType))
                    {
                        Result.Result = RulesResult.Failure;
                        var errorMessage =
                            HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform),
                                                                "SKU" + sku + "Limitations") ??
                            string.Format("SKU {0} Limitations", sku);

                        Result.AddMessage(string.Format(errorMessage.ToString(), cart.CurrentItems[0].SKU));
                        cart.RuleResults.Add(Result);
                    }
                }

                if (cart.CurrentItems[0].SKU == HLConfigManager.Configurations.DOConfiguration.TodayMagazineSku)
                {
                    var catItems =
                        CatalogProvider.GetCatalogItems(
                            (from c in cart.CartItems select c.SKU.Trim()).ToList <string>(), Country);
                    if (catItems != null)
                    {
                        if (!catItems.Any(c => c.Value.ProductType == ProductType.Product))
                        {
                            Result.Result = RulesResult.Failure;
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform), "AddProductFirst")
                                    .ToString(), cart.CurrentItems[0].SKU));
                            cart.RuleResults.Add(Result);
                        }
                    }
                }
            }
            else if (reason == ShoppingCartRuleReason.CartItemsAdded)
            {
                var tempShoppingCartList = new ShoppingCartItemList();
                tempShoppingCartList.AddRange(from c in cart.CartItems
                                              select new ShoppingCartItem_V01(c.ID, c.SKU, c.Quantity, c.Updated));
                var item = tempShoppingCartList.Where(i => i.SKU == cart.CurrentItems[0].SKU);
                if (null != item && item.Count() > 0)
                {
                    var itemFirst = item.First();
                    itemFirst.Quantity += cart.CurrentItems[0].Quantity;
                }
                else
                {
                    tempShoppingCartList.Add(cart.CurrentItems[0]);
                }
            }
            else if (reason == ShoppingCartRuleReason.CartCalculated)
            {
                string orderSubType = cart.OrderSubType;
                if (string.IsNullOrEmpty(cart.OrderSubType))
                {
                    var purchasingLimits =
                        PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);
                    if (null != purchasingLimits)
                    {
                        orderSubType = purchasingLimits.PurchaseSubType;
                    }
                }

                var myhlCart = cart as MyHLShoppingCart;
                if (myhlCart != null)
                {
                    var found =
                        (from a in _IBPAllowedSubTypes.Keys.ToList()
                         from s in myhlCart.ShoppingCartItems
                         where a == s.SKU
                         select a);
                    if (found.Count() > 0)
                    {
                        var skuToDelete = new List <string>();
                        foreach (string sku in found)
                        {
                            var allowed = new List <string>();
                            if (_IBPAllowedSubTypes.TryGetValue(sku, out allowed))
                            {
                                if (!allowed.Contains(orderSubType))
                                {
                                    skuToDelete.Add(sku);
                                }
                            }
                        }
                        if (skuToDelete.Count() > 0)
                        {
                            myhlCart.DeleteItemsFromCart(skuToDelete);
                            foreach (string sku in skuToDelete)
                            {
                                Result.Result = RulesResult.Failure;
                                Result.AddMessage(
                                    string.Format(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                            "SKU" + sku + "Limitations").ToString(), sku));
                                cart.RuleResults.Add(Result);
                            }
                        }
                    }
                }
            }

            return(Result);
        }
        public override Dictionary <int, PurchasingLimits_V01> GetPurchasingLimits(string distributorId, string TIN)
        {
            if (DistributorIsExemptFromPurchasingLimits(distributorId))
            {
                return(null);
            }

            //Fetch these records from Web Service
            string country = DistributorProfileModel.ProcessingCountryCode;

            var purchasingLimitManager = PurchasingLimitManager(distributorId);

            purchasingLimitManager.SetPurchasingLimits(PurchasingLimitProvider.GetOrderMonth());
            PurchasingLimits_V01 currentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
            //Get the current Limits if the exist
            PurchasingLimits_V01 storedLimits = PurchasingLimitProvider.GetPurchasingLimitsFromStore(Country,
                                                                                                     distributorId);
            //Get the saved limits for the DS and country

            PurchasingLimits_V01 theLimits = null;

            if (null != storedLimits && storedLimits.Id > 0) //Decide if we use the stored limits
            {
                storedLimits.MaxEarningsLimit = purchasingLimitManager.MaxEarningsLimit;
                storedLimits.maxVolumeLimit   = purchasingLimitManager.MaxPersonalConsumptionLimit;

                if (IsBlackoutPeriod() || storedLimits.OutstandingOrders > 0 ||
                    PurchasingLimitProvider.GetDistributorPurchasingLimitsSource(Country, distributorId) ==
                    DistributorPurchasingLimitsSourceType.InternetOrdering)
                {
                    theLimits = storedLimits;
                    PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId);
                }
                else
                {
                    theLimits = currentLimits;
                }
            }
            else
            {
                theLimits = currentLimits;
            }

            if (null == theLimits) //We're bare and need the DS
            {
                theLimits = new PurchasingLimits_V01();
                var limit = purchasingLimitManager.ReloadPurchasingLimits(PurchasingLimitProvider.GetOrderMonth());
                if (null != currentLimits) //if We're already init'ed resolve against current refreshed DS
                {
                    if (currentLimits.RemainingVolume > purchasingLimitManager.RemainingPersonalConsumptionLimit)
                    {
                        currentLimits.RemainingVolume = purchasingLimitManager.RemainingPersonalConsumptionLimit;
                    }
                    if (currentLimits.RemainingEarnings > purchasingLimitManager.RemainingEarningsLimit)
                    {
                        currentLimits.RemainingEarnings = purchasingLimitManager.RemainingEarningsLimit;
                    }
                    currentLimits.MaxEarningsLimit = purchasingLimitManager.MaxEarningsLimit;
                    currentLimits.maxVolumeLimit   = purchasingLimitManager.MaxPersonalConsumptionLimit;
                    theLimits          = currentLimits;
                    theLimits.LastRead = DateTime.UtcNow;
                }
                else
                {
                    //Probably first time in - refresh from DS.
                    theLimits.RemainingVolume   = purchasingLimitManager.RemainingPersonalConsumptionLimit;
                    theLimits.RemainingEarnings = purchasingLimitManager.RemainingEarningsLimit;
                    theLimits.MaxEarningsLimit  = purchasingLimitManager.MaxEarningsLimit;
                    theLimits.maxVolumeLimit    = purchasingLimitManager.MaxPersonalConsumptionLimit;
                    theLimits.LastRead          = DateTime.UtcNow;
                }
            }

            if (null == storedLimits)
            {
                PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId, country, true);
            }
            else
            {
                PurchasingLimitProvider.UpdatePurchasingLimits(theLimits, distributorId, PurchasingLimitProvider.GetOrderMonth());
            }
            var theCurrentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
            var limitsType       = PurchaseLimitType.Volume;

            if (theCurrentLimits.maxVolumeLimit < 0)
            {
                limitsType = PurchaseLimitType.None;
            }

            purchasingLimitManager.PurchasingLimits.Values.AsQueryable().ToList().ForEach(pl => pl.PurchaseLimitType = limitsType);

            return(purchasingLimitManager.PurchasingLimits);
        }
Пример #16
0
        /// <summary>
        ///     The IShoppingCart Rule Interface implementation
        /// </summary>
        /// <param name="cart">The current Shopping Cart</param>
        /// <param name="reason">The Rule invoke Reason</param>
        /// <param name="Result">The Rule Results collection</param>
        /// <returns>The cumulative rule results - including the results of this iteration</returns>
        protected override ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            if (reason == ShoppingCartRuleReason.CartItemsBeingAdded)
            {
                decimal DistributorRemainingVolumePoints = 0;
                decimal NewVolumePoints = 0;

                if (cart.CurrentItems == null || cart.CurrentItems.Count == 0)
                {
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                var orderMonth = new OrderMonth(Country);

                PurchasingLimitManager(cart.DistributorID).SetPurchasingLimits(PurchasingLimitProvider.GetOrderMonth());

                var PurchasingLimits =
                    PurchasingLimitProvider.GetCurrentPurchasingLimits(cart.DistributorID);

                if (null == PurchasingLimits)
                {
                    LoggerHelper.Error(
                        string.Format("{0} PurchasingLimits could not be retrieved for distributor {1}", Locale,
                                      cart.DistributorID));
                    Result.Result = RulesResult.Failure;
                    return(Result);
                }

                DistributorRemainingVolumePoints = PurchasingLimits.RemainingVolume;
                var currentItem = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country);
                if (currentItem != null)
                {
                    if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.EventTicket)
                    {
                        PurchasingLimitProvider.GetPurchasingLimits(cart.DistributorID, "ETO");
                    }
                    else
                    {
                        NewVolumePoints = currentItem.VolumePoints * cart.CurrentItems[0].Quantity;
                    }
                }

                // validate order threshold first
                if (PurchasingLimits.maxVolumeLimit == -1)
                {
                    return(Result);
                }

                if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.ProductCategory && currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product)
                {
                    Result.Result = RulesResult.Failure;
                    Result.AddMessage(
                        string.Format(
                            HttpContext.GetGlobalResourceObject(
                                string.Format("{0}_Rules", HLConfigManager.Platform),
                                "PurchaseLimitTypeProductCategory") as string ?? string.Empty,
                            cart.CurrentItems[0].SKU));
                    cart.RuleResults.Add(Result);
                    return(Result);
                }

                // validate against order threshold first
                decimal cartVolume = (cart as MyHLShoppingCart).VolumeInCart;
                if (PurchasingLimitProvider.IsOrderThresholdMaxVolume(PurchasingLimits) ||
                    PurchasingLimits.PurchaseLimitType != PurchaseLimitType.None)
                {
                    if (DistributorRemainingVolumePoints - (cartVolume + NewVolumePoints) < 0)
                    {
                        Result.Result = RulesResult.Failure;

                        string message = string.Empty;

                        if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                        {
                            Result.Messages.Add(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThresholdByIncreasingQuantity") as string ?? string.Empty,
                                    cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                        }
                        else
                        {
                            Result.Messages.Add(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThreshold") as string ?? string.Empty, cart.CurrentItems[0].SKU));
                        }

                        if (Result.Messages.Any())
                        {
                            cart.RuleResults.Add(Result);
                        }
                        else
                        {
                            Result.Result = RulesResult.Success;
                        }

                        return(Result); // if fails, just return
                    }
                }

                if (PurchasingLimits.PurchaseLimitType == PurchaseLimitType.ProductCategory)
                {
                    if (DistributorRemainingVolumePoints -
                        ((cart as MyHLShoppingCart).VolumeInCart + NewVolumePoints) < 0)
                    {
                        Result.Result = RulesResult.Failure;
                        if (cart.CartItems.Exists(item => item.SKU == cart.CurrentItems[0].SKU))
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThresholdByIncreasingQuantity") as string ?? string.Empty,
                                    cart.CurrentItems[0].SKU, cart.CurrentItems[0].Quantity));
                        }
                        else
                        {
                            Result.AddMessage(
                                string.Format(
                                    HttpContext.GetGlobalResourceObject(
                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                        "VolumePointExceedsThreshold") as string ?? string.Empty, cart.CurrentItems[0].SKU));
                        }
                    }
                }
                else
                {
                    Result.Result = RulesResult.Success;
                }
            }
            return(Result);
        }
Пример #17
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var _errors = new List <string>();

            if (ShoppingCart != null)
            {
                if (ShoppingCart.Totals == null)
                {
                    ShoppingCart.Calculate();
                }
                // Set the order
                var order = OrderCreationHelper.CreateOrderObject(ShoppingCart) as Order_V01;
                order.DistributorID       = DistributorID;
                order.CountryOfProcessing = CountryCode;
                order.ReceivedDate        = DateUtils.GetCurrentLocalTime(CountryCode);
                order.OrderMonth          = GetOrderMonthShortString();
                order.OrderCategory       =
                    (OrderCategoryType)
                    Enum.Parse(typeof(OrderCategoryType),
                               HLConfigManager.Configurations.DOConfiguration.HFFModalOrderType);
                order.Shipment = OrderProvider.CreateShippingInfo(CountryCode, ShoppingCart);
                var provider = (Page as ProductsBase).GetShippingProvider();
                (order.Shipment as ShippingInfo_V01).Address = ObjectMappingHelper.Instance.GetToOrder(provider.GetHFFDefaultAddress(ShoppingCart.DeliveryInfo.Address));
                order.Handling = OrderProvider.CreateHandlingInfo(CountryCode, string.Empty, ShoppingCart,
                                                                  order.Shipment as ShippingInfo_V01);
                List <Payment> payments = null;
                if (PaymentOptions != null)
                {
                    if (PaymentOptions.ValidateAndGetPayments(ObjectMappingHelper.Instance.GetToOrder(ShoppingCart.DeliveryInfo.Address.Address), out payments))
                    {
                        if (payments != null && payments.Count > 0)
                        {
                            order.Payments = new PaymentCollection();
                            order.Payments.AddRange((from p in payments select p).ToArray());
                        }

                        HLRulesManager.Manager.PerformTaxationRules(order, (Page as ProductsBase).Locale);

                        if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
                        {
                            if (order.PurchasingLimits == null)
                            {
                                var limits =
                                    PurchasingLimitProvider.GetCurrentPurchasingLimits(DistributorID);
                                if (null != limits)
                                {
                                    limits.PurchaseSubType = ShoppingCart.SelectedDSSubType;
                                    order.PurchasingLimits = limits;
                                    order.PurchaseCategory = limits.PurchaseType;
                                }
                            }
                        }

                        order = OrderProvider.PopulateLineItems(CountryCode, order, ShoppingCart) as Order_V01;
                        order.DiscountPercentage = (ShoppingCart.Totals as OrderTotals_V01).DiscountPercentage;
                        var theOrder = OrderProvider.CreateOrder(order, ShoppingCart, CountryCode);
                        List <FailedCardInfo> failedCards = null;
                        string error   = string.Empty;
                        string orderID = OrderProvider.ImportOrder(theOrder, out error, out failedCards,
                                                                   ShoppingCart.ShoppingCartID);

                        if (string.IsNullOrEmpty(error))
                        {
                            // TODO: how to get auth token
                            ShoppingCartProvider.UpdateShoppingCart(ShoppingCart,
                                                                    OrderProvider.SerializeOrder(theOrder, order,
                                                                                                 ShoppingCart,
                                                                                                 new Guid()),
                                                                    orderID, order.ReceivedDate);
                            if (string.IsNullOrEmpty(order.OrderID))
                            {
                                order.OrderID = orderID;
                                order.Pricing = ShoppingCart.Totals;
                            }
                            if (!String.IsNullOrEmpty(ShoppingCart.EmailAddress))
                            {
                                EmailHelper.SendEmail(ShoppingCart, order);
                            }

                            OrderSubmitted(order, orderID);

                            // Handling UI
                            lbOrderNumValue.Text = orderID;
                            divPayment.Attributes.Add("class",
                                                      string.Format("{0} hide", divSubmitCommand.Attributes["class"]));
                            divPaymentSummary.Attributes["class"] =
                                divEmailNotification.Attributes["class"].Replace("hide", string.Empty);

                            //hide the PaymentSummary if the Payment choice for HFF Order is Wire
                            if (SessionInfo.SelectedPaymentChoice == "WireTransfer")
                            {
                                divPaymentSummary.Attributes["class"] = "hide";
                            }
                            else
                            {
                                divPaymentSummary.Attributes["class"] =
                                    divEmailNotification.Attributes["class"].Replace("hide", string.Empty);
                            }

                            divOrderComplete.Attributes["class"] = divOrderComplete.Attributes["class"].Replace("hide",
                                                                                                                string
                                                                                                                .Empty);
                            divEmailNotification.Attributes["class"] =
                                divEmailNotification.Attributes["class"].Replace("hide", string.Empty);
                            divSubmitCommand.Attributes.Add("class",
                                                            string.Format("{0} hide",
                                                                          divSubmitCommand.Attributes["class"]));
                            divEndCommand.Attributes["class"] = divEndCommand.Attributes["class"].Replace("hide",
                                                                                                          string.Empty);

                            if (PurchasingLimitProvider.RequirePurchasingLimits(DistributorID, CountryCode))
                            {
                                PurchasingLimitProvider.ReconcileAfterPurchase(ShoppingCart, DistributorID, CountryCode);
                            }

                            var currentSession = SessionInfo.GetSessionInfo(DistributorID, Locale);
                            if (currentSession != null)
                            {
                                if (!String.IsNullOrEmpty(currentSession.OrderNumber))
                                {
                                    currentSession.OrderNumber                      = String.Empty;
                                    currentSession.OrderMonthShortString            = string.Empty;
                                    currentSession.OrderMonthString                 = string.Empty;
                                    currentSession.ShippingMethodNameMX             = String.Empty;
                                    currentSession.ShippingMethodNameUSCA           = String.Empty;
                                    currentSession.ShoppingCart.CustomerOrderDetail = null;
                                    // currentSession.CustomerPaymentSettlementApproved = false; Commented out for Merge. Need to investigate
                                    currentSession.CustomerOrderNumber = String.Empty;
                                    currentSession.CustomerAddressID   = 0;
                                    if (null != currentSession.ShippingAddresses)
                                    {
                                        var customerAddress =
                                            currentSession.ShippingAddresses.Find(
                                                p => p.ID == currentSession.CustomerAddressID);
                                        if (customerAddress != null)
                                        {
                                            currentSession.ShippingAddresses.Remove(customerAddress);
                                        }
                                    }
                                }
                            }

                            //Clear the order month session...
                            Session["OrderMonthDataSessionKey"] = null;
                            SessionInfo.SetSessionInfo(DistributorID, Locale, currentSession);

                            if (ShoppingCart != null)
                            {
                                // take out quantities from inventory
                                ShoppingCartProvider.UpdateInventory(ShoppingCart, CountryCode, Locale, true);
                            }

                            ShoppingCart.CloseCart();
                            RecoverActiveCart();
                            onHFFOrderPlaced(this, new EventArgs());
                        }
                        else
                        {
                            LoggerHelper.Error(error);
                            if (error.Contains("AUTHORIZE PAYMENT"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "PaymenyFail"));
                            }
                            else if (error.Contains("TIMEOUT"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "Resubmit"));
                            }
                            else if (error.Contains("ORDER CANNOT BE FULFILLED FOR THE DISTRIBUTOR"))
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "CantOrder"));
                            }
                            else
                            {
                                _errors.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "TransactionFail"));
                            }
                        }
                    }
                }
            }
        }
        private void DisplayRemainingValues(string DSSubType, bool Refresh)
        {
            var limits = new PurchasingLimits_V01();

            trRemainingVal.Visible = true;
            ShoppingCart.EmailValues.RemainingVolume = string.Empty;

            if (string.IsNullOrEmpty(DSSubType))
            {
                limits = PurchasingLimitProvider.GetCurrentPurchasingLimits(DistributorID);
            }
            else
            {
                limits = PurchasingLimitProvider.GetPurchasingLimits(DistributorID, DSSubType);
            }

            if (FOPEnabled)
            {
                if (limits != null && limits.LimitsRestrictionType == LimitsRestrictionType.FOP)
                {
                    DisplayRemainingValuesFOP(DistributorID, Refresh, limits);
                    return;
                }
            }

            if (DSSubType == "RE")
            {
                trRemainingVal.Visible = false;
                OnOrderSubTypeChanged(this,
                                      new OrderSubTypeEventArgs(ddl_DSSubType.SelectedItem.Value, true, false, Refresh));
            }
            else if (DSSubType == "PC")
            {
                lblRemainingValDisplay.Text = GetLocalResourceObject("RemainingVolume").ToString();
                if (ShoppingCart != null)
                {
                    decimal discountedRetail = (null != ShoppingCart.Totals)
                                                   ? ShoppingCart.ProductDiscountedRetailInCart
                                                   : 0.0M;
                    decimal remaining = limits.RemainingVolume - discountedRetail;
                    if (remaining < 0)
                    {
                        remaining = 0;
                    }
                    lblRemainingVal.Text = limits.PurchaseLimitType == PurchaseLimitType.Volume
                                               ? remaining.ToString("N2")
                                               : getAmountString(remaining);
                }
                OnOrderSubTypeChanged(this,
                                      new OrderSubTypeEventArgs(ddl_DSSubType.SelectedItem.Value, false, true, Refresh));
            }
            else
            {
                trRemainingVal.Visible = false;
                OnOrderSubTypeChanged(this, new OrderSubTypeEventArgs("NA", true, false, Refresh));
            }
            if (trRemainingVal.Visible)
            {
                ShoppingCart.EmailValues.RemainingVolume = lblRemainingVal.Text;
            }
        }