예제 #1
0
        public IEnumerable <Items> GetItemList(int orderId)
        {
            List <Items> items     = new List <Items>();
            OrderData    orderData = new OrderData(orderId);

            var info = orderData.PurchaseInfo.XMLDoc.SelectNodes("genxml/items/*");

            foreach (XmlNode xml in info)
            {
                var newInfo = new NBrightInfo
                {
                    XMLData = xml.OuterXml
                };

                items.Add(new Items
                {
                    ProductName  = newInfo.GetXmlProperty("genxml/productname"),
                    Qty          = newInfo.GetXmlPropertyInt("genxml/qty"),
                    Model        = newInfo.GetXmlProperty("genxml/taxratecode"),
                    ProductPrice = Convert.ToDecimal(newInfo.GetXmlPropertyDouble("genxml/appliedcost")),
                    ProductTotal = Convert.ToDecimal(newInfo.GetXmlPropertyDouble("genxml/appliedtotalcost"))
                });
            }
            return(items);
        }
예제 #2
0
        public Double CalculateItemTax(NBrightInfo cartItemInfo, Dictionary <string, double> rateDic)
        {
            if (_taxType == "3")
            {
                return(0);
            }

            if (!rateDic.Any())
            {
                return(0);
            }

            // loop through each item and calc the tax for each.
            Double taxtotal = 0;

            var appliedcost = cartItemInfo.GetXmlPropertyDouble("genxml/appliedcost");

            // check if dealer and if dealertotal cost exists. ()
            if (cartItemInfo.GetXmlPropertyBool("genxml/isdealer"))
            {
                appliedcost = cartItemInfo.GetXmlPropertyDouble("genxml/dealercost");
            }

            var taxrate = GetTaxRate(cartItemInfo, rateDic);

            taxtotal = AddTaxCost(taxtotal, appliedcost, taxrate);

            return(Math.Round(taxtotal, 2));
        }
예제 #3
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            var    shipData   = new ShippingData(Shippingkey);
            var    shipoption = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/rblshippingoptions");
            Double rangeValue = 0;

            if (shipData.CalculationUnit == "1")
            {
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/totalweight");
            }
            else
            {
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            }
            var countrycode = "";
            var regioncode  = "";
            var regionkey   = "";
            var postCode    = "";
            var total       = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");

            switch (shipoption)
            {
            case "1":
                countrycode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                regionkey   = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                postCode    = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/postalcode");
                break;

            case "2":
                countrycode = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/country");
                regionkey   = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/region");
                postCode    = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/textbox/postalcode");
                break;
            }

            var shippingcost = shipData.CalculateShippingByPC(postCode, rangeValue, total);

            if (shippingcost == -1)
            {
                if (regionkey != "")
                {
                    var rl = regionkey.Split(':');
                    if (rl.Count() == 2)
                    {
                        regioncode = rl[1];
                    }
                }
                shippingcost = shipData.CalculateShipping(countrycode, regioncode, rangeValue, total);
            }
            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
예제 #4
0
        public override Double CalculateItemTax(NBrightInfo cartItemInfo)
        {
            var info    = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3")
            {
                return(0);
            }

            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(0);
            }

            // loop through each item and calc the tax for each.
            Double taxtotal = 0;

            var totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totalcost");

            // check if dealer and if dealertotal cost exists. ()
            if (cartItemInfo.GetXmlPropertyBool("genxml/isdealer"))
            {
                totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/dealercost");
            }
            var taxratecode = cartItemInfo.GetXmlProperty("genxml/taxratecode");

            if (!Utils.IsNumeric(taxratecode))
            {
                taxratecode = "0";
            }
            if (!rateDic.ContainsKey(taxratecode))
            {
                taxratecode = "0";
            }
            Double taxrate = 0;

            if (rateDic.ContainsKey(taxratecode))
            {
                taxrate = rateDic[taxratecode]; // Can happen is no default tax added.
            }
            if (taxtype == "1")                 // included in unit price
            {
                taxtotal += totalcost - ((totalcost / (100 + taxrate)) * 100);
            }
            if (taxtype == "2") // NOT included in unit price
            {
                taxtotal += (totalcost / 100) * taxrate;
            }

            return(Math.Round(taxtotal, 2));
        }
예제 #5
0
        public override NBrightInfo CalculateItemPercentDiscount(int portalId, int userId, NBrightInfo cartItemInfo,String discountcode)
        {
            if (userId <= 0) return cartItemInfo;
            cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0"); // reset discount amount
            if (discountcode == "") return cartItemInfo;
            var clientData = new ClientData(portalId,userId);
            if (clientData.DiscountCodes.Count == 0) return cartItemInfo;

            Double discountcodeamt = 0;
            foreach (var d in clientData.DiscountCodes)
            {
                var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                var validutildate = DateTime.Today;
                if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                {
                    var usageleft = d.GetXmlPropertyDouble("genxml/textbox/usageleft");
                    var percentage = d.GetXmlPropertyDouble("genxml/textbox/percentage");
                    if (percentage > 0 && usageleft > 0)
                    {
                        var appliedtotalcost = cartItemInfo.GetXmlPropertyDouble("genxml/appliedtotalcost");
                        discountcodeamt = ((appliedtotalcost/100)*percentage);
                    }
                }
                if (discountcodeamt > 0) break;
            }
            cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", discountcodeamt);

            return cartItemInfo;
        }
 public override bool IsValid(NBrightInfo cartInfo)
 {
     if (cartInfo.GetXmlPropertyDouble("genxml/totalweight") <= 99)
     {
         return(true);
     }
     return(false);
 }
예제 #7
0
        public Double CalculateDiscount(String discountCode)
        {
            // calc if we have free shipping limit
            var freeShipAmt  = Info.GetXmlPropertyDouble("genxml/textbox/freeshiplimit");
            var freeShipRefs = Info.GetXmlProperty("genxml/textbox/freeshipcountrycodes");

            return(0);
        }
예제 #8
0
        /// <summary>
        /// Get the cookie data from the client.
        /// </summary>
        /// <returns></returns>
        public NavigationData Get(string tempfilename = "")
        {
            ClearData();

            if (tempfilename == "")
            {
                if (_storageType == DataStorageType.SessionMemory)
                {
                    if (HttpContext.Current.Session[_cookieName + "tempname"] != null) tempfilename = (String)HttpContext.Current.Session[_cookieName + "tempname"];
                }
                else
                {
                    tempfilename = Cookie.GetCookieValue(_portalId, _cookieName, "tempname", "");
                }
            }

            XmlData = "";

            if (tempfilename != "")
            {
                var filePath = StoreSettings.Current.FolderTempMapPath + "\\" + tempfilename;
                if (File.Exists(filePath)) XmlData = Utils.ReadFile(filePath);
                var nbi = new NBrightInfo();
                nbi.XMLData = XmlData;

                _criteria = nbi.GetXmlProperty("genxml/Criteria");
                PageModuleId = nbi.GetXmlProperty("genxml/PageModuleId");
                PageNumber = nbi.GetXmlProperty("genxml/PageNumber");
                PageName = nbi.GetXmlProperty("genxml/PageName");
                PageSize = nbi.GetXmlProperty("genxml/PageSize");
                OrderBy = nbi.GetXmlProperty("genxml/OrderBy");
                CategoryId = Convert.ToInt32(nbi.GetXmlPropertyDouble("genxml/CategoryId"));
                RecordCount = nbi.GetXmlProperty("genxml/RecordCount");
                Mode = nbi.GetXmlProperty("genxml/Mode");
                OrderByIdx = nbi.GetXmlProperty("genxml/OrderByIdx");
                SearchFormData = nbi.GetXmlNode("genxml/SearchFormData").ToString();
                FilterPropertyList = nbi.GetXmlProperty("genxml/FilterPropertyList");

                _filterPropertiesByProduct = new List<int>();
                var filterCSV = nbi.GetXmlProperty("genxml/filterpropertycsv");
                foreach (var f in filterCSV.Split(','))
                {
                    if (Utils.IsNumeric(f))
                    {
                        AddPropertyFilter(Convert.ToInt32(f));
                    }
                }
            }

            if (_criteria == "" && XmlData == "") // "Exist" property not used for paging data
                Exists = false;
            else
                Exists = true;

            return this;
        }
예제 #9
0
        /// <summary>
        /// Get the cookie data from the client.
        /// </summary>
        /// <returns></returns>
        public NavigationData Get(string tempfilename = "")
        {
            ClearData();

            if (tempfilename == "")
            {
                if (_storageType == DataStorageType.SessionMemory)
                {
                    if (HttpContext.Current.Session[_cookieName + "tempname"] != null)
                    {
                        tempfilename = (String)HttpContext.Current.Session[_cookieName + "tempname"];
                    }
                }
                else
                {
                    tempfilename = Cookie.GetCookieValue(_portalId, _cookieName, "tempname", "");
                }
            }

            XmlData = "";

            if (tempfilename != "")
            {
                var filePath = StoreSettings.Current.FolderTempMapPath + "\\" + tempfilename;
                if (File.Exists(filePath))
                {
                    XmlData = Utils.ReadFile(filePath);
                }
                var nbi = new NBrightInfo();
                nbi.XMLData = XmlData;

                _criteria      = nbi.GetXmlProperty("genxml/Criteria");
                PageModuleId   = nbi.GetXmlProperty("genxml/PageModuleId");
                PageNumber     = nbi.GetXmlProperty("genxml/PageNumber");
                PageName       = nbi.GetXmlProperty("genxml/PageName");
                PageSize       = nbi.GetXmlProperty("genxml/PageSize");
                OrderBy        = nbi.GetXmlProperty("genxml/OrderBy");
                CategoryId     = Convert.ToInt32(nbi.GetXmlPropertyDouble("genxml/CategoryId"));
                RecordCount    = nbi.GetXmlProperty("genxml/RecordCount");
                Mode           = nbi.GetXmlProperty("genxml/Mode");
                OrderByIdx     = nbi.GetXmlProperty("genxml/OrderByIdx");
                SearchFormData = nbi.GetXmlNode("genxml/SearchFormData").ToString();
            }

            if (_criteria == "" && XmlData == "") // "Exist" property not used for paging data
            {
                Exists = false;
            }
            else
            {
                Exists = true;
            }

            return(this);
        }
