CREATE PROCEDURE [MIG_SET_PLM_USER_PREFERENCE_Sp]
( 
	@TargetControlType NVARCHAR(MAX),
	@LegacyPropName NVARCHAR(MAX),
	@LegacyPropGuiType NVARCHAR(MAX),
	@InputPropValue NVARCHAR(MAX),
	@TargetPropValue NVARCHAR(MAX) OUTPUT
)
AS

BEGIN
			-- PROPGUITYPE

			-- 0 - Check-Box
			-- 1 - Dropdown list
			-- 2 - Textbox (directory etc.)
			-- 3 - (plain) Textbox --> to be treated like "Textbox (string mapping)"
			-- 4 - Mapping Rules (Template-ID) --> to be treated like "Textbox (string mapping)"
			-- 5 - Pane/Workarea --> not supported in "pd"
			-- 6 - Project (Reference) --> to be treated like "Textbox (string mapping)"

			IF @LegacyPropName = 'AUTHOR_MUST_CLASSIFY_ITEM' OR @LegacyPropName = 'AUTHOR_MUST_CLASSIFY_DOC' OR @LegacyPropName = 'AUTHOR_MUST_CLASSIFY_MATERIAL' OR 
							@LegacyPropName = 'CONSIST_MODE'  OR  @LegacyPropName = 'CONSIST_FIX'  OR  @LegacyPropName = 'POOL_PROJ'  OR  @LegacyPropName = 'ENABLE_CHECK_IN_OUT_RW_LOCK'  OR  
							@LegacyPropName = 'TASK_APPROVE_DOUBLE'  OR  @LegacyPropName = 'WF_MANDATORY_COMMENTS'  OR  @LegacyPropName = 'CUSTOMER_PART_NO'  OR  
							@LegacyPropName = 'SUPPLIER_PART_NO'  OR  @LegacyPropName = 'ALL_PROJECTS'  OR     
							@LegacyPropName = 'MAIL_FROM_ADDR'  OR  @LegacyPropName = 'AUTHOR_MUST_CLASSIFY_ITEM'  OR  @LegacyPropName = 'AUTHOR_MUST_CLASSIFY_DOC'  OR  
							@LegacyPropName = 'AUTHOR_MUST_CLASSIFY_MATERIAL'
								-- SET PROJ CONFIG PREF VALUE
								SELECT @TargetPropValue = PREF_VALUE FROM SYS_CONFIG WHERE PREF_NAME = @LegacyPropName

			ELSE IF @LegacyPropName = 'ITEM PROJ_SHARE' 
							
					SELECT @TargetPropValue = PREF_VALUE FROM SYS_CONFIG WHERE PREF_NAME = 'PROJ_SHARE' AND CLASS_ID = 'ITEM'
			ELSE IF @LegacyPropName = 'DOC PROJ_SHARE' 
							
					SELECT @TargetPropValue = PREF_VALUE FROM SYS_CONFIG WHERE PREF_NAME = 'PROJ_SHARE' AND CLASS_ID = 'DOC'
			ELSE IF @LegacyPropName = 'FOLDER PROJ_SHARE' 
							
					SELECT @TargetPropValue = PREF_VALUE FROM SYS_CONFIG WHERE PREF_NAME = 'PROJ_SHARE' AND CLASS_ID = 'FOLDER'

			ELSE IF @LegacyPropGuiType = '0' AND @TargetControlType = 'Check Box'
				BEGIN
							SET @TargetPropValue = CASE 
								WHEN @InputPropValue = '1' THEN 
									'1' --yes
								WHEN @InputPropValue = '0' THEN 
									'2' --no
								ELSE
									'2' --default (no)
							END
				END
			ELSE IF @LegacyPropGuiType = '1' AND @TargetControlType = 'Combo Box' 
				BEGIN
					IF @LegacyPropName = 'DEFAULT_ATTACH_TO_BP'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'DEFAULT_ATTACH_TO_BP_ALL_STEPS_LOCKED",' THEN 
											'30' --attach.stp.lck
									  WHEN @InputPropValue = 'DEFAULT_ATTACH_TO_BP_ALL_STEPS_UNLOCKED' THEN 
											'40' --attach.stp.unlk
									  WHEN @InputPropValue = 'DEFAULT_ATTACH_TO_BP_BP_ONLY_LOCKED",' THEN 
											'10' --attach.bp.lck
									  WHEN @InputPropValue = 'DEFAULT_ATTACH_TO_BP_BP_ONLY_UNLOCKED' THEN 
											'20' --attach.bp.unlk
									  ELSE 
											'10' --attach.bp.lck
									END
					  END

					ELSE IF @LegacyPropName = 'DEFAULT_PROJECT'
					  BEGIN
						SET @TargetPropValue = @InputPropValue
					  END

					ELSE IF @LegacyPropName = 'UNIQUE_FILE_NAMES'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Unique across all projects' THEN 
											'10' --uniq.all.proj
									  WHEN @InputPropValue = 'Unique per project' THEN 
											'20' --uniq.per.proj 
									  WHEN @InputPropValue = 'Duplicate of filename is allowed' THEN 
											'30' --dupl.allowed
									  ELSE 
											'30' --dupl.allowed
									END
					  END

					ELSE IF @LegacyPropName = 'DEFAULT_REVISION_OPTION'
					  BEGIN
						SET @TargetPropValue = CASE
									WHEN @InputPropValue = 'All' THEN 
											'10' --all
									WHEN @InputPropValue = 'Latest Released' THEN 
											'20' --latest.released
									WHEN @InputPropValue = 'Current Released' THEN 
											'30' --curr.released
									WHEN @InputPropValue = 'Work-In-Progress' THEN 
											'40' --work.in.progres
									WHEN @InputPropValue = 'Latest-Created' THEN 
											'50' --latest.created
									WHEN @InputPropValue = 'Last modified' THEN 
											'60' --latest.modi
									ELSE 
											'10' --all
							END
					  END

					ELSE IF @LegacyPropName = 'ERP_VERSION'
					  BEGIN
						SET @TargetPropValue = CASE
									WHEN @InputPropValue = 'Baan IV' THEN 
											'30' --erp.baan4
									  WHEN @InputPropValue = 'Baan 5' THEN 
											'40' --erp.baan5
									  WHEN @InputPropValue = 'SSA ERP LN' THEN 
											'10' --erp.ln
									  WHEN @InputPropValue = 'SyteLine' THEN 
											'20' --erp.csi
									  --WHEN @InputPropValue = 'Visual' THEN 
											--'50' --lnk.itm.no
									  --WHEN @InputPropValue = 'M3' THEN 
											--'20' --gen.auto.id
									  WHEN @InputPropValue = 'XA' THEN 
											'60' --erp.xa
									  --WHEN @InputPropValue = 'None' THEN 
											--'40' --lnk.itm.manual
									  WHEN @InputPropValue = 'COM ERP' THEN 
											'50' --erp.com
									  ELSE 
											'10' --erp.ln
									END
					  END

					ELSE IF @LegacyPropName = 'ERP_COMPANY'
					  BEGIN
						SET @TargetPropValue = @InputPropValue
					  END

					ELSE IF @LegacyPropName = 'REPEAT_TASK_REMINDER_UNIT'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Hour' THEN 
											'10' --none
									  WHEN @InputPropValue = 'Day' THEN 
											'20' --file.name
									  ELSE 
											'20' --none
									END
					  END

					--ELSE IF @LegacyPropName = 'CONSIST_MODE'
					--  BEGIN
					--	SET @TargetPropValue = '10'
					--  END

					--ELSE IF @LegacyPropName = 'CONSIST_FIX'
					--  BEGIN
					--	SET @TargetPropValue = '10'
					--  END


				END
		
			ELSE
				SET @TargetPropValue = @InputPropValue

END		





