USE [Prince]
GO
/****** Object:  StoredProcedure [Common].[CMD_CheckFactorItemInKiosk]    Script Date: 12/17/2025 14:17:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [Common].[CMD_CheckFactorItemInKiosk]    
       @ALG_ComputerIP    [Common]._BIG_    
AS
BEGIN

    SET NOCOUNT ON;
        DECLARE @WarningRemainFood        [Common]._INT_, 
				@DisableFinishedCMD       [Common]._INT_
				
		SELECT @WarningRemainFood  = SST_Value  FROM [Common].SystemSetting WHERE SST_Title = 'WarningRemainFood' AND SST_UserID = 0
		SELECT @DisableFinishedCMD = SST_Value FROM [Common].SystemSetting WHERE SST_Title = 'DisableFinishedCMD' AND SST_UserID = 0

		SELECT CMD_ID,CMD_Name,
               Reson = CASE WHEN (((@WarningRemainFood = 1) OR (@DisableFinishedCMD = 1)) AND ([KFI_Count] > ISNULL([CMD_CurrentAmount],0))) THEN 1
                            WHEN (ISNULL([CMD_IsDisabled],0) = 1) THEN 2
                            WHEN (ISNULL([CMD_IsHide_Kiosk],0) = 1) THEN 3
                            ELSE 0
                       END 
		  FROM [Common].[KioskFactorItem]
		  JOIN [Common].[Commodity] ON CMD_ID = KFI_CMD_ID 
		 WHERE [KFI_ComputerIP] = @ALG_ComputerIP AND 
		       (CMD_IsFood = 1) AND
               (
			   (((@WarningRemainFood = 1) OR (@DisableFinishedCMD = 1)) AND ([KFI_Count] > ISNULL([CMD_CurrentAmount],0))) OR 
			   ((ISNULL([CMD_IsDisabled],0) = 1) OR (ISNULL([CMD_IsHide_Kiosk],0) = 1))
			   )
			     
    
   

END