예제 #10
0
        private static Double GetCurrentPromoPrice(NBrightInfo prdData, int whichprice, int modIndex)
        {
            switch (whichprice)
            {
            case 1:
                return(prdData.GetXmlPropertyDouble("genxml/models/genxml[" + modIndex + "]/textbox/txtsaleprice"));

            case 2:
                return(prdData.GetXmlPropertyDouble("genxml/models/genxml[" + modIndex + "]/textbox/txtdealercost"));

            case 3:
                return(prdData.GetXmlPropertyDouble("genxml/models/genxml[" + modIndex + "]/textbox/txtdealersale"));

            case 4:
                return(prdData.GetXmlPropertyDouble("genxml/models/genxml[" + modIndex + "]/textbox/txtdealersale"));

            default:
                return(prdData.GetXmlPropertyDouble("genxml/models/genxml[" + modIndex + "]/textbox/txtsaleprice"));
            }
        }
예제 #11
0
 public static NBrightInfo UpdateItemPercentDiscountCode(int portalId, int userId, NBrightInfo cartItemInfo, String discountcode)
 {
     cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0");
     foreach (var prov in ProviderList)
     {
         var newItemInfo = prov.Value.CalculateItemPercentDiscount(portalId, userId, cartItemInfo, discountcode);
         if (cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt") < newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"))
         {
             cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"));
         }
     }
     return cartItemInfo;
 }
예제 #12
0
        private static Double CalculateShippingTax(NBrightInfo cartInfo, double taxrate, Boolean isDealer)
        {
            if (_taxType == "3")
            {
                return(0);
            }

            Double taxtotal     = 0;
            var    shippingcost = cartInfo.GetXmlPropertyDouble("genxml/shippingcost");

            // check if dealer and if dealer shipping cost exists.
            var dealerShippingCost = cartInfo.GetXmlPropertyDouble("genxml/dealershippingcost");

            if (isDealer && dealerShippingCost > 0)
            {
                shippingcost = dealerShippingCost;
            }

            taxtotal = AddTaxCost(taxtotal, shippingcost, taxrate);

            return(Math.Round(taxtotal, 2));
        }
예제 #13
0
 public static NBrightInfo UpdateItemPercentDiscountCode(int portalId, int userId, NBrightInfo cartItemInfo, String discountcode)
 {
     cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", "0");
     foreach (var prov in ProviderList)
     {
         var newItemInfo = prov.Value.CalculateItemPercentDiscount(portalId, userId, cartItemInfo, discountcode);
         if (cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt") < newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"))
         {
             cartItemInfo.SetXmlPropertyDouble("genxml/discountcodeamt", newItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"));
         }
     }
     return(cartItemInfo);
 }
예제 #14
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            var shipData = new ShippingData(Shippingkey);
            var shipoption = cartInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/rblshippingoptions");
            Double rangeValue = 0;
            if (shipData.CalculationUnit == "1")
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/totalweight");
            else
                rangeValue = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            var countrycode = "";
            var regioncode = "";
            var regionkey = "";
            var total = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
            switch (shipoption)
            {
                case "1":
                    countrycode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                    regionkey = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region");
                    break;
                case "2":
                    countrycode = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/country");
                    regionkey = cartInfo.GetXmlProperty("genxml/shipaddress/genxml/dropdownlist/region");
                    break;
            }

            if (regionkey != "")
            {
                var rl = regionkey.Split(':');
                if (rl.Count() == 2) regioncode = rl[1];
            }

            var shippingcost = shipData.CalculateShipping(countrycode, regioncode, rangeValue, total);
            var shippingdealercost = shippingcost;
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return cartInfo;
        }
예제 #15
0
        private void AlterCost()
        {
            var info     = new NBrightInfo();
            var shipping = new ShippingData(_ctrlkey);

            info.XMLData = GenXmlFunctions.GetGenXml(rpDataH);
            var percentValue = info.GetXmlPropertyDouble("genxml/textbox/alterpercent");

            shipping.UpdateCost(percentValue);
            shipping.Save();

            //remove current setting from cache for reload
            Utils.RemoveCache("NBrightBuyShipping" + PortalSettings.Current.PortalId.ToString(""));
        }
예제 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cartInfo"></param>
        /// <returns></returns>
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            // return zero if we have invalid data
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");
            var modCtrl = new NBrightBuyController();
            var info    = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (info == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }

            if (Merchant.IsEnable && Merchant.Type == "B")
            {
                shippingcost = Merchant.HomeCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }


            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
예제 #17
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");

            NBrightBuyController nbCtrl = new NBrightBuyController();
            NBrightInfo          nbInfo = nbCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (nbInfo == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }


            if (Merchant.IsEnable)
            {
                shippingcost = Merchant.UniMartCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }

            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
예제 #18
0
        public static string CalcGroupPromoItem(NBrightInfo p)
        {
            var objCtrl        = new NBrightBuyController();
            var typeselect     = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid     = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid    = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
            var promoname      = p.GetXmlProperty("genxml/textbox/name");
            var amounttype     = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
            var amount         = p.GetXmlPropertyDouble("genxml/textbox/amount");
            var validfrom      = p.GetXmlProperty("genxml/textbox/validfrom");
            var validuntil     = p.GetXmlProperty("genxml/textbox/validuntil");
            var overwrite      = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
            var disabled       = p.GetXmlPropertyBool("genxml/checkbox/disabled");
            var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated");

            if (!disabled)
            {
                var runcalc = true;
                if (Utils.IsDate(lastcalculated))
                {
                    if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate)
                    {
                        runcalc = false;                                                           // only run if changed
                    }
                    if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1))
                    {
                        runcalc = true;                                                                             // every day just after midnight. (for site performace)
                    }
                }
                if (Utils.IsDate(validuntil))
                {
                    if (DateTime.Now.Date > Convert.ToDateTime(validuntil))
                    {
                        runcalc = true;                                                         // need to disable the promo if passed date
                    }
                }
                if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil))
                {
                    var          dteF = Convert.ToDateTime(validfrom).Date;
                    var          dteU = Convert.ToDateTime(validuntil).Date;
                    CategoryData gCat;
                    var          groupid = catgroupid;
                    if (typeselect != "cat")
                    {
                        groupid = propgroupid;
                    }

                    gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture());
                    var prdList = gCat.GetAllArticles();

                    foreach (var prd in prdList)
                    {
                        if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                        {
                            // CALC Promo
                            CalcProductSalePrice(p.PortalId, prd.ParentItemId, amounttype, amount, promoname, p.ItemID, overwrite, dteF, dteU);
                        }
                        if (DateTime.Now.Date > dteU)
                        {
                            // END Promo
                            RemoveProductPromoData(p.PortalId, prd.ParentItemId, p.ItemID);
                            p.SetXmlProperty("genxml/checkbox/disabled", "True");
                            objCtrl.Update(p);
                        }
                        ProductUtils.RemoveProductDataCache(p.PortalId, prd.ParentItemId);
                    }

                    p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O"));     // Add 10 sec to time so we don't get exact clash with update time.
                    objCtrl.Update(p);
                }
            }
            return("OK");
        }
예제 #19
0
        private static void CalcProductSalePrice(int portalid, int productId, string amounttype, double amount, string promoname, int promoid, bool overwrite, DateTime dteF, DateTime dteU)
        {
            var cultureList = DnnUtils.GetCultureCodeList(portalid);
            var objCtrl     = new NBrightBuyController();
            var prdData     = objCtrl.GetData(productId);

            var nodList = prdData.XMLDoc.SelectNodes("genxml/models/genxml");

            if (nodList != null)
            {
                var currentpromoid = prdData.GetXmlPropertyInt("genxml/hidden/promoid");
                if (currentpromoid == 0 || currentpromoid == promoid || overwrite)
                {
                    prdData.SetXmlProperty("genxml/hidden/promotype", "PROMOGROUP");
                    prdData.SetXmlPropertyDouble("genxml/hidden/promoname", promoname);
                    prdData.SetXmlProperty("genxml/hidden/promoid", promoid.ToString());
                    prdData.SetXmlProperty("genxml/hidden/promocalcdate", DateTime.Now.ToString("O"));
                    prdData.SetXmlProperty("genxml/hidden/datefrom", dteF.ToString("O"));
                    prdData.SetXmlProperty("genxml/hidden/dateuntil", dteU.ToString("O"));

                    var lp = 1;
                    foreach (XmlNode nod in nodList)
                    {
                        var nbi = new NBrightInfo();
                        nbi.XMLData = nod.OuterXml;
                        var    unitcost = nbi.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
                        Double newamt   = 0;
                        if (amounttype == "1")
                        {
                            newamt = unitcost - amount;
                        }
                        else
                        {
                            newamt = unitcost - ((unitcost / 100) * amount);
                        }

                        if (newamt < 0)
                        {
                            newamt = 0;
                        }

                        var currentprice = prdData.GetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice");

                        if (!overwrite)
                        {
                            if (currentprice == 0)
                            {
                                overwrite = true;
                            }
                            if (currentpromoid == promoid)
                            {
                                overwrite = true;
                            }
                        }
                        if (overwrite)
                        {
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt);
                        }
                        lp += 1;
                    }
                    objCtrl.Update(prdData);

                    foreach (var lang in cultureList)
                    {
                        var p           = objCtrl.GetDataLang(promoid, lang);
                        var prdDataLang = objCtrl.GetDataLang(productId, lang);
                        if (prdDataLang != null)
                        {
                            prdDataLang.SetXmlProperty("genxml/hidden/promodesc", p.GetXmlProperty("genxml/textbox/description"));
                            objCtrl.Update(prdDataLang);
                        }
                    }
                }
            }
        }
