public void Calculate_ShouldReturnDiscountResult_WithCorrectProductsAndModel() { // Arrange IQuantityDiscountCalculator timespanDiscountCalculator = new QuantityDiscountCalculator(); List <Product> products = new List <Product>() { new Product() { Id = 1, Name = "Beans", PluralName = "Beans", Price = 0.65m }, new Product() { Id = 2, Name = "Bread", PluralName = "Breads", Price = 0.8m }, new Product() { Id = 3, Name = "Milk", PluralName = "Milk", Price = 1.3m }, new Product() { Id = 4, Name = "Apple", PluralName = "Apples", Price = 1.0m }, }; QuantityDiscount quantityDiscount = new QuantityDiscount() { Id = 1, BuyingProduct = products[0], Quantity = 2, DiscountedProduct = products[1], DiscountPercentage = 0.5f, IsActive = true }; IEnumerable <BasketItem> items = new List <BasketItem>() { new BasketItem() { Product = new BasketItemProduct() { Id = 1, Name = "Beans", PluralName = "Beans", Price = 0.65m }, Quantity = 2 }, new BasketItem() { Product = new BasketItemProduct() { Id = 2, Name = "Bread", PluralName = "Breads", Price = 0.8m }, Quantity = 1 }, }; // Act DiscountResult discountResult = timespanDiscountCalculator.Calculate(items, quantityDiscount); // Assert Assert.Equal(0.5, discountResult.DiscountPercentage); Assert.Equal(0.40m, discountResult.DiscountedPrice); Assert.Equal("Breads", discountResult.ProductPluralName); }
public virtual QuantityDiscount UpdateQuantityDiscount(QuantityDiscount entity) { if (entity.IsTransient()) { return(entity); } QuantityDiscount other = GetQuantityDiscount(entity.QuantityDiscountId); if (entity.Equals(other)) { return(entity); } string sql = @"Update QuantityDiscount set [QuantityDiscountGUID]=@QuantityDiscountGUID , [Name]=@Name , [DisplayOrder]=@DisplayOrder , [ExtensionData]=@ExtensionData , [DiscountType]=@DiscountType , [CreatedOn]=@CreatedOn where QuantityDiscountID=@QuantityDiscountID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@QuantityDiscountID", entity.QuantityDiscountId) , new SqlParameter("@QuantityDiscountGUID", entity.QuantityDiscountGuid) , new SqlParameter("@Name", entity.Name) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@DiscountType", entity.DiscountType) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetQuantityDiscount(entity.QuantityDiscountId)); }
public void When_constructed() { var sut = new QuantityDiscount("apple", 3, 2.00m); Assert.That(sut.Barcode, Is.EqualTo("apple")); Assert.That(sut.DiscountQuantity, Is.EqualTo(3)); Assert.That(sut.DiscountPrice, Is.EqualTo(2.00m)); }
public FQuantityDiscount() { InitializeComponent(); quantityDiscountModel = new QuantityDiscountModel(); listDiscount = new DataTable(); rowIndex = 0; seletedFunction = 0; quantityDiscount = new QuantityDiscount(); }
// To display the discounted amount. protected string ShowDiscountAmount(object QuantityDiscountID, object DiscountPercent) { Customer ThisCustomer = ((AspDotNetStorefrontPrincipal)HttpContext.Current.User).ThisCustomer; if (QuantityDiscount.isFixedQuantityDiscount(Convert.ToInt32(QuantityDiscountID))) { return(Localization.CurrencyStringForDisplayWithExchangeRate((Decimal)DiscountPercent, ThisCustomer.CurrencySetting)); } else { return(Convert.ToDecimal(DiscountPercent).ToString("N" + AppLogic.AppConfigNativeInt("QuantityDiscount.PercentDecimalPlaces")) + "%"); } }
public DiscountItem() { SpendLevels = new List <SpendLevel>(); RestrictedProductIds = new List <int>(); DiscountSchedule = new List <Schedule>(); AdvancedQuantityDiscount = new QuantityDiscount { BuyQuantity = 1, GetQuantity = 1 }; RestrictedPackageIds = new List <int>(); MinimumPacksEligibleIds = new List <int>(); }
public virtual QuantityDiscount QuantityDiscountFromDataRow(DataRow dr) { if (dr == null) { return(null); } QuantityDiscount entity = new QuantityDiscount(); entity.QuantityDiscountId = (System.Int32)dr["QuantityDiscountID"]; entity.QuantityDiscountGuid = (System.Guid)dr["QuantityDiscountGUID"]; entity.Name = dr["Name"].ToString(); entity.DisplayOrder = (System.Int32)dr["DisplayOrder"]; entity.ExtensionData = dr["ExtensionData"].ToString(); entity.DiscountType = (System.Byte)dr["DiscountType"]; entity.CreatedOn = (System.DateTime)dr["CreatedOn"]; return(entity); }
public DiscountResult Calculate(IEnumerable <BasketItem> items, QuantityDiscount model) { if (items == null) { throw new ArgumentNullException(nameof(items)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } BasketItem buyingProduct = items.FirstOrDefault(p => p.Product.Id == model.BuyingProduct.Id); if (buyingProduct == null) { return(null); } BasketItem productForDiscount = items.FirstOrDefault(p => p.Product.Id == model.DiscountedProduct.Id); if (productForDiscount == null) { return(null); } int quantity = buyingProduct.Quantity / model.Quantity; int numberOfDiscounts = quantity > productForDiscount.Quantity ? productForDiscount.Quantity : quantity; if (numberOfDiscounts == 0) { return(null); } decimal currentPrice = productForDiscount.Product.Price; decimal discountedPrice = (currentPrice * (decimal)model.DiscountPercentage) * numberOfDiscounts; DiscountResult result = new DiscountResult(); result.DiscountedPrice = discountedPrice; result.ProductPluralName = productForDiscount.Product.PluralName; result.DiscountPercentage = model.DiscountPercentage; return(result); }
private List <QuantityDiscount> GetQuantityDiscounts() { List <QuantityDiscount> quantityDiscounts = new List <QuantityDiscount>(); QuantityDiscount quantityDiscountA = new QuantityDiscount(); quantityDiscountA.DiscountPrice = 7; quantityDiscountA.MinimumQuantity = 4; quantityDiscountA.ProductCode = "A"; quantityDiscounts.Add(quantityDiscountA); QuantityDiscount quantityDiscountC = new QuantityDiscount(); quantityDiscountC.DiscountPrice = 6; quantityDiscountC.MinimumQuantity = 6; quantityDiscountC.ProductCode = "C"; quantityDiscounts.Add(quantityDiscountC); return(quantityDiscounts); }
public virtual QuantityDiscount InsertQuantityDiscount(QuantityDiscount entity) { QuantityDiscount other = new QuantityDiscount(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into QuantityDiscount ( [QuantityDiscountGUID] ,[Name] ,[DisplayOrder] ,[ExtensionData] ,[DiscountType] ,[CreatedOn] ) Values ( @QuantityDiscountGUID , @Name , @DisplayOrder , @ExtensionData , @DiscountType , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@QuantityDiscountID", entity.QuantityDiscountId) , new SqlParameter("@QuantityDiscountGUID", entity.QuantityDiscountGuid) , new SqlParameter("@Name", entity.Name) , new SqlParameter("@DisplayOrder", entity.DisplayOrder) , new SqlParameter("@ExtensionData", entity.ExtensionData ?? (object)DBNull.Value) , new SqlParameter("@DiscountType", entity.DiscountType) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetQuantityDiscount(Convert.ToInt32(identity))); } return(entity); }
public string ShowQuantityDiscountTableForAccordion(String sProductID, string HeaderText, string ID) //our version to allow display inline without changing app config "ShowQuantityDiscountTablesInline" { Customer ThisCustomer = null; try { ThisCustomer = ((AspDotNetStorefrontPrincipal)HttpContext.Current.User).ThisCustomer; } catch { } if (ThisCustomer == null) { ThisCustomer = new Customer(true); } InputValidator IV = new InputValidator("ShowQuantityDiscountTable"); int ProductID = IV.ValidateInt("ProductID", sProductID); StringBuilder results = new StringBuilder(""); bool CustomerLevelAllowsQuantityDiscounts = QuantityDiscount.CustomerLevelAllowsQuantityDiscounts(ThisCustomer.CustomerLevelID); String MainProductSKU = String.Empty; int ActiveDIDID = QuantityDiscount.LookupProductQuantityDiscountID(ProductID); bool ActiveDID = (ActiveDIDID != 0); if (!CustomerLevelAllowsQuantityDiscounts) { ActiveDID = false; } if (ActiveDID) { results.Append("<div data-role=\"collapsible\">"); results.Append("<h3>" + HeaderText + "</h3>"); results.Append("<div>" + QuantityDiscount.GetQuantityDiscountDisplayTable(ActiveDIDID, ThisCustomer.SkinID) + "</div>"); results.Append("</div>"); } return(results.ToString()); }
public bool insertQuantityDiscount(QuantityDiscount discount) { bool inserted = false; SqlConnection connection; SqlCommand command; string sql = "INSERT INTO tbQuantityDiscount VALUES(" + discount.MinQuantity + ", " + discount.MaxQuantity + ", " + discount.DiscountRate + ")"; try { connection = new ConnectDB().connectToSQL(); command = new SqlCommand(sql, connection); if (command.ExecuteNonQuery() == 1) { inserted = true; } } catch (Exception) { throw; } connection.Close(); return(inserted); }
public bool updateQuantityDiscount(QuantityDiscount quantityDiscount) { bool updated = false; SqlConnection connection; SqlCommand command; string sql = "UPDATE tbQuantityDisCount SET MinQuantity = " + quantityDiscount.MinQuantity + ", MaxQuantity = " + quantityDiscount.MaxQuantity + ", Discount = " + quantityDiscount.DiscountRate + " WHERE DiscountId = " + quantityDiscount.DiscountId; try { connection = new ConnectDB().connectToSQL(); command = new SqlCommand(sql, connection); if (command.ExecuteNonQuery() == 1) { updated = true; } } catch (Exception) { throw; } connection.Close(); return(updated); }
protected void Page_Load(object sender, System.EventArgs e) { Response.CacheControl = "private"; Response.Expires = 0; Response.AddHeader("pragma", "no-cache"); QuantityDiscountID = CommonLogic.QueryStringUSInt("QuantityDiscountID"); QuantityDiscountName = QuantityDiscount.GetQuantityDiscountName(QuantityDiscountID, LocaleSetting); if (CommonLogic.FormBool("IsSubmitByCount")) { // check for new row addition: int Low0 = CommonLogic.FormUSInt("Low_0"); int High0 = CommonLogic.FormUSInt("High_0"); String NewGUID = DB.GetNewGUID(); int NewRowID = 0; if (Low0 != 0 || High0 != 0) { // add the new row if necessary: Decimal Discount = CommonLogic.FormUSDecimal("Rate_0_" + QuantityDiscountID.ToString()); DB.ExecuteSQL("insert into QuantityDiscountTable(QuantityDiscountTableGUID,QuantityDiscountID,LowQuantity,HighQuantity,DiscountPercent) values(" + DB.SQuote(NewGUID) + "," + QuantityDiscountID.ToString() + "," + Localization.IntStringForDB(Low0) + "," + Localization.IntStringForDB(High0) + "," + Localization.DecimalStringForDB(Discount) + ")"); } using (SqlConnection dbconn = DB.dbConn()) { dbconn.Open(); using (IDataReader rs = DB.GetRS("Select QuantityDiscountTableID from QuantityDiscountTable with (NOLOCK) where QuantityDiscountTableGUID=" + DB.SQuote(NewGUID), dbconn)) { rs.Read(); NewRowID = DB.RSFieldInt(rs, "QuantityDiscountTableID"); } } // update existing rows: for (int i = 0; i <= Request.Form.Count - 1; i++) { String FieldName = Request.Form.Keys[i]; if (FieldName.IndexOf("_0_") == -1 && FieldName != "Low_0" && FieldName != "High_0" && FieldName.IndexOf("_vldt") == -1 && (FieldName.IndexOf("Rate_") != -1 || FieldName.IndexOf("Low_") != -1 || FieldName.IndexOf("High_") != -1)) { Decimal FieldVal = CommonLogic.FormUSDecimal(FieldName); // this field should be processed String[] Parsed = FieldName.Split('_'); if (FieldName.IndexOf("Rate_") != -1) { // update discount: DB.ExecuteSQL("Update QuantityDiscountTable set DiscountPercent=" + Localization.DecimalStringForDB(FieldVal) + " where QuantityDiscountTableID=" + Parsed[1]); } if (FieldName.IndexOf("Low_") != -1) { // update low value: DB.ExecuteSQL("Update QuantityDiscountTable set LowQuantity=" + FieldVal.ToString() + " where QuantityDiscountTableID=" + DB.SQuote(Parsed[1])); } if (FieldName.IndexOf("High_") != -1) { // update high value: DB.ExecuteSQL("Update QuantityDiscountTable set HighQuantity=" + FieldVal.ToString() + " where QuantityDiscountTableID=" + DB.SQuote(Parsed[1])); } } } DB.ExecuteSQL("Update QuantityDiscountTable set HighQuantity=999999 where HighQuantity=0 and LowQuantity<>0"); } if (CommonLogic.QueryStringCanBeDangerousContent("deleteByCountid").Length != 0) { DB.ExecuteSQL("delete from QuantityDiscountTable where QuantityDiscountTableID=" + CommonLogic.QueryStringCanBeDangerousContent("deleteByCountid")); } SectionTitle = "<a href=\"" + AppLogic.AdminLinkUrl("quantitydiscounts.aspx") + "\">" + AppLogic.GetString("admin.editquantitydiscounttable.QuantityDiscounts", SkinID, LocaleSetting) + "</a> - " + String.Format(AppLogic.GetString("admin.editquantitydiscounttable.ManageQuantityDiscountTable", SkinID, LocaleSetting), QuantityDiscountName); RenderHtml(); }
public IActionResult AddQuantityDiscountToProduct(Guid productId, QuantityDiscount quantityDiscount) => AddDiscountToProduct(productId, quantityDiscount);
public QuantityDiscount InsertQuantityDiscount(QuantityDiscount entity) { return(_iQuantityDiscountRepository.InsertQuantityDiscount(entity)); }
public QuantityDiscount UpdateQuantityDiscount(QuantityDiscount entity) { return(_iQuantityDiscountRepository.UpdateQuantityDiscount(entity)); }
/// <summary> /// Creates the child controls in a control derived from System.Web.UI.WebControls.CompositeControl. /// </summary> protected override void CreateChildControls() { if (cItem.ProductID > 0) { txtQuantity.Text = cItem.Quantity.ToString(); if (this.AllowEdit) { (txtQuantity as TextBox).Columns = 4; (txtQuantity as TextBox).MaxLength = 4; (txtQuantity as TextBox).ReadOnly = false; (txtQuantity as TextBox).CssClass = "mobileinput"; } //Line Item Description if (LineItemSetting != null) { lineItemDescription.LineItemDescriptionSettings = LineItemSetting; } lineItemDescription.DataSource = this.CartItem; lineItemDescription.AllowEdit = this.AllowEdit; lineItemDescription.IsMiniCart = false; lblSubTotal.Text = cItem.ExtPriceRateDisplayFormat.ToString(); lblVatDisplay.Text = cItem.VatRateDisplayFormat; lblQtyDiscount.Text = cItem.LineItemQuantityDiscount; lblSubTotal.CssClass = "shoppingcartproductprice"; lblVatDisplay.CssClass = "shoppingcartproductprice"; lblQtyDiscount.CssClass = "shoppingcartproductprice"; btnDelete.CssClass = "shoppingcartdeletebutton"; btnDelete.CommandName = "Delete"; btnDelete.CommandArgument = cItem.ShoppingCartRecordID.ToString(); Controls.Add(new LiteralControl(" <table style='width : 100%; padding-top: 10px; padding-bottom: 10px' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); if (this.DisplayMode != CartDisplayMode.MiniCart) { //LineItemDescription Controls.Add(new LiteralControl(" <td style='width: 50%;' valign='top'>")); Controls.Add(lineItemDescription); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" <td style='width: 15%;' align='left' valign='top'>")); Controls.Add(new LiteralControl(" <div>")); //check for restricted quantity if (this.CartItem.RestrictedQuantities.Count == 0 || !this.AllowEdit) { Controls.Add(txtQuantity as Control); } else { // build dropdown for restricted quantities BuildRestrictedQuantities(); Controls.Add(cboQuantity); } Controls.Add(new LiteralControl(" </div>")); Controls.Add(new LiteralControl(" </td>")); } Controls.Add(new LiteralControl(" <td style='width: 25%; padding-right:5px;' align='right' valign='top'>")); Controls.Add(new LiteralControl(" <table style='width:100% padding-right:5px;' cellpadding='0' cellspacing='0' border='0'>")); Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td style='padding-top:5px; padding-right:5px;' align='right' valign='top'>")); Controls.Add(lblSubTotal); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); if (this.DisplayMode != CartDisplayMode.MiniCart) { if (cItem.ThisShoppingCart.VatEnabled) { Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td align='right'>")); Controls.Add(lblVatDisplay); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); } if (QuantityDiscount.CustomerLevelAllowsQuantityDiscounts(cItem.ThisCustomer.CustomerLevelID)) { Controls.Add(new LiteralControl(" <tr>")); Controls.Add(new LiteralControl(" <td align='right'>")); Controls.Add(lblQtyDiscount); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); } } Controls.Add(new LiteralControl(" </table>")); Controls.Add(new LiteralControl(" </td>")); // Delete column Controls.Add(new LiteralControl(" <td style='width: 10%; padding-top:5px;' valign='top' align='right'>")); Controls.Add(btnDelete); Controls.Add(new LiteralControl(" </td>")); Controls.Add(new LiteralControl(" </tr>")); Controls.Add(new LiteralControl(" </table>")); } }
public virtual QuantityDiscount DeleteQuantityDiscount(QuantityDiscount entity) { this.DeleteQuantityDiscount(entity.QuantityDiscountId); return(entity); }