UPDATE TBDD_MODULES SET PRODUCT_VERSION = '2.4.7.2' where NAME = 'Record-Organizer' 
GO
ALTER TRIGGER [dbo].[TBDD_USER_AFT_INS] ON [dbo].[TBDD_USER]
WITH EXECUTE AS CALLER
FOR INSERT
AS
BEGIN TRY
	DECLARE 
		@USER_ID INTEGER,
		@CLIENT_ID INTEGER,
		@ADDED_WHO VARCHAR(50),
		@CLIENT_COUNT INTEGER,
		@ECM_USR_ID INTEGER,
		@USRNAME VARCHAR(50),
		@MODULE_RO BIT,
		@UPDATE_PATH VARCHAR(500)
	SELECT 
		@USER_ID = GUID,
		@ADDED_WHO = ADDED_WHO,
		@USRNAME = USERNAME,
		@MODULE_RO = MODULE_RECORD_ORG
		
	FROM INSERTED

	IF @MODULE_RO = 1
		BEGIN
			SELECT @UPDATE_PATH = VERSION_UPATE_PATH FROM TBDD_MODULES WHERE UPPER(NAME) = UPPER('Record-Organizer')
			INSERT INTO TBDD_VERSION_USER_UPDATE_PATH (USER_ID,MODULE_NAME,UPDATE_PATH) VALUES
				(@USER_ID, 'Record-Organizer', @UPDATE_PATH)
			SELECT @ECM_USR_ID = [dwUserID]
			 FROM [172.24.12.41\BRAINPOOL].windream60.[dbo].[UserInfo] where UPPER(szUserName) = UPPER(@USRNAME)
			IF @ECM_USR_ID IS NOT NULL
				UPDATE TBDD_USER SET USERID_FK_INT_ECM = @ECM_USR_ID
							FROM INSERTED
							WHERE TBDD_USER.GUID = INSERTED.GUID

			SELECT @CLIENT_COUNT = COUNT(*) FROM TBDD_CLIENT
			IF @CLIENT_COUNT = 1
				BEGIN
					SELECT @CLIENT_COUNT = GUID FROM TBDD_CLIENT
					INSERT INTO TBDD_CLIENT_USER (USER_ID,CLIENT_ID,ADDED_WHO) VALUES
					(@USER_ID,@CLIENT_COUNT,@ADDED_WHO)
				END

			INSERT INTO TBDD_USER_MODULES (USER_ID,MODULE_ID) VALUES (@USER_ID,0)
		END
		
END TRY
BEGIN CATCH   
	PRINT 'ERROR IN PROCEDURE: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE())
	+ ' - ERROR-MESSAGE: ' 
	+ CONVERT(VARCHAR(500),ERROR_MESSAGE())
END CATCH
GO
ALTER TABLE TBPMO_KONFIGURATION
 ADD COUNTER_CONTROL_UPDATE_ID INTEGER NOT NULL DEFAULT '1'
GO
ALTER TABLE TBPMO_RIGHTS_WORK_SERVICE
 ADD COUNTER_CONTROL_UPDATE_ID INTEGER NOT NULL DEFAULT '0'
GO