예제 #20
0
        private NBrightInfo ValidateCartItem(int portalId, int userId, NBrightInfo cartItemInfo)
        {
            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemBefore, cartItemInfo);

            var modelid = cartItemInfo.GetXmlProperty("genxml/modelid");
            var prdid = cartItemInfo.GetXmlPropertyInt("genxml/productid");
            var qty = cartItemInfo.GetXmlPropertyDouble("genxml/qty");

            var prd = ProductUtils.GetProductData(prdid, Utils.GetCurrentCulture());
            if (!prd.Exists || prd.Disabled) return null; //Invalid product remove from cart
            var prdModel = prd.GetModel(modelid);
            if (prdModel == null) return null; // Invalid Model remove from cart
            // check if dealer (for tax calc)
            var userInfo = UserController.GetUserById(portalId, userId);
            if (userInfo != null && userInfo.IsInRole(StoreSettings.DealerRole) && StoreSettings.Current.Get("enabledealer") == "True")
                cartItemInfo.SetXmlProperty("genxml/isdealer", "True");
            else
                cartItemInfo.SetXmlProperty("genxml/isdealer", "False");

            // check for price change
            var unitcost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
            var dealercost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
            var saleprice = prdModel.GetXmlPropertyDouble("genxml/textbox/txtsaleprice");

            // calc sale price
            var sellcost = unitcost;
            if (saleprice > 0 && saleprice < sellcost) sellcost = saleprice;

            //stock control
            if (prdModel != null)
            {
                var stockon = prdModel.GetXmlPropertyBool("genxml/checkbox/chkstockon");
                var stocklevel = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining");
                var minStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyminstock");
                if (minStock == 0) minStock = StoreSettings.Current.GetInt("minimumstocklevel");
                var maxStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtystockset");
                var weight = prdModel.GetXmlPropertyDouble("genxml/textbox/weight");
                if (stockon)
                {
                    stocklevel = stocklevel - minStock;
                    stocklevel = stocklevel - prd.GetModelTransQty(modelid, _cartId);
                    if (stocklevel < qty)
                    {
                        qty = stocklevel;
                        if (qty <= 0)
                        {
                            qty = 0;
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "OUTOFSTOCK");
                        }
                        else
                        {
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "STOCKADJ");
                        }
                        base.SetValidated(false);
                        cartItemInfo.SetXmlPropertyDouble("genxml/qty", qty.ToString(""));
                    }
                }

                Double additionalCosts = 0;
                var optNods = cartItemInfo.XMLDoc.SelectNodes("genxml/options/*");
                if (optNods != null)
                {
                    var lp = 1;
                    foreach (XmlNode nod in optNods)
                    {
                        var optid = nod.SelectSingleNode("optid");
                        if (optid != null)
                        {
                            var optvalueid = nod.SelectSingleNode("optvalueid");
                            if (optvalueid != null && optvalueid.InnerText != "False")
                            {
                                XmlNode  optvalcostnod;
                                if (optvalueid.InnerText == "True")
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues[@optionid='" + optid.InnerText + "']/genxml/textbox/txtaddedcost");
                                else
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues/genxml[./hidden/optionvalueid='" + optvalueid.InnerText + "']/textbox/txtaddedcost");

                                if (optvalcostnod != null)
                                {
                                    var optvalcost = optvalcostnod.InnerText;
                                    if (Utils.IsNumeric(optvalcost))
                                    {
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", optvalcost);
                                        var optvaltotal = Convert.ToDouble(optvalcost, CultureInfo.GetCultureInfo("en-US"))*qty;
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", optvaltotal);
                                        additionalCosts += optvaltotal;
                                    }
                                }
                                else
                                {
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", "0");
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", "0");
                                }
                            }
                        }
                        lp += 1;
                    }
                }

                if (qty > 0)  // can't devide by zero
                {
                    unitcost += (additionalCosts / qty);
                    if (dealercost > 0) dealercost += (additionalCosts / qty); // zero turns off
                    if (saleprice > 0) saleprice += (additionalCosts / qty); // zero turns off
                    sellcost += (additionalCosts / qty);
                }

                var totalcost = qty * sellcost;
                var totaldealercost = qty * dealercost;
                var totalweight = weight * qty;

                if (unitcost != cartItemInfo.GetXmlPropertyDouble("genxml/unitcost") || dealercost != cartItemInfo.GetXmlPropertyDouble("genxml/dealercost") || saleprice != cartItemInfo.GetXmlPropertyDouble("genxml/saleprice"))
                {
                    cartItemInfo.SetXmlPropertyDouble("genxml/unitcost", unitcost);
                    cartItemInfo.SetXmlPropertyDouble("genxml/dealercost", dealercost);
                    cartItemInfo.SetXmlPropertyDouble("genxml/saleprice", saleprice);
                    cartItemInfo.RemoveXmlNode("genxml/productxml");
                    cartItemInfo.AddSingleNode("productxml", prd.Info.XMLData, "genxml");
                }

                cartItemInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight.ToString(""));
                cartItemInfo.SetXmlPropertyDouble("genxml/totalcost", totalcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealercost", totaldealercost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", (totalcost - totaldealercost));

                Double salediscount = 0;
                Double dealerdiscount = 0;
                Double discountcodeamt = 0;
                Double totaldiscount = 0;

                //add update genxml/discountcodeamt
                if (saleprice == 0) // discount codes are only valid for items not on sale
                {
                    var discountcode = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
                    cartItemInfo = DiscountCodeInterface.UpdateItemPercentDiscountCode(PortalId, UserId, cartItemInfo, discountcode);
                    discountcodeamt = cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt");
                    if (discountcodeamt > 0) PurchaseInfo.SetXmlProperty("genxml/discountprocessed", "False");
                    totaldiscount = discountcodeamt;
                }
                else
                {
                    salediscount = (unitcost - saleprice);
                    totaldiscount = salediscount * qty;
                }

                var totalsalediscount = salediscount * qty;
                var totaldealerdiscount = dealerdiscount * qty;
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);
                cartItemInfo.SetXmlPropertyDouble("genxml/salediscount", totalsalediscount);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerdiscount", totaldealerdiscount);

                cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", AppliedCost(portalId, userId, totalcost, totaldealercost));
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedcost", AppliedCost(portalId, userId, sellcost, dealercost));

                // calc tax for item
                var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/hidden/taxproviderkey");
                var taxprov = TaxInterface.Instance(taxproviderkey);
                if (taxprov != null)
                {
                    var nbi = (NBrightInfo)cartItemInfo.Clone();
                    cartItemInfo.SetXmlPropertyDouble("genxml/taxcost", taxprov.CalculateItemTax(nbi));
                }

            }

            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemAfter, cartItemInfo);

            return cartItemInfo;
        }
예제 #21
0
        public override NBrightInfo Calculate(NBrightInfo cartInfo)
        {
            var enableShippingTax = _info.GetXmlPropertyBool("genxml/checkbox/enableshippingtax");
            var shippingTaxRate   = _info.GetXmlPropertyDouble("genxml/textbox/shippingtaxrate");

            // return taxtype, 1 = included in cost, 2 = not included in cost, 3 = no tax, 4 = tax included in cost, but calculate to zero.
            cartInfo.SetXmlPropertyDouble("genxml/taxtype", _taxType);

            if (_taxType == "3" || _taxType == "4") // no tax calculation
            {
                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                return(cartInfo);
            }


            var rateDic = GetRates();

            if (!rateDic.Any())
            {
                return(cartInfo);
            }

            // loop through each item and calc the tax for each.
            var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*");

            if (nodList != null)
            {
                Double taxtotal = 0;

                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    taxtotal   += CalculateItemTax(nbi, rateDic);
                }

                if (enableShippingTax && shippingTaxRate > 0)
                {
                    var isDealer = false; // default until dealer shipping cost implemented
                    taxtotal += CalculateShippingTax(cartInfo, shippingTaxRate, isDealer);
                }

                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal);
                if (_taxType == "1")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);                  // tax already in total, so don't apply any more tax.
                }
                if (_taxType == "2")
                {
                    cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal);
                }


                var taxcountry            = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country");
                var storecountry          = StoreSettings.Current.Get("storecountry");
                var valideutaxcountrycode = _info.GetXmlProperty("genxml/textbox/valideutaxcountrycode");
                var isvalidEU             = false;
                valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ",";
                if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ",")))
                {
                    isvalidEU = true;
                }

                // Check for EU tax number.
                var enabletaxnumber = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber");
                if (enabletaxnumber)
                {
                    var taxnumber = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/taxnumber").Trim();
                    if (storecountry != taxcountry && taxnumber != "")
                    {
                        // not matching merchant country, so remove tax
                        if (_taxType == "1")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                        }
                        if (_taxType == "2")
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                            cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                        }
                    }
                }

                // Check for country.
                var enabletaxcountry = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry");
                if (enabletaxcountry)
                {
                    if (taxcountry != "")
                    {
                        if (taxcountry != storecountry && !isvalidEU)
                        {
                            // not matching merchant country, so remove tax
                            if (_taxType == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (_taxType == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }

                // check for region exempt (in same country)
                var taxexemptregions = _info.GetXmlProperty("genxml/textbox/taxexemptregions");
                if (taxexemptregions != "" && taxcountry == storecountry)
                {
                    taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ", "") + ",";
                    var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region").Trim();
                    if (taxregioncode == "")
                    {
                        taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion").Trim();
                    }
                    if (taxregioncode != "")
                    {
                        if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ","))
                        {
                            // not matching merchant region, so remove tax
                            if (_taxType == "1")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1);
                            }
                            if (_taxType == "2")
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0);
                                cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0);
                            }
                        }
                    }
                }
            }


            return(cartInfo);
        }
