USE [prince]
GO
/****** Object:  StoredProcedure [Common].[Scale_GetScalesFromRadinScale]    Script Date: 01/21/2026 11:37:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Ghasem Babaie
-- Create Date: 2025-02-20 | 1403-12-02 [ PRI-3377 ]
-- Description: [mkii].[Scale] استخراج لیست ترازو ها از جدول ترازوهای رادین
-- =============================================
ALTER PROCEDURE [Common].[Scale_GetScalesFromRadinScale]
(
	@SST_UserID		[Common].[_INT_]
)		
WITH EXECUTE AS CALLER
AS
BEGIN
    SET NOCOUNT ON;
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    ------------------------------------------------
    
	DECLARE @Query		NVARCHAR(MAX)
	DECLARE @DBName		NVARCHAR(200)

	SELECT @DBName = SST_Value FROM [Common].[SystemSetting] WHERE [SST_Title] = 'Radin_DBName' AND [SST_UserID] = @SST_UserID
	IF ISNULL(@DBName, '') = ''
		SET @DBName = 'Prince'
		
	-- جدول ترازوها
	DECLARE @RadinScaleTable	NVARCHAR(200)
	SET @RadinScaleTable = '[' + @DBName + '].[mkii].[Scale]'	

	--------------------------
	
	-- 1. استخراج اطلاعات جدول ترازوهای رادین
	SET @Query = ' 
		   SELECT [Id],
					[ScaleId],
					[IP],
					ISNULL([Description], '''') AS [Description],
					[LastStatusUpdate],
					ISNULL([ScaleStatusID], 0) AS [ScaleStatusID],
					[ScaleStatusTitle] = CASE ISNULL([ScaleStatusID], 0)
												WHEN 0 THEN N''عدم بررسی وضعیت'' 
												WHEN 1 THEN N''عدم ارتباط''
												WHEN 2 THEN N''روشن''
												WHEN 3 THEN N''آماده به کار''
												WHEN 4 THEN N''تست''
												WHEN 5 THEN N''دستگاه ناشناس''
												ELSE N''[ - - - ]''
											END
		   FROM ' + @RadinScaleTable
	EXEC (@Query)
	
    ----------------------------------------------
    SET TRANSACTION ISOLATION LEVEL READ COMMITTED
    SET NOCOUNT OFF;
END	    
    