/// <summary> /// Combines any items in the collection that have equivalent data. /// <param name="save">Flag indicating whether or not to persist changes.</param> /// </summary> public void Combine(bool save) { // WE NEED TO TRACK PARENT ITEMS THAT ARE COMBINED Dictionary <int, int> combineMapping = new Dictionary <int, int>(); // LOOP THE BASKET ITEM COLLECTION AND COMBINE ROOT LEVEL PRODUCTS for (int thisIndex = 0; thisIndex < this.Count; thisIndex++) { BasketItem thisItem = this[thisIndex]; // ONLY CHECK ROOT LEVEL PRODUCTS if (thisItem.OrderItemType == OrderItemType.Product && !thisItem.IsChildItem) { // SEE IF WE HAVE ANY MATCHES TO COMBINE int matchIndex = FindNextIndexForCombine(thisIndex); while (matchIndex > -1) { BasketItem matchItem = this[matchIndex]; // TRACK NEW PARENT MAPPING FOR CHILD ITEMS if (matchItem.BasketItemId > 0) { combineMapping[matchItem.BasketItemId] = thisItem.BasketItemId; } // COMBINE QUANTITIES, BE CAREFUL NOT TO EXCEED SHORT LIMIT int newQuantity = thisItem.Quantity + matchItem.Quantity; thisItem.Quantity = (newQuantity > short.MaxValue ? short.MaxValue : (short)newQuantity); this.TrackedRemoveAt(matchIndex); // SEE IF WE HAVE ANOTHER MATCH matchIndex = FindNextIndexForCombine(thisIndex); } } } // UPDATE PARENT IDS THAT HAVE CHANGED AS A RESULT OF THE COMBINE Dictionary <int, int> savedParentMappings = new Dictionary <int, int>(); foreach (BasketItem thisItem in this) { if (thisItem.IsChildItem && combineMapping.ContainsKey(thisItem.ParentItemId)) { thisItem.ParentItemId = combineMapping[thisItem.ParentItemId]; } } // LOOP THE BASKET ITEM COLLECTION AND TO OPERATE ON CHILD ITEMS OrderItemType[] combineTypes = new OrderItemType[] { OrderItemType.Product, OrderItemType.Coupon, OrderItemType.Discount }; for (int thisIndex = 0; thisIndex < this.Count; thisIndex++) { BasketItem thisItem = this[thisIndex]; // ONLY CHECK CHILD ITEMS OF THE SPECIFIED TYPES // AND WHO HAVE PARENTS THAT HAVE BEEN IDENTIFIED IN THE COLLECTION if (thisItem.IsChildItem) { // COMBINE CHILD PRODUCTS, DISCOUNTS, AND COUPONS if (Array.IndexOf(combineTypes, thisItem.OrderItemType) > -1) { // SEE IF WE HAVE ANY MATCHES TO COMBINE int matchIndex = FindNextIndexForCombine(thisIndex); while (matchIndex > -1) { BasketItem matchItem = this[matchIndex]; if (thisItem.OrderItemType == OrderItemType.Product) { // COMBINE QUANTITIES, BE CAREFUL NOT TO EXCEED SHORT LIMIT int newQuantity = thisItem.Quantity + matchItem.Quantity; thisItem.Quantity = (newQuantity > short.MaxValue ? short.MaxValue : (short)newQuantity); } else { // COUPON OR DISCOUNT MAINTAINS ONE QUANTITY, ALTER PRICE INSTEAD thisItem.Price += matchItem.Price; } // REMOVE THE MATCH ITEM FROM THE COLLECTION this.TrackedRemoveAt(matchIndex); // SEE IF WE HAVE ANOTHER MATCH matchIndex = FindNextIndexForCombine(thisIndex); } } } } // LOOP COLLECTION IN REVERSE AND REMOVE ZERO QUANTITY ITEMS for (int i = this.Count - 1; i >= 0; i--) { if (this[i].Quantity < 1) { this.TrackedRemoveAt(i); } } // IF INDICATED, PERSIST CHANGES TO THE DATABASE if (save) { this.Save(); } }
public OrderItem(string path, OrderItemType type) { this.Path = path; this.Type = type; }
public OrderItem BuildOrderItem(int key, string name, float price, int quantity, OrderItemType type) { return(new OrderItem(BuildItem(key, name, price), quantity, type)); }
public FillableOrderItem(OrderItemType itemType, CookState cookState, float percentFilled) : base(itemType, cookState) { PercentFilled = percentFilled; }
public static IEnumerable <IOrderItem> ToOrderItems(this IEnumerable <CartLine> lines) { foreach (var line in lines) { yield return(new OrderItem(line.Product.Reference, line.Product.Name, OrderItemType.FromValue(line.Product.Type), line.Product.Class, line.Quantity, "pcs", new Amount(line.Product.Price), 0, new Amount(line.CalculateTotal()), new Amount(line.Product.VatPercentage == 0 ? 0 : line.CalculateTotal() * line.Product.VatPercentage / 100))); } }
protected void ChangeShipMethodOKButton_Click(object source, EventArgs e) { int shipmentId = AlwaysConvert.ToInt(Request.Form[ChangeShipMethodShipmentId.UniqueID]); int index = _Order.Shipments.IndexOf(shipmentId); if (index > -1) { // WE FOUND THE TARGET SHIPMENT. REMOVE OLD SHIPPING LINE ITEMS OrderShipment shipment = _Order.Shipments[index]; for (int i = shipment.OrderItems.Count - 1; i >= 0; i--) { OrderItemType itemType = shipment.OrderItems[i].OrderItemType; if (itemType == OrderItemType.Shipping || itemType == OrderItemType.Handling) { shipment.OrderItems.DeleteAt(i); } } // SEE IF WE HAVE A NEW SELECTED SHIPMETHOD int shipMethodId = AlwaysConvert.ToInt(Request.Form[NewShipMethod.UniqueID]); ShipMethod shipMethod = ShipMethodDataSource.Load(shipMethodId); if (shipMethod != null) { ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment); if (rate != null) { // ADD NEW SHIPPING LINE ITEMS TO THE ORDER OrderItem shipRateLineItem = new OrderItem(); shipRateLineItem.OrderId = _Order.Id; shipRateLineItem.OrderItemType = OrderItemType.Shipping; shipRateLineItem.OrderShipmentId = shipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Rate; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.TaxCodeId; shipRateLineItem.Save(); shipment.OrderItems.Add(shipRateLineItem); if (rate.Surcharge > 0) { shipRateLineItem = new OrderItem(); shipRateLineItem.OrderId = _Order.Id; shipRateLineItem.OrderItemType = OrderItemType.Handling; shipRateLineItem.OrderShipmentId = shipmentId; shipRateLineItem.Name = shipMethod.Name; shipRateLineItem.Price = rate.Surcharge; shipRateLineItem.Quantity = 1; shipRateLineItem.TaxCodeId = shipMethod.TaxCodeId; shipRateLineItem.Save(); shipment.OrderItems.Add(shipRateLineItem); } //Add the Tracking Number ShipGateway shipGateway = shipMethod.ShipGateway; foreach (TrackingNumber tn in shipment.TrackingNumbers) { tn.ShipGateway = shipGateway; } } } // UPDATE THE SHIPMENT WITH NEW METHOD ASSOCIATION shipment.ShipMethodId = shipMethodId; shipment.ShipMethodName = (shipMethod != null ? shipMethod.Name : string.Empty); shipment.Save(); // RELOAD ORDER AND REBIND THE PAGE FOR UPDATED INFO _Order = OrderDataSource.Load(_Order.Id); BindShipmentsGrid(); } }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="OrderItemType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => OrderItemType.CreateFrom(sourceValue);
public static OrderItemCollection LoadForOrderItemType(OrderItemType orderItemType, DateTime startDate, DateTime endDate, int maximumRows, int startRowIndex) { //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + OrderItem.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_OrderItems"); selectQuery.Append(" WHERE OrderItemTypeId = @orderItemType"); selectQuery.Append(" AND OrderId IN ( SELECT OrderId From ac_Orders WHERE StoreId = @storeId"); if (startDate > DateTime.MinValue) { //CONVERT DATE TO UTC startDate = LocaleHelper.FromLocalTime(startDate); selectQuery.Append(" AND OrderDate >= @startDate"); } if (endDate > DateTime.MinValue) { //CONVERT DATE TO UTC endDate = LocaleHelper.FromLocalTime(endDate); selectQuery.Append(" AND OrderDate <= @endDate"); } selectQuery.Append(")"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@orderItemType", System.Data.DbType.Int32, orderItemType); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId); if (startDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, startDate); } if (endDate > DateTime.MinValue) { database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, endDate); } //EXECUTE THE COMMAND OrderItemCollection results = new OrderItemCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { OrderItem orderItem = new OrderItem(); OrderItem.LoadDataReader(orderItem, dr); results.Add(orderItem); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public PartLaborListAdapter(List <Dictionary <string, object> > items, OrderItemType orderItemType, bool readyOrder = false) { this.Items = items; this.readyOrder = readyOrder; this.orderItemType = orderItemType; }
public static OrderItemCollection LoadForOrderItemType(OrderItemType orderItemType, DateTime startDate, DateTime endDate) { return(LoadForOrderItemType(orderItemType, startDate, endDate, 0, 0)); }
public OrderItemListViewModel(OrderItemType type) { Type = type; }
public SearchParameter(OrderItemType itemType, string code) : this(itemType, code, -1, -1) { }
public OrderItem(Item item, int quantity, OrderItemType type) { Item = item; Quantity = quantity; Type = type; }
public void GetList_WithFilter(OrderItemType type, List <OrderItem> expected) { var actual = repository.GetList(type); AssertOrderItems(actual, expected); }