예제 #22
0
        public static NBrightInfo CalcQtyPromoItem(NBrightInfo p, NBrightInfo cartItemInfo)
        {
            var objCtrl     = new NBrightBuyController();
            var typeselect  = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid  = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
            var promoname   = p.GetXmlProperty("genxml/textbox/name");
            var amounttype  = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
            var amount      = p.GetXmlPropertyDouble("genxml/textbox/amount");
            var overwrite   = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
            var disabled    = p.GetXmlPropertyBool("genxml/checkbox/disabled");
            var rangeList   = p.GetXmlProperty("genxml/textbox/range");

            if (!disabled)
            {
                var productid = cartItemInfo.GetXmlPropertyInt("genxml/productid");

                if (productid > 0)
                {
                    var prodData = new ProductData(productid, Utils.GetCurrentCulture());
                    if (prodData.Exists)
                    {
                        var groupid = catgroupid;
                        if (typeselect == "prop")
                        {
                            groupid = propgroupid;
                        }
                        var gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture());
                        if (gCat == null)
                        {
                            return(cartItemInfo);
                        }

                        if (prodData.HasProperty(gCat.CategoryRef) || prodData.IsInCategory(gCat.CategoryRef))
                        {
                            var runcalc = true;
                            // build range Data
                            var rangeData = new List <RangeItem>();
                            var rl        = rangeList.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var s in rl)
                            {
                                var ri = s.Split('=');
                                if (ri.Count() == 2 && Utils.IsNumeric(ri[1]))
                                {
                                    var riV = ri[0].Split('-');
                                    if (riV.Count() == 2 && Utils.IsNumeric(riV[0]) && Utils.IsNumeric(riV[1]))
                                    {
                                        var rItem = new RangeItem();
                                        rItem.RangeLow  = Convert.ToDouble(riV[0], CultureInfo.GetCultureInfo("en-US"));
                                        rItem.Cost      = Convert.ToDouble(ri[1], CultureInfo.GetCultureInfo("en-US"));
                                        rItem.RangeHigh = Convert.ToDouble(riV[1], CultureInfo.GetCultureInfo("en-US"));
                                        rangeData.Add(rItem);
                                    }
                                }
                            }

                            var unitcost   = cartItemInfo.GetXmlPropertyDouble("genxml/unitcost");
                            var promoprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice");
                            var rangeValue = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
                            var basecost   = unitcost;

                            foreach (var i in rangeData)
                            {
                                if (rangeValue >= i.RangeLow && rangeValue < i.RangeHigh)
                                {
                                    double newsaleprice = 0;

                                    if (amounttype == "1")
                                    {
                                        // percentage discount
                                        newsaleprice = Math.Round(basecost - ((basecost / 100) * i.Cost), 4);
                                    }
                                    else
                                    {
                                        // amount discount
                                        newsaleprice = basecost - i.Cost;
                                        if (newsaleprice < 0)
                                        {
                                            newsaleprice = 0;
                                        }
                                    }

                                    cartItemInfo.SetXmlPropertyDouble("genxml/promoprice", newsaleprice);
                                }
                            }
                        }
                    }
                }
            }
            return(cartItemInfo);
        }
예제 #23
0
        public static string CalcGroupPromoItem(NBrightInfo p)
        {
            var objCtrl = new NBrightBuyController();
                var typeselect = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
                var catgroupid = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
                var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
                var promoname = p.GetXmlProperty("genxml/textbox/name");
                var amounttype = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
                var amount = p.GetXmlPropertyDouble("genxml/textbox/amount");
                var validfrom = p.GetXmlProperty("genxml/textbox/validfrom");
                var validuntil = p.GetXmlProperty("genxml/textbox/validuntil");
                var overwrite = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
                var disabled = p.GetXmlPropertyBool("genxml/checkbox/disabled");
                var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated");

                if (!disabled)
                {
                    var runcalc = true;
                    if (Utils.IsDate(lastcalculated))
                    {
                        if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate) runcalc = false; // only run if changed
                        if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1)) runcalc = true; // every day just after midnight. (for site performace)
                    }
                    if (Utils.IsDate(validuntil))
                    {
                        if (DateTime.Now.Date > Convert.ToDateTime(validuntil)) runcalc = true; // need to disable the promo if passed date
                    }
                    if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil))
                    {
                        var dteF = Convert.ToDateTime(validfrom).Date;
                        var dteU = Convert.ToDateTime(validuntil).Date;
                        CategoryData gCat;
                        var groupid = catgroupid;
                        if (typeselect != "cat") groupid = propgroupid;

                        gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture());
                        var prdList = gCat.GetAllArticles();

                        foreach (var prd in prdList)
                        {
                            if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                            {
                                // CALC Promo
                                CalcProductSalePrice(p.PortalId, prd.ParentItemId, amounttype, amount, promoname, p.ItemID, overwrite,dteF,dteU);
                            }
                            if (DateTime.Now.Date > dteU)
                            {
                                // END Promo
                                RemoveProductPromoData(p.PortalId, prd.ParentItemId, p.ItemID);
                                p.SetXmlProperty("genxml/checkbox/disabled", "True");
                                objCtrl.Update(p);
                            }
                            ProductUtils.RemoveProductDataCache(p.PortalId, prd.ParentItemId);
                        }

                        p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time.
                        objCtrl.Update(p);
                    }
                }
            return "OK";
        }
예제 #24
0
        private static void CalcProductSalePrice(int portalid, int productId, string amounttype, double amount, string promoname, int promoid, bool overwrite,DateTime dteF, DateTime dteU)
        {
            var cultureList = DnnUtils.GetCultureCodeList(portalid);
            var objCtrl = new NBrightBuyController();
            var prdData = objCtrl.GetData(productId);

            var nodList = prdData.XMLDoc.SelectNodes("genxml/models/genxml");
            if (nodList != null)
            {

                var currentpromoid = prdData.GetXmlPropertyInt("genxml/hidden/promoid");
                if (currentpromoid == 0 || currentpromoid == promoid || overwrite)
                {
                    prdData.SetXmlProperty("genxml/hidden/promotype", "PROMOGROUP");
                    prdData.SetXmlPropertyDouble("genxml/hidden/promoname", promoname);
                    prdData.SetXmlProperty("genxml/hidden/promoid", promoid.ToString());
                    prdData.SetXmlProperty("genxml/hidden/promocalcdate", DateTime.Now.ToString("O"));
                    prdData.SetXmlProperty("genxml/hidden/datefrom", dteF.ToString("O"));
                    prdData.SetXmlProperty("genxml/hidden/dateuntil", dteU.ToString("O"));

                    var lp = 1;
                    foreach (XmlNode nod in nodList)
                    {
                        var nbi = new NBrightInfo();
                        nbi.XMLData = nod.OuterXml;
                        var unitcost = nbi.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
                        Double newamt = 0;
                        if (amounttype == "1")
                        {
                            newamt = unitcost - amount;
                        }
                        else
                        {
                            newamt = unitcost - ((unitcost/100)*amount);
                        }

                        if (newamt < 0) newamt = 0;

                        var currentprice = prdData.GetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice");

                        if (!overwrite)
                        {
                            if (currentprice == 0) overwrite = true;
                            if (currentpromoid == promoid) overwrite = true;
                        }
                        if (overwrite)
                        {
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt);
                        }
                        lp += 1;
                    }
                    objCtrl.Update(prdData);

                    foreach (var lang in cultureList)
                    {
                        var p = objCtrl.GetDataLang(promoid, lang);
                        var prdDataLang = objCtrl.GetDataLang(productId, lang);
                        if (prdDataLang != null)
                        {
                            prdDataLang.SetXmlProperty("genxml/hidden/promodesc", p.GetXmlProperty("genxml/textbox/description"));
                            objCtrl.Update(prdDataLang);
                        }
                    }
                }
            }
        }
