예제 #1
0
        public void Page_Load(object sender, EventArgs e)
        {
            (Page.Master as OrderingMaster).EventBus.RegisterObject(this);
            _cart        = (Page as ProductsBase).ShoppingCart;
            _APFExempted = APFDueProvider.IsAPFExemptOn200VP(DistributorOrderingProfile, _cart.VolumeInCart);
            Visible      = APFDueProvider.ShouldShowAPFModule(DistributorID);

            if (DistributorOrderingProfile.IsPC || SessionInfo.IsReplacedPcOrder || ShoppingCart.OrderCategory == OrderCategoryType.ETO)
            {
                Visible = false;
                return;
            }

            _APFStatus = DistributorOrderingProfile.CNAPFStatus;

            if (_APFStatus == 2 && Visible)
            {
                pnlAPFIsDueWithinThreeMonth.Visible = false;
                pnlAPFPaid.Visible = false;
                ReadFromPage();
                GracePeriodAPFDisplay();
            }
            else //Legacy handling
            {
                Visible = APFDueProvider.ShouldShowAPFModule(DistributorID);

                if (Visible)
                {
                    pnlAPFIsDueWithinThreeMonth.Visible = false;
                    pnlAPFPaid.Visible = false;
                    ReadFromPage();
                    DisplayData();
                }
            }
        }
예제 #2
0
        public void APFExempt_distributor_Qualified_wfDecimal()
        {
            distributor.DistributorVolumes[0].Volume = Decimal.Parse("200.1");
            bool    result;
            decimal volume = 0;

            result = APFDueProvider.IsAPFExemptOn200VP(distributor, volume);
            Assert.IsTrue(result);

            PrivateObject apf = new PrivateObject(typeof(APFRules));

            result = Convert.ToBoolean(apf.Invoke("IsAPFExempt", distributor, volume));
            Assert.IsTrue(result);
        }
예제 #3
0
        public void APFExempt_distributor_Qualified()
        {
            bool    result;
            decimal volume = 0;

            result = APFDueProvider.IsAPFExemptOn200VP(distributor, 0);
            Assert.IsTrue(result);

            PrivateObject apf = new PrivateObject(typeof(APFRules));

            result = Convert.ToBoolean(apf.Invoke("IsAPFExempt", distributor, volume));

            Assert.IsTrue(result);
        }
예제 #4
0
        public void APFExempt_distributor_notQualified_Wf_Additional_Volume()
        {
            distributor.DistributorVolumes[0].Volume = 150;
            bool    result;
            decimal volume = decimal.Parse("49.999");

            result = APFDueProvider.IsAPFExemptOn200VP(distributor, volume);
            Assert.IsFalse(result);

            PrivateObject apf = new PrivateObject(typeof(APFRules));

            result = Convert.ToBoolean(apf.Invoke("IsAPFExempt", distributor, volume));

            Assert.IsFalse(result);
        }
예제 #5
0
        public void APFExempt_distributor_null()
        {
            distributor = null;
            decimal volume = 0;
            bool    result;

            result = APFDueProvider.IsAPFExemptOn200VP(distributor, 0);
            Assert.IsFalse(result);

            PrivateObject apf = new PrivateObject(typeof(APFRules));

            object[] args = new object[2] {
                distributor, volume
            };
            result = Convert.ToBoolean(apf.Invoke("IsAPFExempt", distributor, volume));
            Assert.IsFalse(result);
        }
