public double GetTotalAmountAfterDiscounts() { var cartTotal = LineItems.Sum(a => a.Product.UnitPrice * a.Quantity); var discountTotal = GetCampaignDiscount() + GetCouponDiscount(); return(cartTotal - discountTotal); }
public TotalsMeta CalculateTotalsMeta() { return(new TotalsMeta { HighestDeposit = LineItems?.Where(x => x.Amount > 0)?.Max(x => x.Amount) ?? 0, HighestWithdrawal = LineItems?.Where(x => x.Amount < 0)?.Min(x => x.Amount) ?? 0, LowestDeposit = LineItems?.Where(x => x.Amount > 0)?.Min(x => x.Amount) ?? 0, LowestWithdrawal = LineItems?.Where(x => x.Amount < 0)?.Max(x => x.Amount) ?? 0, TotalsTally = LineItems?.Sum(x => x.Amount) == (EndingBalance - StartingBalance) }); }
public double GetCouponDiscount() { if (AppliedCoupon == null) { return(default(double)); } var cartTotal = LineItems.Sum(a => a.Product.UnitPrice * a.Quantity) - GetCampaignDiscount(); return(_couponCalculator.CalculateFor(AppliedCoupon, cartTotal)); }
/// <summary> /// adds line item to collection and recalculates totals /// </summary> /// <param name="line"></param> public void AddLineItem(LineItem item) { item.Discount = _utilities.GetVolumeDiscount(item); item.ItemTotal = Math.Round(item.Bike.Price * item.Discount * item.Quantity, 2); this.LineItems.Add(item); this.SubTotal = Math.Round(LineItems.Sum(l => l.ItemTotal), 2); this.Tax = Math.Round(SubTotal * _utilities.GetSalesTaxRate(this.Company.Address), 2); this.Total = Math.Round(SubTotal + Tax, 2); }
public decimal CalculateOrderPrice() { decimal totalDiscount = 0; decimal totalPrice = LineItems.Sum(i => i.UnitPrice * i.Quantity); foreach (var item in Promotions) { totalDiscount += item.GetDiscount(LineItems); } decimal finalPrice = totalPrice - totalDiscount; Console.WriteLine($"OrderID: {this.Id} => Total price: {totalPrice.ToString("0.00")} | Discount: {totalDiscount.ToString("0.00")} | Final price: {finalPrice.ToString("0.00")}"); return finalPrice; }
public override int GetHashCode() { unchecked { var hashCode = (InvoiceId != null ? InvoiceId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ InvoiceNumber; hashCode = (hashCode * 397) ^ (InvoiceNumberAsString != null ? InvoiceNumberAsString.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Total.GetHashCode(); hashCode = (hashCode * 397) ^ Subtotal.GetHashCode(); hashCode = (hashCode * 397) ^ Tax.GetHashCode(); hashCode = (hashCode * 397) ^ TaxPercentage.GetHashCode(); hashCode = (hashCode * 397) ^ InvoiceDate.GetHashCode(); hashCode = (hashCode * 397) ^ (ContractName != null ? ContractName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ PeriodStartDate.GetHashCode(); hashCode = (hashCode * 397) ^ PeriodEndDate.GetHashCode(); hashCode = (hashCode * 397) ^ (Currency != null ? Currency.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (From != null ? From.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (To != null ? To.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LineItems?.Sum(x => x.GetHashCode()) ?? 0); return(hashCode); } }
public virtual decimal TotalWithTax() { return(LineItems.Sum(amt => amt.TotalWithTax())); }
/// <summary> /// Total is sum of all line unit amts * quantities /// </summary> public virtual decimal Total() { return(LineItems.Sum(amt => amt.Quantity * amt.UnitPrice)); }
public void CalculateTotalPrice() { Price = LineItems.Sum(i => i.Price * i.Quantity); SalesTax = Price * GetSalesTax(); }
private void CalculateTotal() { Total = LineItems.Sum(l => l.DiscountedSubTotal); }
/// <summary> /// GetTotal should return the sum of (Cost * Quantity) for each line item /// </summary> public decimal GetTotal() { return((decimal)LineItems.Sum(x => x.Cost * x.Quantity)); }