예제 #25
0
        private NBrightInfo ValidateCartItem(int portalId, int userId, NBrightInfo cartItemInfo, Boolean removeZeroQtyItems = false)
        {
            #region "get cart values"
            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemBefore, cartItemInfo);

            var modelid = cartItemInfo.GetXmlProperty("genxml/modelid");
            var prdid   = cartItemInfo.GetXmlPropertyInt("genxml/productid");
            var qty     = cartItemInfo.GetXmlPropertyDouble("genxml/qty");
            var lang    = cartItemInfo.GetXmlProperty("genxml/lang");

            if (removeZeroQtyItems && qty == 0)
            {
                return(null);                                // Remove zero qty item
            }
            if (lang == "")
            {
                lang = Utils.GetCurrentCulture();
            }
            var prd = ProductUtils.GetProductData(prdid, lang);
            if (!prd.Exists || prd.Disabled)
            {
                return(null);                             //Invalid product remove from cart
            }
            // update product xml data on cart (product may have change via plugin so always replace)
            cartItemInfo.RemoveXmlNode("genxml/productxml");
            // add entitytype for validation methods
            prd.Info.SetXmlProperty("genxml/entitytypecode", prd.Info.TypeCode);
            cartItemInfo.AddSingleNode("productxml", prd.Info.XMLData, "genxml");

            var prdModel = prd.GetModel(modelid);
            if (prdModel == null)
            {
                return(null);                  // Invalid Model remove from cart
            }
            // check if dealer (for tax calc)
            if (NBrightBuyUtils.IsDealer())
            {
                cartItemInfo.SetXmlProperty("genxml/isdealer", "True");
            }
            else
            {
                cartItemInfo.SetXmlProperty("genxml/isdealer", "False");
            }

            // check for price change
            var unitcost       = prdModel.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
            var dealercost     = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
            var saleprice      = prdModel.GetXmlPropertyDouble("genxml/textbox/txtsaleprice");
            var dealersalecost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealersale");

            // always make sale price best price
            if (unitcost > 0 && (unitcost < saleprice || saleprice <= 0))
            {
                saleprice = unitcost;
            }
            // if we have a promoprice use it as saleprice (This is passed in via events provider like "Multi-Buy promotions")
            if (cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") > 0 && cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") < saleprice)
            {
                saleprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice");
            }

            // always assign the dealercost the best price.
            if (dealersalecost > 0 && dealersalecost < dealercost)
            {
                dealercost = dealersalecost;
            }
            if (saleprice > 0 && (saleprice < dealercost || dealercost <= 0))
            {
                dealercost = saleprice;
            }
            if (unitcost > 0 && (unitcost < dealercost || dealercost <= 0))
            {
                dealercost = unitcost;
            }



            // calc sell price
            // sellcost = the calculated cost of the item.
            var sellcost = unitcost;
            if (saleprice > 0 && saleprice < sellcost)
            {
                sellcost = saleprice;
            }
            if (NBrightBuyUtils.IsDealer())
            {
                if (dealercost > 0 && dealercost < sellcost)
                {
                    sellcost = dealercost;
                }
            }
            // --------------------------------------------
            #endregion

            if (prdModel != null)
            {
                #region "Stock Control"
                var stockon    = prdModel.GetXmlPropertyBool("genxml/checkbox/chkstockon");
                var stocklevel = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining");
                var minStock   = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyminstock");
                if (minStock == 0)
                {
                    minStock = StoreSettings.Current.GetInt("minimumstocklevel");
                }
                var maxStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtystockset");
                var weight   = prdModel.GetXmlPropertyDouble("genxml/textbox/weight");
                if (stockon)
                {
                    stocklevel = stocklevel - minStock;
                    stocklevel = stocklevel - prd.GetModelTransQty(modelid, _cartId);
                    if (stocklevel < qty)
                    {
                        qty = stocklevel;
                        if (qty <= 0)
                        {
                            qty = 0;
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "OUTOFSTOCK");
                        }
                        else
                        {
                            cartItemInfo.SetXmlProperty("genxml/validatecode", "STOCKADJ");
                        }
                        base.SetValidated(false);
                        cartItemInfo.SetXmlPropertyDouble("genxml/qty", qty.ToString(""));
                    }
                }
                #endregion

                #region "Addtional options costs"
                Double additionalCosts = 0;
                var    optNods         = cartItemInfo.XMLDoc.SelectNodes("genxml/options/*");
                if (optNods != null)
                {
                    var lp = 1;
                    foreach (XmlNode nod in optNods)
                    {
                        var optid = nod.SelectSingleNode("optid");
                        if (optid != null)
                        {
                            var optvalueid = nod.SelectSingleNode("optvalueid");
                            if (optvalueid != null && optvalueid.InnerText != "False")
                            {
                                XmlNode optvalcostnod;
                                if (optvalueid.InnerText == "True")
                                {
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues[@optionid='" + optid.InnerText + "']/genxml/textbox/txtaddedcost");
                                }
                                else
                                {
                                    optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues/genxml[./hidden/optionvalueid='" + optvalueid.InnerText + "']/textbox/txtaddedcost");
                                }

                                if (optvalcostnod != null)
                                {
                                    var optvalcost = optvalcostnod.InnerText;
                                    if (Utils.IsNumeric(optvalcost))
                                    {
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", optvalcost);
                                        var optvaltotal = Convert.ToDouble(optvalcost, CultureInfo.GetCultureInfo("en-US")) * qty;
                                        cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", optvaltotal);
                                        additionalCosts += optvaltotal;
                                    }
                                }
                                else
                                {
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", "0");
                                    cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", "0");
                                }
                            }
                        }
                        lp += 1;
                    }
                }

                if (qty > 0)  // can't devide by zero
                {
                    unitcost += (additionalCosts / qty);
                    if (dealercost > 0)
                    {
                        dealercost += (additionalCosts / qty);                 // zero turns off
                    }
                    if (saleprice > 0)
                    {
                        saleprice += (additionalCosts / qty);                // zero turns off
                    }
                    sellcost += (additionalCosts / qty);
                }
                #endregion

                var totalcost     = qty * unitcost;
                var totalsellcost = qty * sellcost;
                var totalweight   = weight * qty;

                cartItemInfo.SetXmlPropertyDouble("genxml/unitcost", unitcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/dealercost", dealercost);
                cartItemInfo.SetXmlPropertyDouble("genxml/saleprice", saleprice);

                cartItemInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight.ToString(""));
                cartItemInfo.SetXmlPropertyDouble("genxml/totalcost", totalcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", (totalcost - (qty * dealercost)));

                Double salediscount    = 0;
                Double discountcodeamt = 0;
                Double totaldiscount   = 0;

                //add update genxml/discountcodeamt
                var discountcode = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");
                if (discountcode != "")
                {
                    cartItemInfo    = DiscountCodeInterface.UpdateItemPercentDiscountCode(PortalId, UserId, cartItemInfo, discountcode);
                    discountcodeamt = cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt");
                    if (discountcodeamt > 0)
                    {
                        PurchaseInfo.SetXmlProperty("genxml/discountprocessed", "False");
                    }
                }

                if (NBrightBuyUtils.IsDealer())
                {
                    salediscount = (unitcost - dealercost);
                }
                else
                {
                    salediscount = (unitcost - saleprice);
                }
                totaldiscount = (salediscount * qty) + discountcodeamt; // add on any promo code amount
                if (totaldiscount < 0)
                {
                    totaldiscount = 0;
                }

                // if we have a promodiscount use it
                if (cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount") > 0)
                {
                    totaldiscount = cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount");
                    totalcost     = totalcost - totaldiscount;
                    if (totalcost < 0)
                    {
                        totalcost = 0;
                    }
                    cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalcost);
                }


                cartItemInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount);

                // if product is on sale then we need to display the sale price in the cart, and any discount codes don;t show at this cart item level, only on the order total.
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalsellcost);
                cartItemInfo.SetXmlPropertyDouble("genxml/appliedcost", sellcost);


                // calc tax for item
                var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/hidden/taxproviderkey");
                var taxprov        = TaxInterface.Instance(taxproviderkey);
                if (taxprov != null)
                {
                    var nbi = (NBrightInfo)cartItemInfo.Clone();
                    cartItemInfo.SetXmlPropertyDouble("genxml/taxcost", taxprov.CalculateItemTax(nbi));
                }
            }


            cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemAfter, cartItemInfo);

            return(cartItemInfo);
        }
예제 #26
0
        private static void CalcProductSalePrice(int portalid, int productId, string amounttype, double amount, int promoid, int whichprice, bool overwrite)
        {
            var cultureList = DnnUtils.GetCultureCodeList(portalid);
            var objCtrl     = new NBrightBuyController();
            var prdData     = objCtrl.GetData(productId);

            var nodList = prdData.XMLDoc.SelectNodes("genxml/models/genxml");

            if (nodList != null)
            {
                prdData.SetXmlProperty("genxml/hidden/promoflag", "True"); // set flag, so we can identify products with promo for product save event removal.
                if (prdData.GetXmlProperty("genxml/promo") == "")
                {
                    prdData.SetXmlProperty("genxml/promo", "");
                }
                var lp = 1;
                foreach (XmlNode nod in nodList)
                {
                    var currentpromoid = GetCurrentPromoId(prdData, whichprice, lp);
                    var nbi            = new NBrightInfo();
                    nbi.XMLData = nod.OuterXml;
                    var    disablesale      = nbi.GetXmlPropertyBool("genxml/checkbox/chkdisablesale");
                    var    disabledealer    = nbi.GetXmlPropertyBool("genxml/checkbox/chkdisabledealer");
                    var    unitcost         = nbi.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
                    var    dealercost       = nbi.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
                    Double newamt           = 0;
                    Double newdealersaleamt = 0;
                    Double newdealeramt     = 0;
                    if (amounttype == "1")
                    {
                        newamt           = unitcost - amount;
                        newdealersaleamt = dealercost - amount;
                    }
                    else
                    {
                        newamt           = unitcost - ((unitcost / 100) * amount);
                        newdealersaleamt = dealercost - ((dealercost / 100) * amount);
                    }
                    newdealeramt = newamt;
                    if (newamt < 0)
                    {
                        newamt = 0;
                    }
                    if (newdealersaleamt < 0)
                    {
                        newdealersaleamt = 0;
                    }

                    var currentprice = GetCurrentPromoPrice(prdData, whichprice, lp);
                    if (!overwrite)
                    {
                        if (currentprice == 0)
                        {
                            overwrite = true;
                        }
                        if (currentpromoid == promoid)
                        {
                            overwrite = true;
                        }
                    }
                    if (overwrite)
                    {
                        switch (whichprice)
                        {
                        case 1:
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt);
                            prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString());
                            break;

                        case 2:
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealercost", newdealeramt);
                            prdData.SetXmlProperty("genxml/promo/dealercostid" + lp, promoid.ToString());
                            break;

                        case 3:
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", newdealersaleamt);
                            prdData.SetXmlProperty("genxml/promo/dealersaleid" + lp, promoid.ToString());
                            break;

                        case 4:
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", newdealersaleamt);
                            prdData.SetXmlProperty("genxml/promo/dealersaleid" + lp, promoid.ToString());
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt);
                            prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString());
                            break;

                        default:
                            prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt);
                            prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString());
                            break;
                        }
                    }
                    if (disablesale)
                    {
                        prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", 0);
                        prdData.RemoveXmlNode("genxml/promo/salepriceid" + lp);
                    }
                    if (disabledealer)
                    {
                        prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealercost", 0);
                        prdData.RemoveXmlNode("genxml/promo/dealercostid" + lp);
                        prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", 0);
                        prdData.RemoveXmlNode("genxml/promo/dealersaleid" + lp);
                    }

                    lp += 1;
                }
                objCtrl.Update(prdData);

                foreach (var lang in cultureList)
                {
                    var promodesc = "";
                    var p         = objCtrl.GetDataLang(promoid, lang);
                    if (p != null)
                    {
                        promodesc = p.GetXmlProperty("genxml/textbox/description");
                    }
                    var prdDataLang = objCtrl.GetDataLang(productId, lang);
                    if (prdDataLang != null)
                    {
                        prdDataLang.SetXmlProperty("genxml/hidden/promodesc", promodesc);
                        objCtrl.Update(prdDataLang);
                    }
                }
            }
        }