예제 #6
0
        public void GracePeriodAPFDisplay()
        {
            _apfSku = APFDueProvider.GetAPFSku();
            List <ShoppingCartItem_V01> item = (from c in _cart.CartItems where c.SKU == _apfSku select c).ToList();

            _APFExempted = APFDueProvider.IsAPFExemptOn200VP(DistributorOrderingProfile, _cart.VolumeInCart);

            if (_APFStatus != 2)
            {
                return;
            }

            if (_APFExempted)
            {
                pnlAPFPaid.Visible = false;
            }

            if (item.Count >= 1)
            {
                ShowApfAddedMessage();
            }
            else
            {
                var apfSku = new List <ShoppingCartItem_V01>();


                if (!_APFExempted)
                {
                    if (_quantityToAdd < 1)
                    {
                        _quantityToAdd = 1;
                    }
                    apfSku.Add(new ShoppingCartItem_V01(0, APFDueProvider.GetAPFSku(), _quantityToAdd, DateTime.Now));
                    _cart.AddItemsToCart(apfSku);
                }


                item = (from c in _cart.CartItems where c.SKU == _apfSku select c).ToList();
                if (item.Count >= 1)
                {
                    ShowApfAddedMessage();
                }
            }
        }
예제 #7
0
        /// <summary>Distributor is APF Due, add APF to the cart</summary>
        /// <param name="distributorID"></param>
        /// <param name="result"></param>
        /// <param name="cacheKey"></param>
        /// <param name="locale"></param>
        /// <param name="cartHasItems"></param>
        /// <param name="ruleResult"></param>
        private void DoApfDue(string distributorID,
                              ShoppingCart_V01 result,
                              string cacheKey,
                              string locale,
                              bool cartHasItems,
                              ShoppingCartRuleResult ruleResult,
                              bool justEntered)
        {
            var cart = result as MyHLShoppingCart;

            if (cart == null)
            {
                return;
            }

            try
            {
                string level;
                if (DistributorProfileModel != null)
                {
                    level = DistributorProfileModel.TypeCode.ToUpper();
                }
                else
                {
                    level = GetMemberLevelFromDistributorProfile(cart.DistributorID);
                }

                var distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(cart.DistributorID,
                                                                                               cart.CountryCode);
                if ((distributorOrderingProfile.HardCashOnly &&
                     !HLConfigManager.Configurations.PaymentsConfiguration.AllowWireForHardCash))
                {
                    return;
                }
                var apfItems = new List <ShoppingCartItem_V01>();
                if (cart.CartItems != null && cart.CartItems.Count > 0)
                {
                    //Stash off all non-APF items - to be re-added if appropriate
                    var nonApfItems =
                        (from c in cart.CartItems where APFDueProvider.IsAPFSku(c.SKU.Trim()) == false select c)
                        .ToList <ShoppingCartItem_V01>();
                    apfItems =
                        (from c in cart.CartItems where APFDueProvider.IsAPFSku(c.SKU.Trim()) select c)
                        .ToList <ShoppingCartItem_V01>();
                    if (nonApfItems.Count > 0 ||
                        HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
                    {
                        // Clear the cart
                        cart.DeleteItemsFromCart(null, true);
                        //if (APFDueProvider.CanEditAPFOrder(distributorID, locale, level))
                        //{
                        //Global rule - they can always edit the cart ie add remove products at least
                        var list =
                            CatalogProvider.GetCatalogItems((from p in nonApfItems select p.SKU).ToList(), Country);
                        var products =
                            (from c in list where c.Value.ProductType == ProductType.Product select c.Value.SKU).ToList();
                        var nonproducts =
                            (from c in list where c.Value.ProductType != ProductType.Product select c.Value.SKU).ToList();
                        if (!HLConfigManager.Configurations.APFConfiguration.AllowNonProductItemsWithStandaloneAPF)
                        //We don't allow non product items alone on an apf order
                        {
                            if (products.Count == 0)
                            {
                                if (nonproducts.Count > 0)
                                {
                                    ruleResult.Result = RulesResult.Success;
                                    ruleResult.AddMessage(
                                        HttpContext.GetGlobalResourceObject(
                                            string.Format("{0}_ErrorMessage", HLConfigManager.Platform),
                                            "NonProductItemsRemovedForStandaloneAPF") as string);
                                    cart.RuleResults.Add(ruleResult);
                                }
                            }
                            else
                            {
                                cart.AddItemsToCart(nonApfItems, true);
                            }
                        }
                        else
                        {
                            if (!HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed)
                            {
                                cart.AddItemsToCart(nonApfItems, true);
                            }
                        }
                    }
                }
                else if (null != cart && null != cart.RuleResults)
                {
                    var rules =
                        (from rule in cart.RuleResults
                         where rule.RuleName == RuleName && rule.Result == RulesResult.Failure
                         select rule);
                    if (null != rules && rules.Count() > 0)
                    {
                        cart.RuleResults.Remove(rules.First());
                    }
                }

                //Add the APF in
                var apfSku = new List <ShoppingCartItem_V01>();
                var sku    = APFDueProvider.GetAPFSku();
                //apfSku.Add(new ShoppingCartItem_V01(0, sku, 1, DateTime.Now));
                bool hasPreOrdering = false;

                //if (apfItems.Count > 0) cart.removeItem(sku);
                var datenow = DateTime.Now; // new DateTime(2015, 9, 17, 12, 0, 0); //(DateTime.Now).Date
                if (HLConfigManager.Configurations.DOConfiguration.IsChina && distributorOrderingProfile.CNAPFStatus == 2)
                {
                    if (!APFDueProvider.IsAPFExemptOn200VP(distributorOrderingProfile, cart.VolumeInCart))
                    {
                        apfSku.Add(new ShoppingCartItem_V01(0, sku, 1, DateTime.Now));
                    }
                    else
                    {
                        cart.removeItem(sku);
                    }
                }
                else
                {
                    apfSku.Add(new ShoppingCartItem_V01(0, sku, 1, DateTime.Now));
                };

                #region !cart.APFEdited
                if (!cart.APFEdited)
                {
                    if (HLConfigManager.Configurations.DOConfiguration.IsChina)
                    {
                        if (cart.CartItems != null && cart.CartItems.Count > 0 && cart.DeliveryInfo != null)
                        {
                            hasPreOrdering = CatalogProvider.IsPreordering(cart.CartItems, cart.DeliveryInfo.WarehouseCode);
                        }

                        if (!hasPreOrdering)
                        {
                            if (cart.CurrentItems != null && cart.CurrentItems.Count > 0 && cart.DeliveryInfo != null)
                            {
                                hasPreOrdering = CatalogProvider.IsPreordering(cart.CurrentItems, cart.DeliveryInfo.WarehouseCode);
                            }
                        }
                    }

                    if (!hasPreOrdering)
                    {
                        if (apfSku.Count > 0)
                        {
                            apfSku[0].Quantity = CalcQuantity(distributorOrderingProfile.ApfDueDate);
                        }

                        if (apfSku.Count > 0 && cart.CartItems.Exists(c => c.SKU == apfSku[0].SKU))
                        {
                            var apf =
                                (from a in cart.CartItems where a.SKU == apfSku[0].SKU select a).First();
                            cart.DeleteItemsFromCart(
                                (from a in cart.CartItems where a.SKU == apfSku[0].SKU select a.SKU).ToList(), true);
                        }
                        if (cart.CartItems.Count == 0) //This is now a Standalone APF
                        {
                            SetAPFDeliveryOption(cart);
                        }

                        if (apfSku.Count > 0)
                        {
                            cart.AddItemsToCart(apfSku, true);
                        }

                        if (justEntered && apfSku.Count > 0)
                        {
                            ruleResult.AddMessage(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "APFDueAdded") as string);
                            ruleResult.Result = RulesResult.Success;

                            SetApfRuleResponse(ruleResult, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF,
                                               "APFDueAdded");

                            cart.RuleResults.Add(ruleResult);
                        }
                        else
                        {
                            foreach (ShoppingCartRuleResult r in cart.RuleResults)
                            {
                                if (r.RuleName == RuleName)
                                {
                                    r.Messages.Clear();
                                    r.AddMessage(string.Empty);
                                }
                            }
                        }
                    }
                }
                #endregion
                //else
                //{
                //    if (APFDueProvider.CanRemoveAPF(distributorID, locale, level))
                //    {
                //        cart.AddItemsToCart(apfSku, true);
                //    }
                //}
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("doAPFDue DS:{0} ERR:{1}", distributorID, ex));
            }
        }