USE [prince]
GO

/****** Object:  StoredProcedure [Common].[CMD_ReLoadKioskCommodityInfoForUser]    Script Date: 12/02/2025 15:48:23 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Common].[CMD_ReLoadKioskCommodityInfoForUser]') AND type in (N'P', N'PC'))
DROP PROCEDURE [Common].[CMD_ReLoadKioskCommodityInfoForUser]
GO

USE [prince]
GO

/****** Object:  StoredProcedure [Common].[CMD_ReLoadKioskCommodityInfoForUser]    Script Date: 12/02/2025 15:48:23 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [Common].[CMD_ReLoadKioskCommodityInfoForUser]    
        @UAC_ID			[Common].[_INT_]	    
AS
BEGIN

    SET NOCOUNT ON;
    
    DECLARE @Query							NVARCHAR(MAX),            
            @GroupCommodity                 NVARCHAR(1000) = ''
    

    SET @GroupCommodity = (SELECT SST_Value FROM Common.SystemSetting where SST_Title = 'GroupCommodity_ID_CustomerOrderingKiosk' AND SST_UserID = @UAC_ID)

    SET @Query = '
	 SELECT [CMD_ID],	        
	        [CMD_CurrentAmount],
	        IsDisabled = CAST(CASE WHEN ((ISNULL([CMD_IsDisabled],0) = 1) OR (ISNULL([CMD_IsHide_Kiosk],0) = 1))THEN 1 ELSE 0 END AS BIT )
		FROM [Common].[Commodity] 
       WHERE ([CMD_IsFood] = 1)  '
	     
	     
   IF ISNULL(@GroupCommodity,'')=''	     
	  SET @Query = @Query + ' AND (1 = 0) ' 
   ELSE 	    
	  SET @Query = @Query + ' AND (ISNULL([CMD_LKP_KioskAppGroup],0) IN ('+@GroupCommodity+')) ' 
	      
   -- print @Query
    EXEC (@Query)


END

GO


