// Products and Line Items public Orders.LineItem ConvertProductToLineItem(Orders.IPurchasable p, OptionSelectionList selections, int quantity, MerchantTribeApplication app) { Orders.LineItem li = new Orders.LineItem(); if (p != null) { Orders.PurchasableSnapshot snapshot = p.AsPurchasable(selections, app, true); if (snapshot != null) { li.BasePricePerItem = snapshot.BasePrice; li.ProductId = snapshot.ProductId; li.ProductName = snapshot.Name; li.ProductShippingHeight = snapshot.ShippingDetails.Height; li.ProductShippingLength = snapshot.ShippingDetails.Length; li.ProductShippingWeight = snapshot.ShippingDetails.Weight; li.ProductShippingWidth = snapshot.ShippingDetails.Width; li.ProductShortDescription = snapshot.Description; li.ProductSku = snapshot.Sku; li.Quantity = quantity; li.SelectionData = snapshot.SelectionData; li.ShippingSchedule = snapshot.ShippingDetails.ShippingScheduleId; li.VariantId = snapshot.VariantId; li.TaxSchedule = snapshot.TaxScheduleId; li.ShipFromAddress = snapshot.ShippingDetails.ShippingSourceAddress; li.ShipFromMode = snapshot.ShippingDetails.ShippingSource; li.ShipFromNotificationId = snapshot.ShippingDetails.ShippingSourceId; li.ShipSeparately = snapshot.ShippingDetails.ShipSeparately; li.ExtraShipCharge = snapshot.ShippingDetails.ExtraShipFee; } } return(li); }
public bool InventoryLineItemUnreserveInventory(Orders.LineItem li, int qty) { if (qty < 0) { throw new ArgumentException("Cannot be negative", "qty"); } return(InventoryLineItemUnreserveSingleItemInventory(li.ProductId, li.VariantId, qty)); }
public bool InventoryLineItemReturnQuantity(Orders.LineItem li, int receivedQuantity, bool returnToInventory) { li.QuantityReturned += receivedQuantity; if (returnToInventory) { return(InventoryAdjustAvailableQuantity(li.ProductId, li.VariantId, receivedQuantity)); } else { return(true); } }
// Products and Line Items public Orders.LineItem ConvertProductToLineItem(Orders.IPurchasable p, OptionSelectionList selections, int quantity, MerchantTribeApplication app) { Orders.LineItem li = new Orders.LineItem(); if (p != null) { Orders.PurchasableSnapshot snapshot = p.AsPurchasable(selections, app, true); if (snapshot != null) { li.BasePricePerItem = snapshot.BasePrice; li.ProductId = snapshot.ProductId; li.ProductName = snapshot.Name; li.ProductShippingHeight = snapshot.ShippingDetails.Height; li.ProductShippingLength = snapshot.ShippingDetails.Length; li.ProductShippingWeight = snapshot.ShippingDetails.Weight; li.ProductShippingWidth = snapshot.ShippingDetails.Width; li.ProductShortDescription = snapshot.Description; li.ProductSku = snapshot.Sku; li.Quantity = quantity; li.SelectionData = snapshot.SelectionData; li.ShippingSchedule = snapshot.ShippingDetails.ShippingScheduleId; li.VariantId = snapshot.VariantId; li.TaxSchedule = snapshot.TaxScheduleId; li.ShipFromAddress = snapshot.ShippingDetails.ShippingSourceAddress; li.ShipFromMode = snapshot.ShippingDetails.ShippingSource; li.ShipFromNotificationId = snapshot.ShippingDetails.ShippingSourceId; li.ShipSeparately = snapshot.ShippingDetails.ShipSeparately; li.ExtraShipCharge = snapshot.ShippingDetails.ExtraShipFee; } } return li; }
public bool InventoryLineItemUnreserveInventory(Orders.LineItem li) { return(InventoryLineItemUnreserveInventory(li, li.Quantity)); }
public int InventoryLineItemReserveInventory(Orders.LineItem li) { return(InventoryLineItemReserveInventory(li, li.Quantity)); }
public bool InventoryLineItemUnShipQuantity(Orders.LineItem li, int quantity) { li.QuantityShipped -= quantity; InventoryUnshipQuantity(li.ProductId, li.VariantId, quantity); return(true); }
// working with local dates and times public static void GenerateInvoiceForStore(Store s, DateTime invoiceDateLocal, MerchantTribeApplication app) { // Create an Order Orders.Order o = new Orders.Order(); o.StoreId = WebAppSettings.BillingStoreId; app.OrderServices.Orders.Create(o); o.Notes.Add(new Orders.OrderNote() { IsPublic = false, Note = "Auto Generated By Invoicing System" }); // Base Rate Orders.LineItem li = new Orders.LineItem(); li.BasePricePerItem = s.CurrentPlanRate; li.ProductName = "BV Commerce Hosted: " + s.PlanName; li.ProductSku = "BVH" + s.PlanId; li.Quantity = 1; li.QuantityShipped = 1; li.ShippingSchedule = -1; o.Items.Add(li); // need to add Percent of sales decimal lastMonthSales = 0; // End date should be immediately before bill not, not on the bill date DateTime localEnd = Dates.MaxOutTime(invoiceDateLocal); localEnd = localEnd.AddDays(-1); DateTime localStart = Dates.ZeroOutTime(invoiceDateLocal).AddMonths(-1); lastMonthSales = app.OrderServices.Transactions.FindBillableTransactionTotal(localStart.ToUniversalTime(), localEnd.ToUniversalTime(), s.Id); Orders.LineItem li2 = new Orders.LineItem(); Decimal multiplier = s.CurrentPlanPercent / 100; Decimal transFees = Math.Round(multiplier * lastMonthSales, 2, MidpointRounding.AwayFromZero); li2.BasePricePerItem = transFees; li2.ProductName = "Transaction Fees:"; li2.ProductShortDescription = s.CurrentPlanPercent + "% of " + lastMonthSales.ToString("c"); li2.ProductShortDescription += " " + localStart.ToShortDateString() + " to " + localEnd.ToShortDateString(); li2.ProductSku = "BVHTF"; li2.Quantity = 1; li2.QuantityShipped = 1; li2.ShippingSchedule = -1; o.Items.Add(li2); List<UserAccount> users = app.AccountServices.FindAdminUsersByStoreId(s.Id); if (users != null) { if (users.Count > 0) { UserAccount u = users[0]; o.UserEmail = u.Email; Service svc = new Service(WebAppSettings.ApplicationConnectionString); BillingAccount act = svc.Accounts.FindOrCreate(u.Email); if (act != null) { o.BillingAddress.RegionData.Abbreviation = string.Empty; o.BillingAddress.RegionName = string.Empty; o.BillingAddress.PostalCode = act.BillingZipCode; o.BillingAddress.FirstName = act.CreditCard.CardHolderName; o.BillingAddress.Company = s.StoreName; app.CalculateOrder(o); Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(o, app); payManager.CreditCardAddInfo(act.CreditCard, o.TotalGrand); o.OrderNumber = app.OrderServices.GenerateNewOrderNumber(WebAppSettings.BillingStoreId).ToString(); o.StatusCode = Orders.OrderStatusCode.Received; o.IsPlaced = true; o.TimeOfOrderUtc = DateTime.UtcNow; o.EvaluateCurrentShippingStatus(); app.OrderServices.Orders.Update(o); } } } }
// working with local dates and times public static void GenerateInvoiceForStore(Store s, DateTime invoiceDateLocal, MerchantTribeApplication app) { // Create an Order Orders.Order o = new Orders.Order(); o.StoreId = WebAppSettings.BillingStoreId; app.OrderServices.Orders.Create(o); o.Notes.Add(new Orders.OrderNote() { IsPublic = false, Note = "Auto Generated By Invoicing System" }); // Base Rate Orders.LineItem li = new Orders.LineItem(); li.BasePricePerItem = s.CurrentPlanRate; li.ProductName = "BV Commerce Hosted: " + s.PlanName; li.ProductSku = "BVH" + s.PlanId; li.Quantity = 1; li.QuantityShipped = 1; li.ShippingSchedule = -1; o.Items.Add(li); // need to add Percent of sales decimal lastMonthSales = 0; // End date should be immediately before bill not, not on the bill date DateTime localEnd = Dates.MaxOutTime(invoiceDateLocal); localEnd = localEnd.AddDays(-1); DateTime localStart = Dates.ZeroOutTime(invoiceDateLocal).AddMonths(-1); lastMonthSales = app.OrderServices.Transactions.FindBillableTransactionTotal(localStart.ToUniversalTime(), localEnd.ToUniversalTime(), s.Id); Orders.LineItem li2 = new Orders.LineItem(); Decimal multiplier = s.CurrentPlanPercent / 100; Decimal transFees = Math.Round(multiplier * lastMonthSales, 2); li2.BasePricePerItem = transFees; li2.ProductName = "Transaction Fees:"; li2.ProductShortDescription = s.CurrentPlanPercent + "% of " + lastMonthSales.ToString("c"); li2.ProductShortDescription += " " + localStart.ToShortDateString() + " to " + localEnd.ToShortDateString(); li2.ProductSku = "BVHTF"; li2.Quantity = 1; li2.QuantityShipped = 1; li2.ShippingSchedule = -1; o.Items.Add(li2); List <UserAccount> users = app.AccountServices.FindAdminUsersByStoreId(s.Id); if (users != null) { if (users.Count > 0) { UserAccount u = users[0]; o.UserEmail = u.Email; Service svc = new Service(WebAppSettings.ApplicationConnectionString); BillingAccount act = svc.Accounts.FindOrCreate(u.Email); if (act != null) { o.BillingAddress.RegionData.Abbreviation = string.Empty; o.BillingAddress.RegionName = string.Empty; o.BillingAddress.PostalCode = act.BillingZipCode; o.BillingAddress.FirstName = act.CreditCard.CardHolderName; o.BillingAddress.Company = s.StoreName; app.CalculateOrder(o); Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(o, app); payManager.CreditCardAddInfo(act.CreditCard, o.TotalGrand); o.OrderNumber = app.OrderServices.GenerateNewOrderNumber(WebAppSettings.BillingStoreId).ToString(); o.StatusCode = Orders.OrderStatusCode.Received; o.IsPlaced = true; o.TimeOfOrderUtc = DateTime.UtcNow; o.EvaluateCurrentShippingStatus(); app.OrderServices.Orders.Update(o); } } } }