예제 #1
0
파일: TicketItem.cs 프로젝트: zaieda/TemPOS
 public bool Delete(bool adjustInventory = true)
 {
     IsPendingReturn       = false;
     QuantityPendingReturn = 0;
     Instances.Remove(PrimaryKey);
     TicketItemOption.DeleteAll(this, adjustInventory);
     return(Delete(PrimaryKey, adjustInventory));
 }
예제 #2
0
파일: TicketItem.cs 프로젝트: zaieda/TemPOS
 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);
     }
 }
예제 #3
0
파일: TicketItem.cs 프로젝트: zaieda/TemPOS
        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);
            }
        }
예제 #4
0
        public static TicketItemOption Get(YearId primaryKey)
        {
            TicketItemOption result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, primaryKey);
            FinishedWithConnection(cn);

            return(result);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
파일: TicketItem.cs 프로젝트: zaieda/TemPOS
        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);
            }
        }