예제 #27
0
        private String GetItemDisplay(NBrightInfo obj, String templ, Boolean displayPrices)
        {
            var isDealer = CmsProviderManager.Default.IsInRole(StoreSettings.DealerRole);
            var outText = templ;
            var stockOn = obj.GetXmlPropertyBool("genxml/checkbox/chkstockon");
            var stock = obj.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining");
            if (stock > 0 || !stockOn)
            {
                outText = outText.Replace("{ref}", obj.GetXmlProperty("genxml/textbox/txtmodelref"));
                outText = outText.Replace("{name}", obj.GetXmlProperty("genxml/lang/genxml/textbox/txtmodelname"));
                outText = outText.Replace("{stock}", stock.ToString(""));

                if (displayPrices)
                {
                    //[TODO: add promotional calc]
                    var saleprice = obj.GetXmlPropertyDouble("genxml/textbox/txtsaleprice");
                    var price = obj.GetXmlPropertyDouble("genxml/textbox/txtunitcost");
                    var bestprice = price;
                    if (saleprice > 0 && saleprice < price) bestprice = saleprice;

                    var strprice = NBrightBuyUtils.FormatToStoreCurrency(price);
                    var strbestprice = NBrightBuyUtils.FormatToStoreCurrency(bestprice);
                    var strsaleprice = NBrightBuyUtils.FormatToStoreCurrency(saleprice);

                    var strdealerprice = "";
                    var dealerprice = obj.GetXmlPropertyDouble("genxml/textbox/txtdealercost");
                    if (isDealer)
                    {
                        strdealerprice = NBrightBuyUtils.FormatToStoreCurrency(dealerprice);
                        if (!outText.Contains("{dealerprice}") && (price > dealerprice)) strprice = strdealerprice;
                        if (dealerprice < bestprice) bestprice = dealerprice;
                    }

                    outText = outText.Replace("{price}", "(" + strprice + ")");
                    outText = outText.Replace("{dealerprice}", strdealerprice);
                    outText = outText.Replace("{bestprice}", strbestprice);
                    outText = outText.Replace("{saleprice}", strsaleprice);
                }
                else
                {
                    outText = outText.Replace("{price}", "");
                    outText = outText.Replace("{dealerprice}", "");
                    outText = outText.Replace("{bestprice}", "");
                    outText = outText.Replace("{saleprice}", "");
                }

                return outText;
            }
            return ""; // no stock so return empty string.
        }
예제 #28
0
        public override Double CalculateItemTax(NBrightInfo cartItemInfo)
        {
            var info = ProviderUtils.GetProviderSettings("tax");
            var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype");

            if (taxtype == "3") return 0;

            var rateDic = GetRates();
            if (!rateDic.Any()) return 0;

            // loop through each item and calc the tax for each.
            Double taxtotal = 0;

            var totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totalcost");
            if (cartItemInfo.GetXmlPropertyBool("genxml/isdealer")) totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totaldealercost");
            var taxratecode = cartItemInfo.GetXmlProperty("genxml/taxratecode");
            if (taxratecode == "") taxratecode = "0";
            if (!rateDic.ContainsKey(taxratecode)) taxratecode = "0";
            Double taxrate = 0;
            if (rateDic.ContainsKey(taxratecode)) taxrate = rateDic[taxratecode]; // Can happen is no default tax added.

            if (taxtype == "1") // included in unit price
            {
                taxtotal += totalcost - ((totalcost / (100 + taxrate)) * 100);
            }
            if (taxtype == "2") // NOT included in unit price
            {
                taxtotal += (totalcost / 100) * taxrate;
            }

            return Math.Round(taxtotal, 2);
        }
예제 #29
0
        public static string CalcGroupPromoItem(NBrightInfo p)
        {
            var objCtrl        = new NBrightBuyController();
            var typeselect     = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid     = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid    = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
            var promoname      = p.GetXmlProperty("genxml/textbox/name");
            var amounttype     = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
            var amount         = p.GetXmlPropertyDouble("genxml/textbox/amount");
            var validfrom      = p.GetXmlProperty("genxml/textbox/validfrom");
            var validuntil     = p.GetXmlProperty("genxml/textbox/validuntil");
            var overwrite      = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
            var disabled       = p.GetXmlPropertyBool("genxml/checkbox/disabled");
            var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated");
            var whichprice     = p.GetXmlPropertyInt("genxml/radiobuttonlist/whichprice");
            var runfreq        = p.GetXmlPropertyInt("genxml/radiobuttonlist/runfreq");

            if (!disabled)
            {
                var portalsettings = NBrightDNN.DnnUtils.GetPortalSettings(p.PortalId);
                var lang           = portalsettings.DefaultLanguage;

                var prdList = new List <NBrightInfo>();
                if (typeselect == "all")
                {
                    prdList = objCtrl.GetList(p.PortalId, -1, "PRD");
                }
                else
                {
                    CategoryData gCat;
                    var          groupid = catgroupid;
                    if (typeselect != "cat")
                    {
                        groupid = propgroupid;
                    }
                    gCat = CategoryUtils.GetCategoryData(groupid, lang);
                    if (gCat != null)
                    {
                        prdList = gCat.GetAllArticles();
                    }
                }

                var runcalc = true;
                if (runfreq == 1 || runfreq == 3) // run freq is date range
                {
                    if (runfreq == 3)
                    {
                        // run constantly, set end date to +100 year
                        validfrom  = DateTime.Now.AddYears(-1).ToString("s");
                        validuntil = DateTime.Now.AddYears(100).ToString("s");
                    }
                    // run date range
                    if (Utils.IsDate(lastcalculated))
                    {
                        if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate)
                        {
                            runcalc = false;                                                       // only run if changed
                        }
                        if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1))
                        {
                            runcalc = true;                                                                         // every day just after midnight. (for site performace)
                        }
                    }
                    if (Utils.IsDate(validuntil))
                    {
                        if (DateTime.Now.Date > Convert.ToDateTime(validuntil))
                        {
                            runcalc = true;                                                     // need to disable the promo if passed date
                        }
                    }
                    if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil))
                    {
                        var dteF = Convert.ToDateTime(validfrom).Date;
                        var dteU = Convert.ToDateTime(validuntil).Date;

                        foreach (var prd in prdList)
                        {
                            var productid = prd.ParentItemId;
                            if (typeselect == "all")
                            {
                                productid = prd.ItemID;
                            }

                            if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                            {
                                // CALC Promo
                                CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite);
                            }
                            if (DateTime.Now.Date > dteU)
                            {
                                // END Promo
                                RemoveProductPromoData(p.PortalId, productid, p.ItemID);
                            }
                            ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                            var productData = ProductUtils.GetProductData(productid, lang);
                            productData.Save(); // recalc any new prices.
                        }
                        if (DateTime.Now.Date > dteU)
                        {
                            // END Promo
                            p.SetXmlProperty("genxml/checkbox/disabled", "True");
                        }
                    }
                }
                if (runfreq == 2) // run Once, do update and disable promo.
                {
                    foreach (var prd in prdList)
                    {
                        var productid = prd.ParentItemId;
                        if (typeselect == "all")
                        {
                            productid = prd.ItemID;
                        }
                        // CALC Promo
                        CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite);
                        ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                        var productData = ProductUtils.GetProductData(productid, lang);
                        productData.Save(); // recalc any new prices.
                    }
                    p.SetXmlProperty("genxml/checkbox/disabled", "True");
                }
                if (runfreq == 4) // remove
                {
                    foreach (var prd in prdList)
                    {
                        var productid = prd.ParentItemId;
                        if (typeselect == "all")
                        {
                            productid = prd.ItemID;
                        }
                        RemoveProductPromoData(p.PortalId, productid, p.ItemID);
                        ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                        var productData = ProductUtils.GetProductData(productid, lang);
                        productData.Save(); // recalc any new prices.
                    }

                    p.SetXmlProperty("genxml/checkbox/disabled", "True");
                }
                p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time.
                objCtrl.Update(p);
            }
            return("OK");
        }
