public bool Delete(bool adjustInventory = true) { IsPendingReturn = false; QuantityPendingReturn = 0; Instances.Remove(PrimaryKey); TicketItemOption.DeleteAll(this, adjustInventory); return(Delete(PrimaryKey, adjustInventory)); }
private static void RestorePreviousTicketItemOptions(TicketItem ticketItem) { TicketItemOption.DeleteAll(ticketItem, true); foreach (TicketItemOption option in ticketItem._cachedItemOptions) { TicketItemOption.Add(option.TicketItemId, option.ItemOptionId, option.Type, option.ChangeCount); } }
public static void CacheTicketItemOptions(TicketItem ticketItem) { IEnumerable <TicketItemOption> options = TicketItemOption.GetAll(ticketItem.PrimaryKey); ticketItem._cachedItemOptions.Clear(); foreach (TicketItemOption option in options) { ticketItem._cachedItemOptions.Add(option); } }
public static TicketItemOption Get(YearId primaryKey) { TicketItemOption result = null; SqlConnection cn = GetConnection(); result = Get(cn, primaryKey); FinishedWithConnection(cn); return(result); }
public static TicketItemOption Add(int ticketItemId, int itemOptionId, TicketItemOptionType type, int changeCount) { TicketItemOption result = null; short year = DayOfOperation.CurrentYear; YearId ticketItemPrimaryKey = new YearId(year, ticketItemId); changeCount = changeCount.Clamp(0, 255); // Cache old before making a change TicketItem ticketItem = TicketItem.Get(ticketItemPrimaryKey); if (!ticketItem.IsTicketItemOptionsChanged) { TicketItem.CacheTicketItemOptions(ticketItem); } SqlConnection cn = GetConnection(); using (SqlCommand sqlCmd = new SqlCommand("AddTicketItemOption", cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@TicketItemOptionItemOptionId", SqlDbType.Int, itemOptionId); BuildSqlParameter(sqlCmd, "@TicketItemOptionTicketItemId", SqlDbType.Int, ticketItemId); BuildSqlParameter(sqlCmd, "@TicketItemOptionType", SqlDbType.TinyInt, type); BuildSqlParameter(sqlCmd, "@TicketItemOptionChangeCount", SqlDbType.TinyInt, changeCount); BuildSqlParameter(sqlCmd, "@TicketItemOptionYear", SqlDbType.SmallInt, year); BuildSqlParameter(sqlCmd, "@TicketItemOptionId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new TicketItemOption(new YearId(year, Convert.ToInt32(sqlCmd.Parameters["@TicketItemOptionId"].Value)), itemOptionId, ticketItemId, type, changeCount); } } FinishedWithConnection(cn); if (result != null) { SetTicketItemIsChanged(ticketItem); } // Reduce the inventory TicketItemOption.AdjustInventory(result, ticketItem.Quantity, false); return(result); }
private static TicketItemOption Get(SqlConnection cn, YearId primaryKey) { TicketItemOption result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketItemOption WHERE " + "(TicketItemOptionYear=" + primaryKey.Year + " AND TicketItemOptionId=" + primaryKey.Id + ")", cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildTicketItemOption(rdr); } } } return(result); }
public static void AdjustInventory(TicketItemOption ticketItemOption, double portionSize, bool increaseInventory) { ItemOption itemOption = ItemOption.Get(ticketItemOption.ItemOptionId); if (itemOption.UsesItem && (itemOption.ProductId != null) && (itemOption.ProductAmount != null)) { PosModelHelper.AdjustInventoryByItem( itemOption.ProductId.Value, itemOption.ProductAmount.Value * portionSize, increaseInventory); } else if (itemOption.UsesIngredient && (itemOption.ProductId != null) && (itemOption.ProductAmount != null) && (itemOption.ProductMeasurementUnit != null)) { PosModelHelper.AdjustInventoryByIngredient( itemOption.ProductId.Value, increaseInventory, itemOption.ProductAmount.Value * portionSize, itemOption.ProductMeasurementUnit.Value); } }
public static void AdjustInventory(TicketItem ticketItem, bool increase, int?difference = null) { int quantity = (difference != null ? difference.Value : (ticketItem.QuantityPending != null ? ticketItem.QuantityPending.Value : ticketItem.Quantity)); foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(ticketItem.ItemId)) { PosModelHelper.AdjustInventoryByIngredient(itemIngredient.IngredientId, increase, itemIngredient.Amount * quantity, itemIngredient.MeasurementUnit); } foreach (TicketItemOption ticketItemOption in TicketItemOption.GetAll(ticketItem.PrimaryKey)) { TicketItemOption.AdjustInventory(ticketItemOption, quantity, increase); } }