private static ComboOrderData BuildComboOrder(string partyId, decimal amount, string fund) { var usd = new CurrencyData("USD"); var party = new PersonData { PartyId = partyId }; var customerParty = new CustomerPartyData { Id = partyId, Party = party }; var orderData = new OrderData { BillToCustomerParty = customerParty, SoldToCustomerParty = customerParty, Currency = usd, Lines = new OrderLineDataCollection{ new OrderLineData { Item = new GiftItemData {ItemCode = fund}, QuantityOrdered = new QuantityData(1), UnitPrice = new MonetaryAmountData(amount, usd), ExtendedAmount = new MonetaryAmountData(amount, usd) } }, }; var comboOrder = new ComboOrderData { Currency = usd, Order = orderData }; comboOrder.Payments = new RemittanceDataCollection { new RemittanceData { Amount = new MonetaryAmountData(amount, usd), PaymentMethod = new PaymentMethodData {PaymentMethodId = "CASH"}, PayorParty = new CustomerPartyData {Id = partyId, Party = party} } }; return comboOrder; }
public ICollection<Object> CreateImportCollection(string filePath) { messageBuilder = new StringBuilder(); contractsToImport = new List<Object>(); var numberOfOrders = 0; var lineNumber = 0; ObjectCount = 0; numberOfErrors = 0; ErrorLines = new Collection<String>(); ComboOrderData comboOrder = null; OrderData order = null; foreach (var line in File.ReadLines(filePath)) { lineNumber++; var pieces = new String[0]; if (line != null) pieces = line.Split(','); if (pieces.Length < 1) { AddError(line, lineNumber, "Invalid line - too few columns"); } else { var lineType = pieces[flagColumn]; switch (lineType.ToUpperInvariant()) { case "ORDER": if (comboOrder != null) { // add previous comboOrder to the list FinishComboOrder(comboOrder); } order = ProcessOrderImportRow(pieces, line, lineNumber); comboOrder = new ComboOrderData {Order = order}; numberOfOrders++; break; case "ORDERLINE": ProcessOrderLineImportRow(pieces, line, lineNumber, order); break; case "PRODUCT": ProcessProductImportRow(pieces, line, lineNumber); break; default: AddError(line, lineNumber, "Line does not start with ORDER, ORDERLINE, or PRODUCT"); break; } } } if (comboOrder != null) { // add last combo order FinishComboOrder(comboOrder); } ObjectCount = numberOfOrders; if (messageBuilder.Length > 0) { if (numberOfErrors > maxErrorsToShow) messageBuilder.AppendFormat("<li>Additional errors: {0}</li>", numberOfErrors - maxErrorsToShow); messageBuilder.Append("</ul>"); } HasErrors = numberOfErrors > 0; ErrorMessage = messageBuilder.ToString(); return contractsToImport; }
private void FinishComboOrder(ComboOrderData comboOrder) { var total = 0m; foreach (var line in comboOrder.Order.Lines) { if (line.ExtendedAmount.HasValue) total += line.ExtendedAmount.Value.Amount; } comboOrder.Currency = CommerceSettings.DefaultCurrency; comboOrder.Payments = new RemittanceDataCollection { new RemittanceData { Amount = new MonetaryAmountData(total, CommerceSettings.DefaultCurrency), PaymentMethod = new PaymentMethodData {PaymentMethodId = "CASH"}, PayorParty = comboOrder.Order.BillToCustomerParty } }; contractsToImport.Add(comboOrder); }