/// <summary> /// Builds the cashflows. /// </summary> /// <returns></returns> public Cashflows Build() { //TODO what about the cash flow match parameter? var cashflows = new Cashflows { paymentCalculationPeriod = Coupons.Select(priceableCoupon => priceableCoupon.Build()).ToArray() }; return(cashflows); }
public PseudoCart ToPseudo() { var pseudoCart = new PseudoCart { Cart = Contents.Select(item => item.ToPseudo()).ToList(), Coupons = Coupons.Select(coupon => coupon.Id).Distinct().ToList() }; return(pseudoCart); }
/// <summary> /// Aggregates the metric. /// </summary> /// <param name="metric">The metric.</param> /// <param name="valuationDate">The vluation date. </param> /// <returns></returns> public Decimal AggregateMetric(string metric, DateTime valuationDate) { var enumMetric = EnumHelper.Parse <InstrumentMetrics>(metric); var childControllerValuations = new List <AssetValuation>(); if (Coupons != null) { childControllerValuations.AddRange(Coupons.Select(cashflow => GetValue(cashflow.CalculationResults, valuationDate))); } if (Exchanges != null) { childControllerValuations.AddRange(Exchanges.Select(principal => GetValue(principal.CalculationResults, valuationDate))); } var result = AggregateMetric(enumMetric, childControllerValuations); return(result); }
/// <summary> /// Builds the cashflows. /// </summary> /// <returns></returns> protected Cashflows BuildCashflows() { //TODO what about the cash flow match parameter? var cashflows = new Cashflows { paymentCalculationPeriod = Coupons.Select(priceableCoupon => priceableCoupon.Build()).ToArray() }; if (Exchanges != null) { var principalExchanges = Exchanges.Select(principalExchange => principalExchange.Build()).ToArray(); if (principalExchanges.Any()) { cashflows.principalExchange = principalExchanges; } } return(cashflows); }
public override object Clone() { var result = base.Clone() as ShoppingCart; result.HandlingTotal = HandlingTotal?.Clone() as Money; result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money; result.DiscountAmount = DiscountAmount?.Clone() as Money; result.Total = Total?.Clone() as Money; result.SubTotal = SubTotal?.Clone() as Money; result.SubTotalWithTax = SubTotalWithTax?.Clone() as Money; result.ShippingPrice = ShippingPrice?.Clone() as Money; result.ShippingPriceWithTax = ShippingPriceWithTax?.Clone() as Money; result.ShippingTotal = ShippingTotal?.Clone() as Money; result.ShippingTotalWithTax = ShippingTotalWithTax?.Clone() as Money; result.PaymentPrice = PaymentPrice?.Clone() as Money; result.PaymentPriceWithTax = PaymentPriceWithTax?.Clone() as Money; result.PaymentTotal = PaymentTotal?.Clone() as Money; result.PaymentTotalWithTax = PaymentTotalWithTax?.Clone() as Money; result.HandlingTotal = HandlingTotal?.Clone() as Money; result.HandlingTotalWithTax = HandlingTotalWithTax?.Clone() as Money; result.DiscountTotal = DiscountTotal?.Clone() as Money; result.DiscountTotalWithTax = DiscountTotalWithTax?.Clone() as Money; result.TaxTotal = TaxTotal?.Clone() as Money; if (Discounts != null) { result.Discounts = new List <Discount>(Discounts.Select(x => x.Clone() as Discount)); } if (TaxDetails != null) { result.TaxDetails = new List <TaxDetail>(TaxDetails.Select(x => x.Clone() as TaxDetail)); } if (DynamicProperties != null) { result.DynamicProperties = new List <DynamicProperty>(DynamicProperties.Select(x => x.Clone() as DynamicProperty)); } if (ValidationErrors != null) { result.ValidationErrors = new List <ValidationError>(ValidationErrors.Select(x => x.Clone() as ValidationError)); } if (Addresses != null) { result.Addresses = new List <Address>(Addresses.Select(x => x.Clone() as Address)); } if (Items != null) { result.Items = new List <LineItem>(Items.Select(x => x.Clone() as LineItem)); } if (Payments != null) { result.Payments = new List <Payment>(Payments.Select(x => x.Clone() as Payment)); } if (Shipments != null) { result.Shipments = new List <Shipment>(Shipments.Select(x => x.Clone() as Shipment)); } if (Coupons != null) { result.Coupons = new List <Coupon>(Coupons.Select(x => x.Clone() as Coupon)); } if (AvailablePaymentMethods != null) { result.AvailablePaymentMethods = new List <PaymentMethod>(AvailablePaymentMethods.Select(x => x.Clone() as PaymentMethod)); } return(result); }
public virtual ShoppingCart ToModel(ShoppingCart cart) { if (cart == null) { throw new ArgumentNullException(nameof(cart)); } cart.Id = Id; cart.CreatedBy = CreatedBy; cart.CreatedDate = CreatedDate; cart.ModifiedBy = ModifiedBy; cart.ModifiedDate = ModifiedDate; cart.StoreId = StoreId; cart.Fee = Fee; cart.FeeWithTax = FeeWithTax; cart.Status = Status; cart.PurchaseOrderNumber = PurchaseOrderNumber; cart.Currency = Currency; cart.ValidationType = ValidationType; cart.CustomerId = CustomerId; cart.CustomerName = CustomerName; cart.IsAnonymous = IsAnonymous; cart.IsRecuring = IsRecuring; cart.LanguageCode = LanguageCode; cart.Comment = Comment; cart.OrganizationId = OrganizationId; cart.Total = Total; cart.SubTotal = SubTotal; cart.SubTotalWithTax = SubTotalWithTax; cart.ShippingTotal = ShippingTotal; cart.ShippingTotalWithTax = ShippingTotalWithTax; cart.PaymentTotal = PaymentTotal; cart.PaymentTotalWithTax = PaymentTotalWithTax; cart.HandlingTotal = HandlingTotal; cart.HandlingTotalWithTax = HandlingTotalWithTax; cart.DiscountTotal = DiscountTotal; cart.DiscountTotalWithTax = DiscountTotalWithTax; cart.DiscountAmount = DiscountAmount; cart.TaxTotal = TaxTotal; cart.TaxPercentRate = TaxPercentRate; cart.Type = Type; cart.Name = Name; cart.Discounts = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList(); cart.Items = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList(); cart.Addresses = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList(); cart.Shipments = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).ToList(); cart.Payments = Payments.Select(x => x.ToModel(AbstractTypeFactory <Payment> .TryCreateInstance())).ToList(); cart.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList(); cart.Coupons = Coupons.Select(x => x.Code).ToList(); // Assigning single coupon to preserve backwards compatibility with previous versions of CartModule cart.Coupon = cart.Coupons.FirstOrDefault(); cart.DynamicProperties = DynamicPropertyObjectValues.GroupBy(g => g.PropertyId).Select(x => { var property = AbstractTypeFactory <DynamicObjectProperty> .TryCreateInstance(); property.Id = x.Key; property.Name = x.FirstOrDefault()?.PropertyName; property.Values = x.Select(v => v.ToModel(AbstractTypeFactory <DynamicPropertyObjectValue> .TryCreateInstance())).ToArray(); return(property); }).ToArray(); return(cart); }