public static DB.ITM_History GetItemCurrentHistory(DB.ITM_Inventory entry, DataContext dataContext)
        {
            DB.SYS_Period currentPeriod = SYS.SYS_Period.GetCurrentPeriod(dataContext);

            DB.ITM_History history = dataContext.EntityInventoryContext.ITM_History.FirstOrDefault(n => n.InventoryId ==
                                                                                                   entry.InventoryId && n.PeriodId == currentPeriod.Id && n.SiteId == ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId);

            return(history);
        }
        internal static String Save(DB.ITM_Inventory entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntityInventoryContext.GetEntityState(entry) == EntityState.Detached)
                {
                    dataContext.EntityInventoryContext.ITM_Inventory.Add(entry);
                }

                Validation.ValidateEntity(dataContext.EntityInventoryContext, entry);
            }
            catch (Validation.EntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
        //public static DB.ITM_Inventory GetNextItem(DB.ITM_Inventory ITM_Inventory, DataContext dataContext)
        //{
        //    return dataContext.EntityInventoryContext.ITM_Inventory.OrderBy(o => o.SYS_Entity.CodeMain).ThenBy(o => o.SYS_Entity.CodeSub).FirstOrDefault(n => n.SYS_Entity.CodeMain.CompareTo(ITM_Inventory.SYS_Entity.CodeMain) > 0 && n.SYS_Entity.CodeMain.CompareTo(ITM_Inventory.SYS_Entity.CodeMain) != 0);
        //}

        //public static DB.ITM_Inventory GetPreviousItem(DB.ITM_Inventory ITM_Inventory, DataContext dataContext)
        //{
        //    return dataContext.EntityInventoryContext.ITM_Inventory.OrderByDescending(o => o.SYS_Entity.CodeMain).ThenByDescending(o => o.SYS_Entity.CodeSub).FirstOrDefault(n => n.SYS_Entity.CodeMain.CompareTo(ITM_Inventory.SYS_Entity.CodeMain) < 0 && n.SYS_Entity.CodeMain.CompareTo(ITM_Inventory.SYS_Entity.CodeMain) != 0);
        //}

        public static int GenerateInventoryHistory(DB.ITM_Inventory inventory, DataContext dataContext)
        {
            return(dataContext.EntityInventoryContext.Database.ExecuteSqlCommand("EXEC CDS_SYS.spGenerateInventoryHistory {0}, {1}", inventory.EntityId, inventory.SiteId));
        }