예제 #30
0
        public override NBrightInfo CalculateVoucherAmount(int portalId, int userId, NBrightInfo cartInfo, string discountcode)
        {
            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "");
            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", "0"); // reset discount amount
            Double discountcodeamt = 0;
            if (userId > 0)
            {
                var clientData = new ClientData(portalId, userId);
                if (clientData.DiscountCodes.Count > 0)
                {
                    var subtotal = cartInfo.GetXmlPropertyDouble("genxml/subtotal");
                    // do client voucher discount on total cart
                    foreach (var d in clientData.VoucherCodes)
                    {
                        var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                        var validutildate = DateTime.Today;
                        if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                        if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                        {
                            var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                            if (amount > 0)
                            {
                                if (subtotal >= amount)
                                    discountcodeamt = amount;
                                else
                                    discountcodeamt = subtotal;
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                            }
                            else
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                            }
                        }
                        if (discountcodeamt > 0) break;
                    }
                }
            }

            if (discountcodeamt == 0) // if no client level, calc any portal level percentage discount
            {
                var objCtrl = new NBrightBuyController();
                var d = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (d != null)
                {
                    var validutil = d.GetXmlProperty("genxml/textbox/validuntil");
                    var validutildate = DateTime.Today;
                    if (Utils.IsDate(validutil)) validutildate = Convert.ToDateTime(validutil);
                    if (validutildate >= DateTime.Today && d.GetXmlProperty("genxml/radiobuttonlist/amounttype") == "1")
                    {
                        var minamountlimit = d.GetXmlPropertyDouble("genxml/textbox/minamountlimit");
                        var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                        var usage = d.GetXmlPropertyDouble("genxml/textbox/usage");
                        var usagelimit = d.GetXmlPropertyDouble("genxml/textbox/usagelimit");
                        var appliedsubtotal = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
                        if (amount > 0 && (usagelimit == 0 || usagelimit > usage) && (appliedsubtotal >= minamountlimit))
                        {
                            discountcodeamt = amount;
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                        }
                        else
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                        }
                    }
                }
            }

            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", discountcodeamt); // reset discount amount

            return cartInfo;
        }
예제 #31
0
        private void CreateXchartOrderRevDataBind(object sender, EventArgs e)
        {
            var lc = (Literal) sender;
            var container = (IDataItemContainer) lc.NamingContainer;
            lc.Visible = visibleStatus.DefaultIfEmpty(true).First();
            if (lc.Visible && container.DataItem != null)
            {
                var nbi1 = (NBrightInfo) container.DataItem;
                var strOut = "";
                var nodList = nbi1.XMLDoc.SelectNodes("root/orderstats/*");
                if (nodList != null)
                {
                    foreach (XmlNode nod in nodList)
                    {
                        var nbi = new NBrightInfo();
                        nbi.XMLData = nod.OuterXml;

                        strOut += "{'x': '" + nbi.GetXmlPropertyInt("item/createdyear") + "-" + nbi.GetXmlPropertyInt("item/createdmonth") + "',";
                        strOut += "'y': " + nbi.GetXmlPropertyDouble("item/appliedtotal").ToString() + "},";

                    }
                    strOut = strOut.TrimEnd(',');
                }

                lc.Text = strOut;
            }
        }
예제 #32
0
        /// <summary>
        /// Get the cookie data from the client.
        /// </summary>
        /// <returns></returns>
        public NavigationData Get()
        {
            ClearData();

            var tempfilename = "";

            if (_storageType == DataStorageType.SessionMemory)
            {
                if (HttpContext.Current.Session[_cookieName + "tempname"] != null) tempfilename = (String)HttpContext.Current.Session[_cookieName + "tempname"];
            }
            else
            {
                tempfilename = Cookie.GetCookieValue(_portalId, _cookieName, "tempname", "");
            }

            XmlData = "";

            if (tempfilename != "")
            {
                var filePath = StoreSettings.Current.FolderTempMapPath + "\\" + tempfilename;
                if (File.Exists(filePath)) XmlData = Utils.ReadFile(filePath);
                var nbi = new NBrightInfo();
                nbi.XMLData = XmlData;

                _criteria = nbi.GetXmlProperty("genxml/Criteria");
                PageModuleId = nbi.GetXmlProperty("genxml/PageModuleId");
                PageNumber = nbi.GetXmlProperty("genxml/PageNumber");
                PageName = nbi.GetXmlProperty("genxml/PageName");
                PageSize = nbi.GetXmlProperty("genxml/PageSize");
                OrderBy = nbi.GetXmlProperty("genxml/OrderBy");
                CategoryId = Convert.ToInt32(nbi.GetXmlPropertyDouble("genxml/CategoryId"));
                RecordCount = nbi.GetXmlProperty("genxml/RecordCount");
                Mode = nbi.GetXmlProperty("genxml/Mode");
                OrderByIdx = nbi.GetXmlProperty("genxml/OrderByIdx");
                SearchFormData = nbi.GetXmlNode("genxml/SearchFormData").ToString();

            }

            if (_criteria == "" && XmlData == "") // "Exist" property not used for paging data
                Exists = false;
            else
                Exists = true;

            return this;
        }
