private static void CheckDiscountConditions(Line line, decimal lineSubTotal, Discount discount, ICollection <ReciptLineItem> items) { var qualifiesForDiscount = discount.Condition(line); var item = new ReciptLineItem(); //There may be other discounts applied to this line. We need to ensure that we don't stack the discounts. Discounts are compounding. var addedDiscounts = items.Sum(s => s.Total); if (qualifiesForDiscount) { //We don't want to have discount that is greater than total. if (discount.Fixed.HasValue && (discount.Fixed.Value) < lineSubTotal + addedDiscounts) { item.Description = discount.Message; item.Total = discount.Fixed.Value * -1; items.Add(item); } if (discount.Percentage.HasValue) { //Make sure that if other discounts are taken into account. var discounted = ((lineSubTotal + addedDiscounts) * discount.Percentage.Value); item.Description = discount.Message; item.Total = discounted * -1; items.Add(item); } } }
private static void CheckDiscountConditions(Line line, decimal lineSubTotal, Discount discount, ICollection<ReciptLineItem> items) { var qualifiesForDiscount = discount.Condition(line); var item = new ReciptLineItem(); //There may be other discounts applied to this line. We need to ensure that we don't stack the discounts. Discounts are compounding. var addedDiscounts = items.Sum(s => s.Total); if (qualifiesForDiscount) { //We don't want to have discount that is greater than total. if (discount.Fixed.HasValue && (discount.Fixed.Value) < lineSubTotal + addedDiscounts) { item.Description = discount.Message; item.Total = discount.Fixed.Value * -1; items.Add(item); } if (discount.Percentage.HasValue) { //Make sure that if other discounts are taken into account. var discounted = ((lineSubTotal + addedDiscounts) * discount.Percentage.Value); item.Description = discount.Message; item.Total = discounted * -1; items.Add(item); } } }