public override NBrightInfo UpdatePercentUsage(int portalId, int userId, NBrightInfo purchaseInfo) { if (userId <= 0) return purchaseInfo; var discountcode = purchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode"); if (!purchaseInfo.GetXmlPropertyBool("genxml/discountprocessed")) { if (discountcode == "") return purchaseInfo; var clientData = new ClientData(portalId, userId); if (clientData.DiscountCodes.Count == 0) return purchaseInfo; var list = clientData.DiscountCodes; foreach (var d in list) { if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower()) { var usageleft = d.GetXmlPropertyDouble("genxml/textbox/usageleft"); var used = d.GetXmlPropertyDouble("genxml/textbox/used"); d.SetXmlPropertyDouble("genxml/textbox/usageleft", (usageleft - 1)); d.SetXmlPropertyDouble("genxml/textbox/used", (used + 1)); } } clientData.UpdateDiscountCodeList(list); clientData.Save(); purchaseInfo.SetXmlProperty("genxml/discountprocessed", "True"); } return purchaseInfo; }
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; }
private String GetClientVoucherCodes(HttpContext context) { try { //get uploaded params var strOut = ""; var settings = GetAjaxFields(context); if (!settings.ContainsKey("userid")) settings.Add("userid", ""); var userid = settings["userid"]; if (!settings.ContainsKey("portalid")) settings.Add("portalid", ""); var portalid = settings["portalid"]; if (Utils.IsNumeric(portalid) && Utils.IsNumeric(userid)) { // get template var themeFolder = StoreSettings.Current.ThemeFolder; if (settings.ContainsKey("themefolder")) themeFolder = settings["themefolder"]; var templCtrl = NBrightBuyUtils.GetTemplateGetter(themeFolder); var bodyTempl = templCtrl.GetTemplateData("clientvouchercodes.html", _lang, true, true, true, StoreSettings.Current.Settings()); bodyTempl = Utils.ReplaceSettingTokens(bodyTempl, StoreSettings.Current.Settings()); //get data var clientData = new ClientData(Convert.ToInt32(portalid), Convert.ToInt32(userid)); strOut = GenXmlFunctions.RenderRepeater(clientData.VoucherCodes, bodyTempl); } return strOut; } catch (Exception ex) { return ex.ToString(); } }
private String AddClientVoucherCodes(HttpContext context) { try { var strOut = "Missing data ('userid', 'portalid' hidden fields needed on input form)"; //get uploaded params var settings = GetAjaxFields(context); if (!settings.ContainsKey("addqty")) settings.Add("addqty", "1"); if (!settings.ContainsKey("userid")) settings.Add("userid", ""); var userid = settings["userid"]; if (!settings.ContainsKey("portalid")) settings.Add("portalid", ""); var portalid = settings["portalid"]; if (Utils.IsNumeric(portalid) && Utils.IsNumeric(userid)) { var clientData = new ClientData(Convert.ToInt32(portalid), Convert.ToInt32(userid)); var qty = settings["addqty"]; if (!Utils.IsNumeric(qty)) qty = "1"; var lp = 1; var modelcount = clientData.VoucherCodes.Count; while (lp <= Convert.ToInt32(qty)) { clientData.AddNewVoucherCode(); lp += 1; if (lp > 10) break; // we don;t want to create a stupid amount, it will slow the system!!! } clientData.Save(); var modelcount2 = clientData.VoucherCodes.Count; var rtnList = new List<NBrightInfo>(); for (var i = modelcount; i < modelcount2; i++) { rtnList.Add(clientData.VoucherCodes[i]); } // get template var themeFolder = StoreSettings.Current.ThemeFolder; if (settings.ContainsKey("themefolder")) themeFolder = settings["themefolder"]; var templCtrl = NBrightBuyUtils.GetTemplateGetter(themeFolder); var bodyTempl = templCtrl.GetTemplateData("clientvouchercodes.html", _lang, true, true, true, StoreSettings.Current.Settings()); //get data strOut = GenXmlFunctions.RenderRepeater(rtnList, bodyTempl); } return strOut; } catch (Exception ex) { return ex.ToString(); } }
protected void CtrlItemCommand(object source, RepeaterCommandEventArgs e) { var cArg = e.CommandArgument.ToString(); var param = new string[3]; var navigationData = new NavigationData(PortalId, "ClientsAdmin"); switch (e.CommandName.ToLower()) { case "entrydetail": param[0] = "uid=" + cArg; if (_page != "") param[1] = "page=" + _page; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "return": param[0] = ""; if (_page != "") param[1] = "page=" + _page; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "search": navigationData.XmlData = GenXmlFunctions.GetGenXml(rpSearch,"",""); navigationData.Save(); Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "resetsearch": // clear cookie info navigationData.Delete(); Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "unlockuser": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); clientData.UnlockUser(); } param[0] = "uid=" + cArg; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "deleteuser": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); clientData.DeleteUser(); } param[0] = "uid=" + cArg; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "removeuser": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); var ok = clientData.RemoveUser(); if (!ok) { NBrightBuyUtils.SetNotfiyMessage(ModuleId,"removeuser", NotifyCode.fail); param[0] = "uid=" + cArg; } } Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "validateuser": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); clientData.AuthoriseClient(); clientData.AddClientRole(ModSettings); if (StoreSettings.Current.Get("resetpasswordonclientvalidate") == "True") clientData.ResetPassword(); } param[0] = "uid=" + cArg; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "resetpass": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); clientData.ResetPassword(); } param[0] = "uid=" + cArg; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; case "viewaddressbook": param[0] = ""; if (Utils.IsNumeric(cArg)) { param[0] = "ctrl=addressbook"; param[1] = "uid=" + cArg; } Response.Redirect(Globals.NavigateURL(TabId, "", param), true); break; case "vieworders": param[0] = ""; if (Utils.IsNumeric(cArg)) { param[0] = "ctrl=orders"; param[1] = "uid=" + cArg; } Response.Redirect(Globals.NavigateURL(TabId, "", param), true); break; case "createorder": param[0] = ""; var tabId = TabId; if (Utils.IsNumeric(cArg)) { var cart = new CartData(PortalId); cart.UserId = Convert.ToInt32(cArg); cart.EditMode = "C"; cart.Save(); tabId = StoreSettings.Current.GetInt("productlisttab"); if (tabId==0) tabId = TabId; } Response.Redirect(NBrightBuyUtils.AdminUrl(tabId, param), true); break; case "save": if (Utils.IsNumeric(cArg)) { var clientData = new ClientData(PortalId, Convert.ToInt32(cArg)); if (clientData.Exists) { clientData.Update(rpData); clientData.Save(); } } param[0] = "uid=" + cArg; Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true); break; } }
private void DisplayDataEntryRepeater(String entryId) { if (Utils.IsNumeric(entryId) && entryId != "0") { var clientData = new ClientData(PortalId, Convert.ToInt32(entryId)); clientData.OutputDebugFile("debug_client.xml"); //render the detail page base.DoDetail(rpData, clientData.GetInfo()); } }
public Boolean ConvertToOrder(Boolean debugMode = false) { var itemList = GetCartItemList(); if (IsValidated() && itemList.Count > 0) { PurchaseTypeCode = "ORDER"; if (base.PurchaseInfo.GetXmlProperty("genxml/createddate") == "") base.PurchaseInfo.SetXmlProperty("genxml/createddate", DateTime.Now.ToString(CultureInfo.GetCultureInfo(Utils.GetCurrentCulture())), TypeCode.DateTime); if (base.PurchaseInfo.GetXmlProperty("genxml/ordernumber") == "") base.PurchaseInfo.SetXmlProperty("genxml/ordernumber", StoreSettings.Current.Get("orderprefix") + DateTime.Today.Year.ToString("").Substring(2, 2) + DateTime.Today.Month.ToString("00") + DateTime.Today.Day.ToString("00") + _cartId); Save(); var ordData = new OrderData(PortalId, base.PurchaseInfo.ItemID); ordData.OrderStatus = "010"; if (ordData.EditMode == "") // don't update if we are in edit mode, we dont; want manager email to be altered. { // if the client has updated the email address, link this back to DNN profile. (We assume they alway place there current email address on th order.) var objUser = UserController.GetUserById(PortalSettings.Current.PortalId, ordData.UserId); if (objUser != null && objUser.Email != ordData.EmailAddress) { var clientData = new ClientData(PortalId, ordData.UserId); clientData.UpdateEmail(ordData.EmailAddress); } } ordData.Save(); if (StoreSettings.Current.DebugModeFileOut) OutputDebugFile("debug_convertedcart.xml"); Exists = false; return true; } return false; }
private void PageLoad() { var objprof = _profileData.GetProfile(); if (!_profileData.Exists || objprof == null) { objprof = new NBrightInfo(true); //assume new address objprof.XMLData = NBrightBuyUtils.GetFormTempData(ModuleId); // get any saved data } if (UserId >= 0) { var cData = new ClientData(PortalSettings.PortalId, UserId); objprof.AddXmlNode("<client>" + cData.GetInfo().XMLData + "</client>", "client", "genxml"); if (StoreSettings.Current.DebugMode) objprof.XMLDoc.Save(PortalSettings.Current.HomeDirectoryMapPath + "debug_profile.xml"); } base.DoDetail(rpInp, objprof); }
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; }
public override NBrightInfo UpdateVoucherAmount(int portalId, int userId, NBrightInfo purchaseInfo) { // the "UpdatePercentUsage" function deals with the vouchers for DISCOUNTCODE. var discountcode = purchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode"); var voucherdiscount = purchaseInfo.GetXmlProperty("genxml/voucherdiscount"); if (userId > 0 && Utils.IsNumeric(voucherdiscount)) { if (discountcode == "") return purchaseInfo; var clientData = new ClientData(portalId, userId); if (clientData.VoucherCodes.Count > 0) { clientData.UpdateVoucherAmount(discountcode, Convert.ToDouble(voucherdiscount)); clientData.Save(); } } return purchaseInfo; }
public override NBrightInfo UpdatePercentUsage(int portalId, int userId, NBrightInfo purchaseInfo) { var discountcode = purchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode"); if (!purchaseInfo.GetXmlPropertyBool("genxml/discountprocessed")) { if (userId > 0) { if (discountcode == "") return purchaseInfo; var clientData = new ClientData(portalId, userId); if (clientData.DiscountCodes.Count > 0) { var list = clientData.DiscountCodes; foreach (var d in list) { if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower()) { var usageleft = d.GetXmlPropertyDouble("genxml/textbox/usageleft"); var used = d.GetXmlPropertyDouble("genxml/textbox/used"); d.SetXmlPropertyDouble("genxml/textbox/usageleft", (usageleft - 1)); d.SetXmlPropertyDouble("genxml/textbox/used", (used + 1)); } } clientData.UpdateDiscountCodeList(list); clientData.Save(); purchaseInfo.SetXmlProperty("genxml/discountprocessed", "True"); } } var objCtrl = new NBrightBuyController(); var dis = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode); if (dis != null) { var usage = dis.GetXmlPropertyDouble("genxml/textbox/usage"); dis.SetXmlPropertyDouble("genxml/textbox/usage", (usage + 1)); objCtrl.Update(dis); purchaseInfo.SetXmlProperty("genxml/discountprocessed", "True"); } } return purchaseInfo; }