예제 #33
0
        public String AddSingleItem(String strproductid, String strmodelId, String strqtyId, NBrightInfo objInfoIn, Boolean debugMode = false, int replaceIndex = -1)
        {
            if (!Utils.IsNumeric(strqtyId) || Convert.ToInt32(strqtyId) <= 0) return "";

            if (StoreSettings.Current.DebugModeFileOut) objInfoIn.XMLDoc.Save(PortalSettings.Current.HomeDirectoryMapPath + "debug_addtobasket.xml");

            var objInfo = new NBrightInfo();
            objInfo.XMLData = "<genxml></genxml>";

            // get productid
            if (Utils.IsNumeric(strproductid))
            {
                var itemcode = ""; // The itemcode var is used to decide if a cart item is new or already existing in the cart.
                var productData = ProductUtils.GetProductData(Convert.ToInt32(strproductid), Utils.GetCurrentCulture());

                if (productData.Info == null) return ""; // we may have a invalid productid that has been saved by a cookie, but since has been deleted.

                var modelInfo = productData.GetModel(strmodelId);
                if (modelInfo == null) return ""; // no valid model

                objInfo.AddSingleNode("productid", strproductid, "genxml");
                itemcode += strproductid + "-";

                objInfo.AddSingleNode("modelid", strmodelId, "genxml");
                itemcode += strmodelId + "-";

                // Get Qty
                objInfo.AddSingleNode("qty", strqtyId, "genxml");

                #region "Get model and product data"

                objInfo.AddSingleNode("productname", productData.Info.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtproductname"), "genxml");
                objInfo.AddSingleNode("summary", productData.Info.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtsummary"), "genxml");

                objInfo.AddSingleNode("modelref", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtmodelref"), "genxml");
                objInfo.AddSingleNode("modeldesc", modelInfo.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtmodelname"), "genxml");
                objInfo.AddSingleNode("modelextra", modelInfo.GetXmlPropertyRaw("genxml/lang/genxml/textbox/txtextra"), "genxml");
                objInfo.AddSingleNode("unitcost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtunitcost"), "genxml");
                objInfo.AddSingleNode("dealercost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtdealercost"), "genxml");
                objInfo.AddSingleNode("taxratecode", modelInfo.GetXmlPropertyRaw("genxml/dropdownlist/taxrate"), "genxml");
                objInfo.AddSingleNode("saleprice", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtsaleprice"), "genxml");
                objInfo.AddSingleNode("basecost", modelInfo.GetXmlPropertyRaw("genxml/textbox/txtunitcost"), "genxml");

                // flag if dealer
                var userInfo = UserController.Instance.GetCurrentUserInfo();
                if (userInfo != null && userInfo.IsInRole(StoreSettings.DealerRole) && StoreSettings.Current.Get("enabledealer") == "True")
                    objInfo.SetXmlProperty("genxml/isdealer", "True");
                else
                    objInfo.SetXmlProperty("genxml/isdealer", "False");

                //move all product and model data into cart item, so we can display bespoke fields.
                objInfo.AddSingleNode("productxml", productData.Info.XMLData, "genxml");

                #endregion

                #region "Get option Data"

                //build option data for cart
                Double additionalCosts = 0;
                var strXmlIn = "";
                var optionDataList = new Dictionary<String, String>();
                if (objInfoIn.XMLDoc != null)
                {
                    var nodList = objInfoIn.XMLDoc.SelectNodes("genxml/textbox/*[starts-with(name(), 'optiontxt')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                            strXmlIn = "<option>";
                            var idx = nod.Name.Replace("optiontxt", "");
                            var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                            var optionInfo = productData.GetOption(optionid);
                            var optvaltext = nod.InnerText;
                            strXmlIn += "<optid>" + optionid + "</optid>";
                            strXmlIn += "<optvaltext>" + optvaltext + "</optvaltext>";
                            itemcode += optionid + "-" + Utils.GetUniqueKey() + "-";
                            strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                            strXmlIn += "</option>";
                            if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                    nodList = objInfoIn.XMLDoc.SelectNodes("genxml/dropdownlist/*[starts-with(name(), 'optionddl')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                            strXmlIn = "<option>";
                            var idx = nod.Name.Replace("optionddl", "");
                            var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                            var optionvalueid = nod.InnerText;
                            var optionValueInfo = productData.GetOptionValue(optionid, optionvalueid);
                            var optionInfo = productData.GetOption(optionid);
                            strXmlIn += "<optid>" + optionid + "</optid>";
                            strXmlIn += "<optvalueid>" + optionvalueid + "</optvalueid>";
                            itemcode += optionid + ":" + optionvalueid + "-";
                            strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                            strXmlIn += "<optvalcost>" + optionValueInfo.GetXmlProperty("genxml/textbox/txtaddedcost") + "</optvalcost>";
                            strXmlIn += "<optvaltext>" + optionValueInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + "</optvaltext>";
                            strXmlIn += "</option>";
                            additionalCosts += optionValueInfo.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
                            if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                    nodList = objInfoIn.XMLDoc.SelectNodes("genxml/checkbox/*[starts-with(name(), 'optionchk')]");
                    if (nodList != null)
                        foreach (XmlNode nod in nodList)
                        {
                                strXmlIn = "<option>";
                                var idx = nod.Name.Replace("optionchk", "");
                                var optionid = objInfoIn.GetXmlProperty("genxml/hidden/optionid" + idx);
                                var optionvalueid = nod.InnerText;
                                var optionValueInfo = productData.GetOptionValue(optionid, ""); // checkbox does not have optionvalueid
                                var optionInfo = productData.GetOption(optionid);
                                strXmlIn += "<optid>" + optionid + "</optid>";
                                strXmlIn += "<optvalueid>" + optionvalueid + "</optvalueid>";
                                itemcode += optionid + ":" + optionvalueid + "-";
                                strXmlIn += "<optname>" + optionInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptiondesc") + "</optname>";
                                strXmlIn += "<optvalcost>" + optionValueInfo.GetXmlProperty("genxml/textbox/txtaddedcost") + "</optvalcost>";
                                strXmlIn += "<optvaltext>" + optionValueInfo.GetXmlProperty("genxml/lang/genxml/textbox/txtoptionvaluedesc") + "</optvaltext>";
                                strXmlIn += "</option>";
                                if (nod.InnerText.ToLower() == "true") additionalCosts += optionValueInfo.GetXmlPropertyDouble("genxml/textbox/txtaddedcost");
                                if (!optionDataList.ContainsKey(idx)) optionDataList.Add(idx, strXmlIn);
                        }
                }

                // we need to save the options in the same order as in product, so index works correct on the template tokens.
                var strXmlOpt = "<options>";
                for (int i = 1; i <= optionDataList.Count; i++)
                {
                    if (optionDataList.ContainsKey(i.ToString("")))
                    {
                        strXmlOpt += optionDataList[i.ToString("")];
                    }
                }
                strXmlOpt += "</options>";

                objInfo.AddXmlNode(strXmlOpt, "options", "genxml");

                #endregion

                //add additional costs from optionvalues (Add to both dealer and unit cost)
                if (additionalCosts > 0)
                {
                    objInfo.SetXmlPropertyDouble("genxml/additionalcosts", additionalCosts);
                    var uc = objInfo.GetXmlPropertyDouble("genxml/unitcost");
                    var dc = objInfo.GetXmlPropertyDouble("genxml/dealercost");
                    uc += additionalCosts;
                    if (dc > 0) dc += additionalCosts; // only calc dealer cost if it's > zero (active)
                    objInfo.SetXmlPropertyDouble("genxml/unitcost", uc);
                    objInfo.SetXmlPropertyDouble("genxml/dealercost", dc);
                }

                objInfo.AddSingleNode("itemcode", itemcode.TrimEnd('-'), "genxml");

                // check if we have a client file upload
                var clientfileuopload = objInfoIn.GetXmlProperty("genxml/textbox/optionfilelist") != "";

                //replace the item if it's already in the list.
                var nodItem = PurchaseInfo.XMLDoc.SelectSingleNode("genxml/items/genxml[itemcode='" + itemcode.TrimEnd('-') + "']");
                if (nodItem == null || clientfileuopload)
                {
                    #region "Client Files"

                    if (clientfileuopload)
                    {
                        // client has uploaded files, so save these to client upload folder and create link in cart data.
                        var flist = objInfoIn.GetXmlProperty("genxml/textbox/optionfilelist").TrimEnd(',');
                        var fprefix = objInfoIn.GetXmlProperty("genxml/hidden/optionfileprefix") + "_";
                        var fileXml = "<clientfiles>";
                        foreach (var f in flist.Split(','))
                        {
                            var fullName = StoreSettings.Current.FolderTempMapPath.TrimEnd(Convert.ToChar("\\")) + "\\" + fprefix + f;
                            var extension = Path.GetExtension(fullName);
                            if (File.Exists(fullName))
                            {
                                var newDocFileName = StoreSettings.Current.FolderClientUploadsMapPath.TrimEnd(Convert.ToChar("\\")) + "\\" + Guid.NewGuid() + extension;
                                File.Copy(fullName, newDocFileName, true);
                                File.Delete(fullName);
                                var docurl = StoreSettings.Current.FolderClientUploads.TrimEnd('/') + "/" + Path.GetFileName(newDocFileName);
                                fileXml += "<file>";
                                fileXml += "<mappath>" + newDocFileName + "</mappath>";
                                fileXml += "<url>" + docurl + "</url>";
                                fileXml += "<name>" + f + "</name>";
                                fileXml += "<prefix>" + fprefix + "</prefix>";
                                fileXml += "</file>";
                            }
                        }
                        fileXml += "</clientfiles>";
                        objInfo.AddXmlNode(fileXml, "clientfiles", "genxml");
                    }

                    #endregion

                    if (replaceIndex >= 0 && replaceIndex < _itemList.Count)
                        _itemList[replaceIndex] = objInfo; //replace
                    else
                        _itemList.Add(objInfo); //add as new item
                }
                else
                {
                    //replace item
                    var qty = nodItem.SelectSingleNode("qty");
                    if (qty != null && Utils.IsNumeric(qty.InnerText) && Utils.IsNumeric(strqtyId))
                    {
                        var userqtylimit = objInfoIn.GetXmlPropertyInt("genxml/hidden/userqtylimit");
                        if (userqtylimit > 0 && Convert.ToInt32(qty.InnerText) >= userqtylimit) return "";

                        //add new qty and replace item
                        PurchaseInfo.RemoveXmlNode("genxml/items/genxml[itemcode='" + itemcode.TrimEnd('-') + "']");
                        _itemList = GetCartItemList();
                        var newQty = Convert.ToString(Convert.ToInt32(qty.InnerText) + Convert.ToInt32(strqtyId));
                        objInfo.SetXmlProperty("genxml/qty", newQty, TypeCode.String, false);
                        _itemList.Add(objInfo);
                    }
                }

                //add nodes for any fields that might exist in cart template
                objInfo.AddSingleNode("textbox", "", "genxml");
                objInfo.AddSingleNode("dropdownlist", "", "genxml");
                objInfo.AddSingleNode("radiobuttonlist", "", "genxml");
                objInfo.AddSingleNode("checkbox", "", "genxml");

                SavePurchaseData(); // need to save after each add, so it exists in data when we check it already exists for updating.

                // return the message status code in textData, non-critical (usually empty)
                return objInfo.TextData;
            }
            return "";
        }
예제 #34
0
        public override NBrightInfo CalculateVoucherAmount(int portalId, int userId, NBrightInfo cartInfo, string discountcode)
        {
            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "");
            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", "0"); // reset discount amount
            Double discountcodeamt = 0;

            if (userId > 0)
            {
                var clientData = new ClientData(portalId, userId);
                if (clientData.DiscountCodes.Count > 0)
                {
                    var subtotal = cartInfo.GetXmlPropertyDouble("genxml/subtotal");
                    // do client voucher discount on total cart
                    foreach (var d in clientData.VoucherCodes)
                    {
                        var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                        var validutildate = DateTime.Today;
                        if (Utils.IsDate(validutil))
                        {
                            validutildate = Convert.ToDateTime(validutil);
                        }
                        if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                        {
                            var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                            if (amount > 0)
                            {
                                if (subtotal >= amount)
                                {
                                    discountcodeamt = amount;
                                }
                                else
                                {
                                    discountcodeamt = subtotal;
                                }
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                            }
                            else
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                            }
                        }
                        if (discountcodeamt > 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (discountcodeamt == 0) // if no client level, calc any portal level percentage discount
            {
                var objCtrl = new NBrightBuyController();
                var d       = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (d != null)
                {
                    var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                    var validutildate = DateTime.Today;
                    if (Utils.IsDate(validutil))
                    {
                        validutildate = Convert.ToDateTime(validutil);
                    }
                    if (validutildate >= DateTime.Today && d.GetXmlProperty("genxml/radiobuttonlist/amounttype") == "1")
                    {
                        var minamountlimit  = d.GetXmlPropertyDouble("genxml/textbox/minamountlimit");
                        var amount          = d.GetXmlPropertyDouble("genxml/textbox/amount");
                        var usage           = d.GetXmlPropertyDouble("genxml/textbox/usage");
                        var usagelimit      = d.GetXmlPropertyDouble("genxml/textbox/usagelimit");
                        var appliedsubtotal = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
                        if (amount > 0 && (usagelimit == 0 || usagelimit > usage) && (appliedsubtotal >= minamountlimit))
                        {
                            discountcodeamt = amount;
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                        }
                        else
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                        }
                    }
                }
            }

            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", discountcodeamt); // reset discount amount

            return(cartInfo);
        }