public decimal GetSum() { var plainSum = GetPlainSum(); var discount = CalculateDiscounts(Discounts.Where(x => x.DiscountType == (int)DiscountType.Percent), plainSum); var tax = CalculateTax(plainSum, discount); var services = CalculateServices(TaxServices, plainSum - discount, tax); return((plainSum - discount + services + tax) - Discounts.Where(x => x.DiscountType != (int)DiscountType.Percent).Sum(x => x.Amount)); }
private void CalculateDiscount() { //total discount from giftcards decimal giftCardDiscount = Discounts.Where(x => x.GetType() == typeof(GiftVoucher)).Sum(x => x.Amount); //we know we can only have one offer voucher, so SingleOrDefault will either return the voucher, or null OfferVoucher voucher = (OfferVoucher)Discounts.SingleOrDefault(x => x.GetType() == typeof(OfferVoucher)); if (voucher == null) { DiscountTotal = giftCardDiscount; return; } decimal voucherDiscount = 0; //if the voucher is applied to a certain category, return the sum of products in the category, else return the sum of all the products in the basket. decimal voucherCategoryProductTotal = voucher.Category != null?Products.Where(x => x.Product.Category == voucher.Category).Sum(x => x.Total) : SubTotal; voucherDiscount = voucherCategoryProductTotal > voucher.Amount ? voucher.Amount : voucherCategoryProductTotal; //if the discountable total is less than the discounts added, then the max discount is used - this is because giftcards aren't available for discount. DiscountTotal = DiscountableTotal < giftCardDiscount + voucherDiscount ? DiscountableTotal : giftCardDiscount + voucherDiscount; }
public DiscountRuleDTO GetDiscount(decimal subtotal) { return(Discounts.Where(d => d.CheckRange(subtotal)).FirstOrDefault()); }
public Discount GetAppliedDiscount() { return(HasDiscount ? Discounts.Where(x => x.EndDate >= DateTime.Now).MinBy(x => x.CalculateDiscountedPrice(Price)) : null); }
public decimal GetRoundingTotal() { return(CalculateDiscounts(Discounts.Where(x => x.DiscountType != (int)DiscountType.Percent), 0)); }
public decimal GetDiscountTotal() { decimal sum = GetPlainSum(); return(CalculateDiscounts(Discounts.Where(x => x.DiscountType == (int)DiscountType.Percent), sum)); }