Beispiel #1
0
        /// <summary>
        /// query fusion if there is outstanding orders
        /// </summary>
        /// <param name="country"></param>
        /// <param name="distributorId"></param>
        /// <returns></returns>
        private DistributorPurchasingLimitsSourceType GetDistributorPurchasingLimitsSource(string country, string distributorId)
        {
            if (HLConfigManager.Configurations.DOConfiguration.IsChina)
            {
                return(DistributorPurchasingLimitsSourceType.HMS);
            }

            if (PurchaseRestrictionProvider.IsBlackoutPeriod(country))
            {
                return(DistributorPurchasingLimitsSourceType.InternetOrdering);
            }

            var    source    = DistributorPurchasingLimitsSourceType.Unknown;
            string cacheKey  = string.Format("{0}_{1}_{2}", "FOP_PLSOURCE", country, distributorId);
            string useFusion = HttpRuntime.Cache[cacheKey] as string;

            if (useFusion == null)
            {
                if (!string.IsNullOrEmpty(distributorId) && !string.IsNullOrEmpty(country))
                {
                    try
                    {
                        var proxy   = ServiceClientProvider.GetOrderServiceProxy();
                        var request =
                            new GetDistributorPurchasingLimitsSourceRequest_V01();
                        request.DistributorID = distributorId;
                        request.CountryCode   = country;
                        // RS exception in country for request
                        if (country.Equals("RS"))
                        {
                            request.CountryCode = HL.Common.ValueObjects.CountryType.RS.HmsCountryCodes.FirstOrDefault();
                        }

                        var response = proxy.GetDistributorPurchasingLimitsSource(new GetDistributorPurchasingLimitsSourceRequest(request)).GetDistributorPurchasingLimitsSourceResult as GetDistributorPurchasingLimitsSourceResponse_V01;
                        if (response.Status != MyHerbalife3.Ordering.ServiceProvider.OrderSvc.ServiceResponseStatusType.Success)
                        {
                            LoggerHelper.Error(
                                string.Format("GetDistributorPurchasingLimitsSource failed for Distributor {0}, Country {1}, Status{2}",
                                              distributorId, country, response.Status));
                        }
                        if (null != response)
                        {
                            source    = response.Source;
                            useFusion = source == DistributorPurchasingLimitsSourceType.HMS ? Boolean.TrueString : Boolean.FalseString;
                            HttpRuntime.Cache.Insert(cacheKey, useFusion, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.Error(
                            string.Format(
                                "Error retrieving OutstandingOrders Status from BPEL service for: DS:{0} - Country:{1}, {2}",
                                distributorId, country, ex));
                    }
                }
            }

            return(source = string.IsNullOrEmpty(useFusion) ? DistributorPurchasingLimitsSourceType.InternetOrdering : (useFusion.Equals(Boolean.TrueString) ? DistributorPurchasingLimitsSourceType.HMS : DistributorPurchasingLimitsSourceType.InternetOrdering));
        }
Beispiel #2
0
 private void checkLimitExpiry(PurchasingLimits_V01 limit, DateTime localDatetime)
 {
     if (limit.LimitsRestrictionType == LimitsRestrictionType.FOP ||
         limit.LimitsRestrictionType == LimitsRestrictionType.OrderThreshold)
     {
         if (limit.maxVolumeLimit == -1)
         {
             limit.Completed         = true;
             limit.maxVolumeLimit    = -1; // no limit
             limit.RestrictionPeriod = PurchasingLimitRestrictionPeriod.OneTime;
             WritePurchasingLimitsToDB(new List <PurchasingLimits> {
                 limit
             });
         }
         else if (hasValidDate(limit.FirstOrderDate) && !limit.Completed)
         {
             DateTime firstOrderDatetimeLocal = new DateTime(limit.FirstOrderDate.Year, limit.FirstOrderDate.Month, limit.FirstOrderDate.Day);
             DateTime expiry = firstOrderDatetimeLocal.AddDays(limit.ThresholdPeriod == 0 ? PurchaseRestrictionProvider.GetThresholdPeriod(this._processingCountry) : limit.ThresholdPeriod);
             localDatetime = new DateTime(localDatetime.Year, localDatetime.Month, localDatetime.Day);
             if (expiry <= localDatetime)
             {
                 limit.Completed         = true;
                 limit.maxVolumeLimit    = -1; // no limit
                 limit.Expiry            = expiry;
                 limit.RestrictionPeriod = PurchasingLimitRestrictionPeriod.OneTime;
                 WritePurchasingLimitsToDB(new List <PurchasingLimits> {
                     limit
                 });
             }
         }
     }
 }
Beispiel #3
0
 public void ReconcileAfterPurchaseForeLearning(MyHLShoppingCart shoppingCart)
 {
     foreach (var l in this.PurchasingLimits.Keys)
     {
         var currentLimits = PurchasingLimits[l];
         if (currentLimits.LimitsRestrictionType == LimitsRestrictionType.FOP)
         {
             currentLimits.maxVolumeLimit   = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV;
             currentLimits.RemainingVolume -= currentLimits.maxVolumeLimit - shoppingCart.VolumeInCart;
             if (!hasValidDate(currentLimits.FirstOrderDate) && shoppingCart.VolumeInCart > 0) // this is just to indicate first order just placed
             {
                 currentLimits.FirstOrderDate = HL.Common.Utilities.DateUtils.ConvertToCurrentLocalTime(DateTime.Now, this._currentLoggedInCountry);
                 currentLimits.Expiry         = AbsoluteEnd(currentLimits.FirstOrderDate.AddDays(currentLimits.ThresholdPeriod == 0 ? PurchaseRestrictionProvider.GetThresholdPeriod(_processingCountry) - 1 : currentLimits.ThresholdPeriod)); /// one for now
             }
         }
         else if (currentLimits.LimitsRestrictionType == LimitsRestrictionType.PurchasingLimits)
         {
             currentLimits.RemainingVolume -= shoppingCart.ProductVolumeInCart;
         }
         UpdatePurchasingLimits(currentLimits);
     }
 }
Beispiel #4
0
        public void ReconcileAfterPurchase(MyHLShoppingCart shoppingCart, string distributorId, string countryCode)
        {
            if (null != shoppingCart)
            {
                if (HLConfigManager.Configurations.ShoppingCartConfiguration.CheckELearning)
                {
                    if (PurchaseRestrictionProvider.RequireTraining(distributorId, shoppingCart.Locale, countryCode))
                    {
                        ReconcileAfterPurchaseForeLearning(shoppingCart);
                        return;
                    }
                }

                var currentLimits = GetPurchasingLimits(shoppingCart.OrderMonth);

                if (null != currentLimits)
                {
                    // orderMonth : 1408
                    if (currentLimits.LimitsRestrictionType == LimitsRestrictionType.FOP || currentLimits.LimitsRestrictionType == LimitsRestrictionType.OrderThreshold)
                    {
                        bool     placingFirstOrder = false;
                        DateTime currentDateTime   = HL.Common.Utilities.DateUtils.ConvertToCurrentLocalTime(DateTime.Now, this._currentLoggedInCountry);
                        currentLimits.RemainingVolume -= shoppingCart.VolumeInCart;
                        if (!hasValidDate(currentLimits.FirstOrderDate) && shoppingCart.VolumeInCart > 0) // this is just to indicate first order just placed
                        {
                            placingFirstOrder             = true;
                            currentLimits.maxVolumeLimit  = PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP(_processingCountry);
                            currentLimits.RemainingVolume = currentLimits.maxVolumeLimit - shoppingCart.VolumeInCart;
                            //currentLimits.FirstOrderDate = currentDateTime = HL.Common.Utilities.DateUtils.ConvertToCurrentLocalTime(DateTime.Now, this._currentLoggedInCountry);
                            currentLimits.Expiry = AbsoluteEnd(currentLimits.FirstOrderDate.AddDays(currentLimits.ThresholdPeriod == 0 ? PurchaseRestrictionProvider.GetThresholdPeriod(_processingCountry) - 1 : currentLimits.ThresholdPeriod)); /// one for now
                        }
                        if (PurchasingLimits != null)
                        {
                            foreach (var p in PurchasingLimits)
                            {
                                if (p.Value.LimitsRestrictionType == LimitsRestrictionType.FOP)
                                {
                                    p.Value.RemainingVolume = currentLimits.RemainingVolume;
                                    if (placingFirstOrder)
                                    {
                                        p.Value.FirstOrderDate = currentDateTime;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        switch (currentLimits.PurchaseLimitType)
                        {
                        case PurchaseLimitType.Earnings:
                        {
                            currentLimits.RemainingEarnings -= shoppingCart.ProductEarningsInCart;
                            break;
                        }

                        case PurchaseLimitType.Volume:
                        {
                            if (currentLimits.RestrictionPeriod != PurchasingLimitRestrictionPeriod.PerOrder)
                            {
                                currentLimits.RemainingVolume -= HLConfigManager.Configurations.DOConfiguration.UseTotalVolumeToReconciliation ? shoppingCart.ProductPromoVolumeInCart : shoppingCart.ProductVolumeInCart;
                            }
                            break;
                        }

                        case PurchaseLimitType.DiscountedRetail:
                        {
                            currentLimits.RemainingVolume -= shoppingCart.ProductDiscountedRetailInCart;
                            break;
                        }

                        case PurchaseLimitType.TotalPaid:
                        {
                            currentLimits.RemainingVolume -= (shoppingCart.Totals as OrderTotals_V01).AmountDue;
                            break;
                        }
                        }
                    }

                    UpdatePurchasingLimits(currentLimits);
                    // ExpireCache();
                }
            }
            else
            {
                LoggerHelper.Error(
                    string.Format(
                        "PurchaseRestrictionManager.ReconcileAfterPurchase was passed a null cart and couldn't update the cached limits for Distributor: {0}, Country: {1}",
                        distributorId, countryCode));
            }
        }
Beispiel #5
0
        public bool PurchasingLimitsAreExceeded(string distributorId, MyHLShoppingCart cart)
        {
            bool exceeded = false;

            if (cart.OrderCategory == OrderCategoryType.HSO)
            {
                return(exceeded);
            }
            if (CanPurchase)
            {
                // PurchasingLimits_V01 limits = PurchasingLimitProvider.GetCurrentPurchasingLimits(distributorId);
                PurchasingLimits_V01 limits = GetPurchasingLimits(intOrderMonth(OrderMonth.GetCurrentOrderMonth()));
                if (limits == null || cart == null)
                {
                    return(exceeded);
                }

                if (null != cart.Totals && cart.OrderCategory == OrderCategoryType.ETO)
                {
                    return(exceeded);
                }

                if (null != limits && limits.LimitsRestrictionType == LimitsRestrictionType.PurchasingLimits && limits.PurchaseLimitType != PurchaseLimitType.None)
                {
                    switch (limits.PurchaseLimitType)
                    {
                    case PurchaseLimitType.Earnings:
                    {
                        exceeded = limits.NextMaxEarningsLimit > -1 && ((limits.RemainingEarnings - cart.ProductEarningsInCart) < 0);
                        break;
                    }

                    case PurchaseLimitType.Volume:
                    {
                        exceeded = limits.maxVolumeLimit > -1 && ((limits.RemainingVolume - cart.ProductVolumeInCart) < 0);
                        break;
                    }

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

                    case PurchaseLimitType.TotalPaid:
                    {
                        if (null != cart.Totals)
                        {
                            if (APFDueProvider.containsOnlyAPFSku(cart.ShoppingCartItems))
                            {
                                return(exceeded);
                            }

                            exceeded = limits.maxVolumeLimit > -1 && ((limits.RemainingVolume - (cart.Totals as OrderTotals_V01).AmountDue) < 0);
                        }
                        break;
                    }
                    }
                }
                if (null != limits && limits.LimitsRestrictionType != LimitsRestrictionType.PurchasingLimits)
                {
                    exceeded = ((limits.RemainingVolume - cart.VolumeInCart) < 0);
                    if (exceeded)
                    {
                        cart.RuleResults = new List <ShoppingCartRuleResult>();
                        ShoppingCartRuleResult Result = new ShoppingCartRuleResult();
                        Result.RuleName = "PurchaseRestriction Rules";
                        Result.Result   = RulesResult.Failure;
                        Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject(
                                                            string.Format("{0}_Rules", HLConfigManager.Platform),
                                                            "FOPVolumePointExceedsOnCheckout").ToString(), 1100, PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP(_processingCountry), PurchaseRestrictionProvider.GetThresholdPeriod(_processingCountry), cart.VolumeInCart - limits.RemainingVolume));
                        cart.RuleResults.Add(Result);
                    }
                }
                else if (exceeded)
                {
                    cart.RuleResults = new List <ShoppingCartRuleResult>();
                    ShoppingCartRuleResult Result = new ShoppingCartRuleResult();
                    Result.RuleName = "PurchaseRestriction Rules";
                    Result.Result   = RulesResult.Failure;
                    Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject(
                                                        string.Format("{0}_Rules", HLConfigManager.Platform),
                                                        "RemainingVolumePointExceeds").ToString(), (cart.VolumeInCart - limits.RemainingVolume)));
                    cart.RuleResults.Add(Result);
                }
            }
            else  //member can't purchase
            {
                if ((cart.Totals as OrderTotals_V01).AmountDue > 0) //can't purchase and there are items in cart
                {
                    exceeded         = true;
                    cart.RuleResults = new List <ShoppingCartRuleResult>();
                    ShoppingCartRuleResult Result = new ShoppingCartRuleResult();
                    Result.RuleName = "PurchaseRestriction Rules";
                    Result.Result   = RulesResult.Failure;
                    Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject(
                                                        string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                                        "CantBuy").ToString(), 1100, cart.DistributorID));
                    cart.RuleResults.Add(Result);
                }
            }
            return(exceeded);
        }