/* Update-Schritte 2026.08.0: 1. in Tabelle planning.tTabs Spalte StartPage hinzufügen 2. in Tabelle planning.tTabLayouts Spalte StartPage hinzufügen 3. bisheriges Startseiten HTML in neuen Tab übernehmen */ GO ALTER TABLE planning.tTabs ADD StartPage BIT NULL; GO UPDATE planning.tTabs SET StartPage = 0; ALTER TABLE planning.tTabs ALTER COLUMN StartPage BIT NOT NULL; GO ALTER TABLE planning.tTabLayouts ADD StartPage BIT NULL; GO UPDATE planning.tTabLayouts SET StartPage = 0; ALTER TABLE planning.tTabLayouts ALTER COLUMN StartPage BIT NOT NULL; GO DECLARE @StartPageHTML NVARCHAR(MAX); SELECT @StartPageHTML = REPLACE(ValueJSON, ' ', '
') FROM system.tSettings WHERE SettingID = 'ClusterStart_Html_Page'; IF @StartPageHTML IS NOT NULL BEGIN INSERT INTO planning.tTabLayouts (FactoryID, ProductLineID, TabID, LayoutID, LayoutName, LayoutJSON, OrderIndex, LayoutOwner, StartPage) VALUES ('', '', 'START', '1', 'Default layout', @StartPageHTML, 1, '', 1); END DELETE FROM system.tSettings WHERE SettingID = 'ClusterStart_Html_Page'; GO DROP PROCEDURE IF EXISTS planning.spCOPY_Factory; GO /* Procedure to COPY a Factory Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spCOPY_Factory @Username = N'SQL' , @SourceFactoryID = N'1' , @TargetFactoryID = N'1COPY' , @TargetFactoryNameShort = N'Factory COPY'; PRINT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_Factory', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_Factory', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spCOPY_Factory @Username NVARCHAR(255) , @SourceFactoryID NVARCHAR(255) = N'' , @TargetFactoryID NVARCHAR(255) = N'' , @TargetFactoryNameShort NVARCHAR(255) = N'' AS BEGIN BEGIN TRY BEGIN TRANSACTION planning_spCOPY_Factory; -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 4, @Username, @SourceFactoryID, @TargetFactoryID, @TargetFactoryNameShort; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @TransactUserKey INT = 0; DECLARE @SourceFactoryKey INT = 0; DECLARE @SourceFactoryNameShort NVARCHAR(255) = N''; DECLARE @TargetFactoryKey INT = 0; -- Input parameter handling SET @Username = COALESCE(system.fProtectString(@Username), N''); SET @SourceFactoryID = COALESCE(system.fProtectID(@SourceFactoryID), N''); SET @TargetFactoryID = COALESCE(system.fProtectID(@TargetFactoryID), N''); SET @TargetFactoryNameShort = COALESCE(system.fProtectString(@TargetFactoryNameShort), N''); -- Check input parameters IF @SourceFactoryID = N'' OR @TargetFactoryID = N'' EXEC system.spSEND_Message N'ERROR', N'Invalid input parameters.'; -- Check rights EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights.'; -- Determine SourceKeys SELECT @SourceFactoryKey = FactoryKey , @SourceFactoryNameShort = NameShort FROM planning.tdFactories WHERE FactoryID = @SourceFactoryID; IF @SourceFactoryKey = 0 EXEC system.spSEND_Message N'ERROR', N'Source Factory doesn''t exist.'; -- Determine TargetKeys SELECT @TargetFactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @TargetFactoryID; IF @TargetFactoryKey <> 0 EXEC system.spSEND_Message N'ERROR', N'Target Factory already exists.'; -- Copy data DECLARE @Keys AS TABLE ([Key] INT NOT NULL); -- Factories INSERT INTO planning.tdFactories ( FactoryID , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName ) OUTPUT INSERTED.FactoryKey INTO @Keys([Key]) SELECT @TargetFactoryID AS FactoryID , @TargetFactoryNameShort AS NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName FROM planning.tdFactories WHERE FactoryID = @SourceFactoryID; SET @AffectedRows = @@ROWCOUNT; SELECT TOP 1 @TargetFactoryKey = [Key] FROM @Keys; -- ProductLines INSERT INTO planning.tdProductLines ( FactoryKey , ProductLineID , FactoryID , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , DefaultTemplate , GlobalAttributeSource1 , GlobalAttributeAlias1 , GlobalAttributeSource2 , GlobalAttributeAlias2 , GlobalAttributeSource3 , GlobalAttributeAlias3 , GlobalAttributeSource4 , GlobalAttributeAlias4 , GlobalAttributeSource5 , GlobalAttributeAlias5 , GlobalAttributeSource6 , GlobalAttributeAlias6 , GlobalAttributeSource7 , GlobalAttributeAlias7 , GlobalAttributeSource8 , GlobalAttributeAlias8 , GlobalAttributeSource9 , GlobalAttributeAlias9 , GlobalAttributeSource10 , GlobalAttributeAlias10 , GlobalAttributeSource11 , GlobalAttributeAlias11 , GlobalAttributeSource12 , GlobalAttributeAlias12 , GlobalAttributeSource13 , GlobalAttributeAlias13 , GlobalAttributeSource14 , GlobalAttributeAlias14 , GlobalAttributeSource15 , GlobalAttributeAlias15 , GlobalAttributeSource16 , GlobalAttributeAlias16 , GlobalAttributeSource17 , GlobalAttributeAlias17 , GlobalAttributeSource18 , GlobalAttributeAlias18 , GlobalAttributeSource19 , GlobalAttributeAlias19 , GlobalAttributeSource20 , GlobalAttributeAlias20 , GlobalAttributeSource21 , GlobalAttributeAlias21 , GlobalAttributeSource22 , GlobalAttributeAlias22 , GlobalAttributeSource23 , GlobalAttributeAlias23 , GlobalAttributeSource24 , GlobalAttributeAlias24 , GlobalAttributeSource25 , GlobalAttributeAlias25 , LayoutJSON ) SELECT @TargetFactoryKey AS FactoryKey , ProductLineID , @TargetFactoryID AS FactoryID , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , DefaultTemplate , GlobalAttributeSource1 , GlobalAttributeAlias1 , GlobalAttributeSource2 , GlobalAttributeAlias2 , GlobalAttributeSource3 , GlobalAttributeAlias3 , GlobalAttributeSource4 , GlobalAttributeAlias4 , GlobalAttributeSource5 , GlobalAttributeAlias5 , GlobalAttributeSource6 , GlobalAttributeAlias6 , GlobalAttributeSource7 , GlobalAttributeAlias7 , GlobalAttributeSource8 , GlobalAttributeAlias8 , GlobalAttributeSource9 , GlobalAttributeAlias9 , GlobalAttributeSource10 , GlobalAttributeAlias10 , GlobalAttributeSource11 , GlobalAttributeAlias11 , GlobalAttributeSource12 , GlobalAttributeAlias12 , GlobalAttributeSource13 , GlobalAttributeAlias13 , GlobalAttributeSource14 , GlobalAttributeAlias14 , GlobalAttributeSource15 , GlobalAttributeAlias15 , GlobalAttributeSource16 , GlobalAttributeAlias16 , GlobalAttributeSource17 , GlobalAttributeAlias17 , GlobalAttributeSource18 , GlobalAttributeAlias18 , GlobalAttributeSource19 , GlobalAttributeAlias19 , GlobalAttributeSource20 , GlobalAttributeAlias20 , GlobalAttributeSource21 , GlobalAttributeAlias21 , GlobalAttributeSource22 , GlobalAttributeAlias22 , GlobalAttributeSource23 , GlobalAttributeAlias23 , GlobalAttributeSource24 , GlobalAttributeAlias24 , GlobalAttributeSource25 , GlobalAttributeAlias25 , LayoutJSON FROM planning.tdProductLines WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- Products INSERT INTO planning.tdProducts ( ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , TimeType , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , Status , Template , TemplateVersion , GlobalAttribute1 , GlobalAttribute2 , GlobalAttribute3 , GlobalAttribute4 , GlobalAttribute5 , GlobalAttribute6 , GlobalAttribute7 , GlobalAttribute8 , GlobalAttribute9 , GlobalAttribute10 , GlobalAttribute11 , GlobalAttribute12 , GlobalAttribute13 , GlobalAttribute14 , GlobalAttribute15 , GlobalAttribute16 , GlobalAttribute17 , GlobalAttribute18 , GlobalAttribute19 , GlobalAttribute20 , GlobalAttribute21 , GlobalAttribute22 , GlobalAttribute23 , GlobalAttribute24 , GlobalAttribute25 ) SELECT PL.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , ProductID , dP.ProductLineID , @TargetFactoryID AS FactoryID , TimeType , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , Status , Template , TemplateVersion , GlobalAttribute1 , GlobalAttribute2 , GlobalAttribute3 , GlobalAttribute4 , GlobalAttribute5 , GlobalAttribute6 , GlobalAttribute7 , GlobalAttribute8 , GlobalAttribute9 , GlobalAttribute10 , GlobalAttribute11 , GlobalAttribute12 , GlobalAttribute13 , GlobalAttribute14 , GlobalAttribute15 , GlobalAttribute16 , GlobalAttribute17 , GlobalAttribute18 , GlobalAttribute19 , GlobalAttribute20 , GlobalAttribute21 , GlobalAttribute22 , GlobalAttribute23 , GlobalAttribute24 , GlobalAttribute25 FROM planning.tdProducts AS dP LEFT JOIN ( SELECT ProductLineKey , ProductLineID FROM planning.tdProductLines WHERE FactoryKey = @TargetFactoryKey ) AS PL ON PL.ProductLineID = dP.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- ValueSeries INSERT INTO planning.tdValueSeries ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ValueSeriesID , ValueSeriesNo , NameShort , NameLong , CommentUser , CommentDev , ImageName , IsNumeric , VisibilityLevel , ValueSource , ValueListID , ValueFormatID , Unit , Scale , Effect , EffectParameter , AllowZero ) SELECT P.ProductKey AS ProductKey , P.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , dVS.ProductID , dVS.ProductLineID , @TargetFactoryID AS FactoryID , ValueSeriesID , ValueSeriesNo , NameShort , NameLong , CommentUser , CommentDev , ImageName , [IsNumeric] , VisibilityLevel , ValueSource , ValueListID , ValueFormatID , Unit , Scale , Effect , EffectParameter , AllowZero FROM planning.tdValueSeries AS dVS LEFT JOIN ( SELECT ProductKey , ProductLineKey , ProductID , ProductLineID FROM planning.tdProducts WHERE FactoryKey = @TargetFactoryKey ) AS P ON P.ProductID = dVS.ProductID AND P.ProductLineID = dVS.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- Time INSERT INTO planning.tdTime ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , TimeID , FormatID ) SELECT P.ProductKey AS ProductKey , P.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , dT.ProductID , dT.ProductLineID , @TargetFactoryID AS FactoryID , TimeID , FormatID FROM planning.tdTime AS dT LEFT JOIN ( SELECT ProductKey , ProductLineKey , ProductID , ProductLineID FROM planning.tdProducts WHERE FactoryKey = @TargetFactoryKey ) AS P ON P.ProductID = dT.ProductID AND P.ProductLineID = dT.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- Values INSERT INTO planning.tfValues ( ValueSeriesKey , ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ValueSeriesID , TimeID , ValueFormula , ValueInt , ValueText , ValueComment ) SELECT VS.ValueSeriesKey AS ValueSeriesKey , VS.ProductKey AS ProductKey , VS.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , fV.ProductID , fV.ProductLineID , @TargetFactoryID AS FactoryID , fV.ValueSeriesID , TimeID , ValueFormula , ValueInt , ValueText , ValueComment FROM planning.tfValues AS fV LEFT JOIN ( SELECT ProductKey , ValueSeriesKey , ProductLineKey , ProductID , ValueSeriesID , ProductLineID FROM planning.tdValueSeries WHERE FactoryKey = @TargetFactoryKey ) AS VS ON fV.ValueSeriesID = VS.ValueSeriesID AND fV.ProductID = VS.ProductID AND fV.ProductLineID = VS.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- gFactories INSERT INTO planning.tgFactories ( FactoryKey , FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID ) SELECT @TargetFactoryKey AS FactoryKey , @TargetFactoryID AS FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID FROM planning.tgFactories WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- gProductLines INSERT INTO planning.tgProductLines ( ProductLineKey , FactoryKey , ProductLineID , FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID ) SELECT PL.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , gPL.ProductLineID , @TargetFactoryID AS FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID FROM planning.tgProductLines AS gPL LEFT JOIN ( SELECT ProductLineKey , ProductLineID FROM planning.tdProductLines WHERE FactoryKey = @TargetFactoryKey ) AS PL ON PL.ProductLineID = gPL.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- gProducts INSERT INTO planning.tgProducts ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID ) SELECT P.ProductKey AS ProductKey , P.ProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , gP.ProductID , gP.ProductLineID , @TargetFactoryID AS FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID FROM planning.tgProducts AS gP LEFT JOIN ( SELECT ProductKey , ProductLineKey , ProductID , ProductLineID FROM planning.tdProducts WHERE FactoryKey = @TargetFactoryKey ) AS P ON P.ProductID = gP.ProductID AND P.ProductLineID = gP.ProductLineID WHERE FactoryKey = @SourceFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- Files INSERT INTO planning.tFiles ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , FileID , FileName , FileExtension , FileBody , UploadedBy , UploadedAt , Filepath ) SELECT @TargetFactoryKey , P.ProductLineKey , P.ProductKey , @TargetFactoryID , tF.ProductLineID , tF.ProductID , tF.FileID , tF.FileName , tF.FileExtension , tF.FileBody , tF.UploadedBy , tF.UploadedAt , tF.Filepath FROM planning.tFiles AS tF LEFT JOIN ( SELECT ProductKey , ProductLineKey , ProductID , ProductLineID FROM planning.tdProducts WHERE FactoryKey = @TargetFactoryKey ) AS P ON P.ProductID = tF.ProductID AND P.ProductLineID = tF.ProductLineID WHERE FactoryID = @SourceFactoryID; SET @AffectedRows += @@ROWCOUNT; -- tTabs INSERT INTO planning.tTabs ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage ) SELECT @TargetFactoryKey , COALESCE(PL.ProductLineKey, -1) AS ProductLineKey , COALESCE(P.ProductKey, -1) AS ProductKey , @TargetFactoryID AS FactoryID , COALESCE(tT.ProductLineID, '') AS ProductLineID , COALESCE(tT.ProductID, '') AS ProductID , tT.TabID , tT.Orderindex , tT.TabName , tT.TabHint , tT.TabText , tT.PresentationCODE , tT.Datasource , tT.IsVisibleBOOL , tT.ParameterJSON , tT.SQLCommand , tT.StartPage FROM planning.tTabs AS tT -- Determine new ProductKeys LEFT JOIN ( SELECT ProductKey , ProductLineKey , ProductID , ProductLineID FROM planning.tdProducts WHERE FactoryKey = @TargetFactoryKey ) AS P ON COALESCE(P.ProductID, '') = tT.ProductID AND COALESCE(P.ProductLineID, '') = tT.ProductLineID -- Determine new ProductLineKeys LEFT JOIN ( SELECT ProductLineKey , ProductLineID FROM planning.tdProductlines WHERE FactoryKey = @TargetFactoryKey ) AS PL ON COALESCE(PL.ProductLineID, '') = tT.ProductLineID WHERE FactoryID = @SourceFactoryID; SET @AffectedRows += @@ROWCOUNT; -- TabLayouts INSERT INTO planning.tTabLayouts ( FactoryID , ProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage ) SELECT @TargetFactoryID , ProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage FROM planning.tTabLayouts WHERE FactoryID = @SourceFactoryID; SET @AffectedRows += @@ROWCOUNT; -- Statements INSERT INTO planning.tfStatements ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ActionType , Statement , UserName , PCName , ProcessorCode , IPAddresses , Timestamp , IsDeleted , IsResolved ) SELECT ProductKey , dp.ProductLineKey , @TargetFactoryKey AS FactoryKey , ProductID , dp.ProductLineID , @TargetFactoryID AS FactoryID , N'COPY' AS ActionType , CONCAT( N'Product produced as a copy of Factory <', @SourceFactoryID, N'>"', @SourceFactoryNameShort , N'" / ProductLine <', dp.ProductLineID, N'>"', dpl.NameShort , N'" / Product <', ProductID, N'>"', dp.NameShort, '"' ) AS Statement , @TransactUsername AS UserName , N'' AS PCName , N'' AS ProcessorCode , N'' AS IPAddresses , GETUTCDATE() AS Timestamp , 0 AS IsDeleted , 0 AS IsResolved FROM planning.tdProducts AS dp LEFT JOIN planning.tdProductLines AS dpl ON dp.ProductLineKey= dpl.ProductLineKey WHERE dp.FactoryKey = @TargetFactoryKey; SET @AffectedRows += @@ROWCOUNT; -- Right materialization EXEC system.spMATERIALIZE_trUserRights; COMMIT TRANSACTION planning_spCOPY_Factory; SET @ResultCode = 201 END TRY BEGIN CATCH ROLLBACK TRANSACTION planning_spCOPY_Factory; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spCOPY_Factory' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to COPY Operation for a Factory'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceFactoryID'; SET @value = N'SourceFactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetFactoryID'; SET @value = N'TargetFactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetFactoryNameShort'; SET @value = N'TargetFactoryNameShort'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spCOPY_ProductLine; GO /* Procedure to COPY a ProductLine Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spCOPY_ProductLine @Username = N'SQL' , @SourceFactoryID = N'1' , @SourceProductLineID = N'1' , @TargetFactoryID = N'1' , @TargetProductLineID = N'1COPY' , @TargetProductLineNameShort = N'ProductLine COPY'; PRINT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_ProductLine', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_ProductLine', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spCOPY_ProductLine @Username NVARCHAR(255) , @SourceFactoryID NVARCHAR(255) = N'' , @SourceProductLineID NVARCHAR(255) = N'' , @TargetFactoryID NVARCHAR(255) = N'' , @TargetProductLineID NVARCHAR(255) = N'' , @TargetProductLineNameShort NVARCHAR(255) = N'' AS BEGIN BEGIN TRY BEGIN TRANSACTION planning_spCOPY_ProductLine; -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 6, @Username, @SourceFactoryID, @SourceProductLineID, @TargetFactoryID, @TargetProductLineID, @TargetProductLineNameShort; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @TransactUserKey INT = 0; DECLARE @SourceFactoryKey INT = 0; DECLARE @SourceProductLineKey INT = 0; DECLARE @SourceFactoryNameShort NVARCHAR(255) = N''; DECLARE @SourceProductLineNameShort NVARCHAR(255) = N''; DECLARE @SourceProductNameShort NVARCHAR(255) = N''; DECLARE @TargetFactoryKey INT = 0; DECLARE @TargetProductLineKey INT = 0; -- Input parameter handling SET @Username = COALESCE(system.fProtectString(@Username), N''); SET @SourceFactoryID = COALESCE(system.fProtectID(@SourceFactoryID), N''); SET @SourceProductLineID = COALESCE(system.fProtectID(@SourceProductLineID), N''); SET @TargetFactoryID = COALESCE(system.fProtectID(@TargetFactoryID), N''); SET @TargetProductLineID = COALESCE(system.fProtectID(@TargetProductLineID), N''); SET @TargetProductLineNameShort = COALESCE(system.fProtectString(@TargetProductLineNameShort), N''); -- Check input parameters IF @SourceFactoryID = N'' OR @SourceProductLineID = N'' OR @TargetFactoryID = N'' OR @TargetProductLineID = N'' OR @TargetProductLineNameShort = N'' EXEC system.spSEND_Message N'ERROR', N'Invalid input parameters.'; -- Check rights EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @TargetFactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Invalid rights on target.'; EXEC @ResultCode = planning.spGET_FactoryReadRight @TransactUsername, @SourceFactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Invalid rights on source'; -- Determine SourceKeys SELECT @SourceFactoryKey = FactoryKey , @SourceFactoryNameShort = NameShort FROM planning.tdFactories WHERE FactoryID = @SourceFactoryID; SELECT @SourceProductLineKey = ProductLineKey , @SourceProductLineNameShort = NameShort FROM planning.tdProductLines WHERE FactoryKey = @SourceFactoryKey AND ProductLineID = @SourceProductLineID; IF @SourceFactoryKey = 0 OR @SourceProductLineKey = 0 EXEC system.spSEND_Message N'ERROR', N'Source object doesn''t exist.'; -- Determine TargetKeys SELECT @TargetFactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @TargetFactoryID; SELECT @TargetProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @TargetFactoryKey AND ProductLineID = @TargetProductLineID; IF @TargetFactoryKey = 0 EXEC system.spSEND_Message N'ERROR', N'Target Factory doesn''t exist.'; IF @TargetProductLineKey <> 0 EXEC system.spSEND_Message N'ERROR', N'Target ProductLine already exists.'; -- Copy data DECLARE @Keys AS TABLE ([Key] INT NOT NULL); -- ProductLines INSERT INTO planning.tdProductLines ( FactoryKey , ProductLineID , FactoryID , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , DefaultTemplate , GlobalAttributeSource1 , GlobalAttributeAlias1 , GlobalAttributeSource2 , GlobalAttributeAlias2 , GlobalAttributeSource3 , GlobalAttributeAlias3 , GlobalAttributeSource4 , GlobalAttributeAlias4 , GlobalAttributeSource5 , GlobalAttributeAlias5 , GlobalAttributeSource6 , GlobalAttributeAlias6 , GlobalAttributeSource7 , GlobalAttributeAlias7 , GlobalAttributeSource8 , GlobalAttributeAlias8 , GlobalAttributeSource9 , GlobalAttributeAlias9 , GlobalAttributeSource10 , GlobalAttributeAlias10 , GlobalAttributeSource11 , GlobalAttributeAlias11 , GlobalAttributeSource12 , GlobalAttributeAlias12 , GlobalAttributeSource13 , GlobalAttributeAlias13 , GlobalAttributeSource14 , GlobalAttributeAlias14 , GlobalAttributeSource15 , GlobalAttributeAlias15 , GlobalAttributeSource16 , GlobalAttributeAlias16 , GlobalAttributeSource17 , GlobalAttributeAlias17 , GlobalAttributeSource18 , GlobalAttributeAlias18 , GlobalAttributeSource19 , GlobalAttributeAlias19 , GlobalAttributeSource20 , GlobalAttributeAlias20 , GlobalAttributeSource21 , GlobalAttributeAlias21 , GlobalAttributeSource22 , GlobalAttributeAlias22 , GlobalAttributeSource23 , GlobalAttributeAlias23 , GlobalAttributeSource24 , GlobalAttributeAlias24 , GlobalAttributeSource25 , GlobalAttributeAlias25 , LayoutJSON ) OUTPUT INSERTED.ProductLineKey INTO @Keys([Key]) SELECT @TargetFactoryKey AS FactoryKey , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , @TargetProductLineNameShort AS NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , DefaultTemplate , GlobalAttributeSource1 , GlobalAttributeAlias1 , GlobalAttributeSource2 , GlobalAttributeAlias2 , GlobalAttributeSource3 , GlobalAttributeAlias3 , GlobalAttributeSource4 , GlobalAttributeAlias4 , GlobalAttributeSource5 , GlobalAttributeAlias5 , GlobalAttributeSource6 , GlobalAttributeAlias6 , GlobalAttributeSource7 , GlobalAttributeAlias7 , GlobalAttributeSource8 , GlobalAttributeAlias8 , GlobalAttributeSource9 , GlobalAttributeAlias9 , GlobalAttributeSource10 , GlobalAttributeAlias10 , GlobalAttributeSource11 , GlobalAttributeAlias11 , GlobalAttributeSource12 , GlobalAttributeAlias12 , GlobalAttributeSource13 , GlobalAttributeAlias13 , GlobalAttributeSource14 , GlobalAttributeAlias14 , GlobalAttributeSource15 , GlobalAttributeAlias15 , GlobalAttributeSource16 , GlobalAttributeAlias16 , GlobalAttributeSource17 , GlobalAttributeAlias17 , GlobalAttributeSource18 , GlobalAttributeAlias18 , GlobalAttributeSource19 , GlobalAttributeAlias19 , GlobalAttributeSource20 , GlobalAttributeAlias20 , GlobalAttributeSource21 , GlobalAttributeAlias21 , GlobalAttributeSource22 , GlobalAttributeAlias22 , GlobalAttributeSource23 , GlobalAttributeAlias23 , GlobalAttributeSource24 , GlobalAttributeAlias24 , GlobalAttributeSource25 , GlobalAttributeAlias25 , LayoutJSON FROM planning.tdProductLines WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; SELECT TOP 1 @TargetProductLineKey = [Key] FROM @Keys; -- Products INSERT INTO planning.tdProducts ( ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , TimeType , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , Status , Template , TemplateVersion , GlobalAttribute1 , GlobalAttribute2 , GlobalAttribute3 , GlobalAttribute4 , GlobalAttribute5 , GlobalAttribute6 , GlobalAttribute7 , GlobalAttribute8 , GlobalAttribute9 , GlobalAttribute10 , GlobalAttribute11 , GlobalAttribute12 , GlobalAttribute13 , GlobalAttribute14 , GlobalAttribute15 , GlobalAttribute16 , GlobalAttribute17 , GlobalAttribute18 , GlobalAttribute19 , GlobalAttribute20 , GlobalAttribute21 , GlobalAttribute22 , GlobalAttribute23 , GlobalAttribute24 , GlobalAttribute25 ) SELECT @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , TimeType , NameShort , NameLong , CommentUser , CommentDev , ResponsiblePerson , ImageName , Status , Template , TemplateVersion , GlobalAttribute1 , GlobalAttribute2 , GlobalAttribute3 , GlobalAttribute4 , GlobalAttribute5 , GlobalAttribute6 , GlobalAttribute7 , GlobalAttribute8 , GlobalAttribute9 , GlobalAttribute10 , GlobalAttribute11 , GlobalAttribute12 , GlobalAttribute13 , GlobalAttribute14 , GlobalAttribute15 , GlobalAttribute16 , GlobalAttribute17 , GlobalAttribute18 , GlobalAttribute19 , GlobalAttribute20 , GlobalAttribute21 , GlobalAttribute22 , GlobalAttribute23 , GlobalAttribute24 , GlobalAttribute25 FROM planning.tdProducts WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- ValueSeries INSERT INTO planning.tdValueSeries ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ValueSeriesID , ValueSeriesNo , NameShort , NameLong , CommentUser , CommentDev , ImageName , IsNumeric , VisibilityLevel , ValueSource , ValueListID , ValueFormatID , Unit , Scale , Effect , EffectParameter , AllowZero ) SELECT P.ProductKey AS ProductKey , @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , dVS.ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , ValueSeriesID , ValueSeriesNo , NameShort , NameLong , CommentUser , CommentDev , ImageName , [IsNumeric] , VisibilityLevel , ValueSource , ValueListID , ValueFormatID , Unit , Scale , Effect , EffectParameter , AllowZero FROM planning.tdValueSeries AS dVS LEFT JOIN ( SELECT ProductKey , ProductID FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey ) AS P ON P.ProductID = dVS.ProductID WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- Time INSERT INTO planning.tdTime ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , TimeID , FormatID ) SELECT P.ProductKey AS ProductKey , @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , dT.ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , TimeID , FormatID FROM planning.tdTime AS dT LEFT JOIN ( SELECT ProductKey , ProductID FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey ) AS P ON P.ProductID = dT.ProductID WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- Values INSERT INTO planning.tfValues ( ValueSeriesKey , ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ValueSeriesID , TimeID , ValueFormula , ValueInt , ValueText , ValueComment ) SELECT VS.ValueSeriesKey AS ValueSeriesKey , VS.ProductKey AS ProductKey , @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , fV.ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , fV.ValueSeriesID , TimeID , ValueFormula , ValueInt , ValueText , ValueComment FROM planning.tfValues AS fV LEFT JOIN ( SELECT ValueSeriesKey , ProductKey , ValueSeriesID , ProductID FROM planning.tdValueSeries WHERE ProductLineKey = @TargetProductLineKey ) AS VS ON fV.ValueSeriesID = VS.ValueSeriesID AND fV.ProductID = VS.ProductID WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- gProductLines INSERT INTO planning.tgProductLines ( ProductLineKey , FactoryKey , ProductLineID , FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID ) SELECT @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID FROM planning.tgProductLines WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- gProducts INSERT INTO planning.tgProducts ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID ) SELECT P.ProductKey AS ProductKey , @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , gP.ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , PropertyID , PropertyName , CommentUser , CommentDev , Unit , ValueText , ValueInt , Scale , IsROSystemProperty , FormatID FROM planning.tgProducts AS gP LEFT JOIN ( SELECT ProductKey , ProductID FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey ) AS P ON P.ProductID = gP.ProductID WHERE ProductLineKey = @SourceProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- Files INSERT INTO planning.tFiles ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , FileID , FileName , FileExtension , FileBody , UploadedBy , UploadedAt , Filepath ) SELECT @TargetFactoryKey , @TargetProductLineKey , P.ProductKey , @TargetFactoryID AS FactoryID , @TargetProductLineID AS ProductLineID , tF.ProductID , tF.FileID , tF.FileName , tF.FileExtension , tF.FileBody , tF.UploadedBy , tF.UploadedAt , tF.Filepath FROM planning.tFiles AS tF LEFT JOIN ( SELECT ProductKey , ProductID FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey ) AS P ON P.ProductID = tF.ProductID WHERE FactoryID = @SourceFactoryID AND ProductLineID = @SourceProductLineID; SET @AffectedRows += @@ROWCOUNT; -- Tabs INSERT INTO planning.tTabs ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage ) SELECT @TargetFactoryKey , @TargetProductLineKey , COALESCE(P.ProductKey, -1) AS ProductKey , @TargetFactoryID AS FactoryID , @TargetProductLineID AS ProductLineID , COALESCE(tT.ProductID, '') AS ProductID , tT.TabID , tT.Orderindex , tT.TabName , tT.TabHint , tT.TabText , tT.PresentationCODE , tT.Datasource , tT.IsVisibleBOOL , tT.ParameterJSON , tT.SQLCommand , tT.StartPage FROM planning.tTabs AS tT LEFT JOIN ( SELECT ProductKey , ProductID FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey ) AS P ON COALESCE(P.ProductID, '') = tT.ProductID WHERE FactoryID = @SourceFactoryID AND ProductLineID = @SourceProductLineID; SET @AffectedRows += @@ROWCOUNT; -- TabLayouts INSERT INTO planning.tTabLayouts ( FactoryID , ProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage ) SELECT @TargetFactoryID , @TargetProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage FROM planning.tTabLayouts WHERE FactoryID = @SourceFactoryID AND ProductLineID = @SourceProductLineID; SET @AffectedRows += @@ROWCOUNT; -- Statements INSERT INTO planning.tfStatements ( ProductKey , ProductLineKey , FactoryKey , ProductID , ProductLineID , FactoryID , ActionType , Statement , UserName , PCName , ProcessorCode , IPAddresses , Timestamp , IsDeleted , IsResolved ) SELECT ProductKey , @TargetProductLineKey AS ProductLineKey , @TargetFactoryKey AS FactoryKey , ProductID , @TargetProductLineID AS ProductLineID , @TargetFactoryID AS FactoryID , N'COPY' AS ActionType , CONCAT( N'Product produced as a copy of Factory <', @SourceFactoryID, N'>"', @SourceFactoryNameShort , N'" / ProductLine <', @SourceProductLineID, N'>"', @SourceProductLineNameShort , N'" / Product <', ProductID, N'>"', NameShort, '"' ) AS Statement , @TransactUsername AS UserName , N'' AS PCName , N'' AS ProcessorCode , N'' AS IPAddresses , GETUTCDATE() AS Timestamp , 0 AS IsDeleted , 0 AS IsResolved FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey; SET @AffectedRows += @@ROWCOUNT; -- Rights materialization EXEC system.spMATERIALIZE_trUserRights; COMMIT TRANSACTION planning_spCOPY_ProductLine; SET @ResultCode = 201 END TRY BEGIN CATCH ROLLBACK TRANSACTION planning_spCOPY_ProductLine; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spCOPY_ProductLine'-- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to COPY Operation for a ProductLine'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceFactoryID'; SET @value = N'SourceFactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceProductLineID'; SET @value = N'SourceProductLineID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetFactoryID'; SET @value = N'TargetFactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetProductLineID'; SET @value = N'TargetProductLineID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetProductLineNameShort'; SET @value = N'TargetProductLineNameShort'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spEXPORT_Factory; GO /* Procedure to EXPORT a Factory with all its dependend objects Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spEXPORT_Factory @Username = N'SQL' , @FactoryID = N'1' , @OutputForSQLServer = 1; PRINT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_Factory',NULL,NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_Factory','PARAMETER',NULL) */ CREATE PROCEDURE planning.spEXPORT_Factory @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @OutputForSQLServer INT = 1 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 3, @Username, @FactoryID, @OutputForSQLServer; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @FactoryKey BIGINT = 0; -- Input parameter handling SET @Username = COALESCE(system.fProtectString(@Username), N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @OutputForSQLServer = COALESCE(@OutputForSQLServer, 1); -- Check input parameters IF @FactoryID = N'' EXEC system.spSEND_Message N'ERROR', N'Invalid input parameters.'; -- Determine keys SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID; IF @FactoryKey = 0 EXEC system.spSEND_Message N'ERROR', N'Factory doesn''t exist.'; -- Check rights EXEC @ResultCode = planning.spGET_FactoryReadRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights.'; -- Determine dependend objects -- Determine dependend Lists and store in temporary table DECLARE @DependendListIDs AS TABLE ( ListID NVARCHAR(255) ); WITH lists AS ( -- MERGE dependend Lists, used in ProductDataTable SELECT ValueListID FROM planning.tdValueSeries WHERE FactoryKey = @FactoryKey -- MERGE dependend Lists, used in Globalattributes UNION ALL SELECT GlobalAttributeSource1 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource2 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource3 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource4 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource5 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource6 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource7 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource8 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource9 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource10 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource11 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource12 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource13 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource14 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource15 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource16 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource17 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource18 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource19 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource20 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource21 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource22 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource23 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource24 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey UNION ALL SELECT GlobalAttributeSource25 FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey ) INSERT INTO @DependendListIDs ( ListID ) SELECT DISTINCT ValueListID FROM lists; -- Declare temporary Table for export results DECLARE @ExportTable AS TABLE ( StepNumber INT NOT NULL , RowNumber INT NOT NULL , Command NVARCHAR(MAX) ); INSERT INTO @ExportTable VALUES (0, 1, N'-- CONFIG: Adjust variable names manually to fit your needs!') , (0, 1, N'DECLARE @Username NVARCHAR(255) = ''SQL''') , (0, 1, CONCAT(N'DECLARE @FactoryID NVARCHAR(255) = ''', @FactoryID, N'''')) , (0, 1, N'') , (0, 1, N'-- This FactoryID will be deleted during import, if it exists. You should be sure!'); -- DELETE FactoryID if exists INSERT INTO @ExportTable VALUES ( 1000 , 1 , N'EXEC planning.spDELETE_Factory @Username, @FactoryID;' ); -- POST Factory INSERT INTO @ExportTable SELECT 1001 , 1 , CONCAT( N'EXEC planning.spPOST_Factory' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ResponsiblePerson = ''', system.fMaskSQL(ResponsiblePerson), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N';' ) FROM planning.tdFactories WHERE FactoryKey = @FactoryKey; -- POST ProductLines INSERT INTO @ExportTable SELECT 1002 , 1 , CONCAT( N'EXEC planning.spPOST_ProductLine' , N' @Username = @Username' , N', @ProductLineID = ''', ProductLineID, N'''' , N', @FactoryID = @FactoryID' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(system.fUnifyLinebreaks(CommentUser)), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ResponsiblePerson = ''', system.fMaskSQL(ResponsiblePerson), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @DefaultTemplate = ''', system.fMaskSQL(DefaultTemplate), N'''' , N', @GlobalAttributeSource1 = ''', system.fMaskSQL(GlobalAttributeSource1), N'''' , N', @GlobalAttributeAlias1 = ''', system.fMaskSQL(GlobalAttributeAlias1), N'''' , N', @GlobalAttributeSource2 = ''', system.fMaskSQL(GlobalAttributeSource2), N'''' , N', @GlobalAttributeAlias2 = ''', system.fMaskSQL(GlobalAttributeAlias2), N'''' , N', @GlobalAttributeSource3 = ''', system.fMaskSQL(GlobalAttributeSource3), N'''' , N', @GlobalAttributeAlias3 = ''', system.fMaskSQL(GlobalAttributeAlias3), N'''' , N', @GlobalAttributeSource4 = ''', system.fMaskSQL(GlobalAttributeSource4), N'''' , N', @GlobalAttributeAlias4 = ''', system.fMaskSQL(GlobalAttributeAlias4), N'''' , N', @GlobalAttributeSource5 = ''', system.fMaskSQL(GlobalAttributeSource5), N'''' , N', @GlobalAttributeAlias5 = ''', system.fMaskSQL(GlobalAttributeAlias5), N'''' , N', @GlobalAttributeSource6 = ''', system.fMaskSQL(GlobalAttributeSource6), N'''' , N', @GlobalAttributeAlias6 = ''', system.fMaskSQL(GlobalAttributeAlias6), N'''' , N', @GlobalAttributeSource7 = ''', system.fMaskSQL(GlobalAttributeSource7), N'''' , N', @GlobalAttributeAlias7 = ''', system.fMaskSQL(GlobalAttributeAlias7), N'''' , N', @GlobalAttributeSource8 = ''', system.fMaskSQL(GlobalAttributeSource8), N'''' , N', @GlobalAttributeAlias8 = ''', system.fMaskSQL(GlobalAttributeAlias8), N'''' , N', @GlobalAttributeSource9 = ''', system.fMaskSQL(GlobalAttributeSource9), N'''' , N', @GlobalAttributeAlias9 = ''', system.fMaskSQL(GlobalAttributeAlias9), N'''' , N', @GlobalAttributeSource10 = ''', system.fMaskSQL(GlobalAttributeSource10), N'''' , N', @GlobalAttributeAlias10 = ''', system.fMaskSQL(GlobalAttributeAlias10), N'''' , N', @GlobalAttributeSource11 = ''', system.fMaskSQL(GlobalAttributeSource11), N'''' , N', @GlobalAttributeAlias11 = ''', system.fMaskSQL(GlobalAttributeAlias11), N'''' , N', @GlobalAttributeSource12 = ''', system.fMaskSQL(GlobalAttributeSource12), N'''' , N', @GlobalAttributeAlias12 = ''', system.fMaskSQL(GlobalAttributeAlias12), N'''' , N', @GlobalAttributeSource13 = ''', system.fMaskSQL(GlobalAttributeSource13), N'''' , N', @GlobalAttributeAlias13 = ''', system.fMaskSQL(GlobalAttributeAlias13), N'''' , N', @GlobalAttributeSource14 = ''', system.fMaskSQL(GlobalAttributeSource14), N'''' , N', @GlobalAttributeAlias14 = ''', system.fMaskSQL(GlobalAttributeAlias14), N'''' , N', @GlobalAttributeSource15 = ''', system.fMaskSQL(GlobalAttributeSource15), N'''' , N', @GlobalAttributeAlias15 = ''', system.fMaskSQL(GlobalAttributeAlias15), N'''' , N', @GlobalAttributeSource16 = ''', system.fMaskSQL(GlobalAttributeSource16), N'''' , N', @GlobalAttributeAlias16 = ''', system.fMaskSQL(GlobalAttributeAlias16), N'''' , N', @GlobalAttributeSource17 = ''', system.fMaskSQL(GlobalAttributeSource17), N'''' , N', @GlobalAttributeAlias17 = ''', system.fMaskSQL(GlobalAttributeAlias17), N'''' , N', @GlobalAttributeSource18 = ''', system.fMaskSQL(GlobalAttributeSource18), N'''' , N', @GlobalAttributeAlias18 = ''', system.fMaskSQL(GlobalAttributeAlias18), N'''' , N', @GlobalAttributeSource19 = ''', system.fMaskSQL(GlobalAttributeSource19), N'''' , N', @GlobalAttributeAlias19 = ''', system.fMaskSQL(GlobalAttributeAlias19), N'''' , N', @GlobalAttributeSource20 = ''', system.fMaskSQL(GlobalAttributeSource20), N'''' , N', @GlobalAttributeAlias20 = ''', system.fMaskSQL(GlobalAttributeAlias20), N'''' , N', @GlobalAttributeSource21 = ''', system.fMaskSQL(GlobalAttributeSource21), N'''' , N', @GlobalAttributeAlias21 = ''', system.fMaskSQL(GlobalAttributeAlias21), N'''' , N', @GlobalAttributeSource22 = ''', system.fMaskSQL(GlobalAttributeSource22), N'''' , N', @GlobalAttributeAlias22 = ''', system.fMaskSQL(GlobalAttributeAlias22), N'''' , N', @GlobalAttributeSource23 = ''', system.fMaskSQL(GlobalAttributeSource23), N'''' , N', @GlobalAttributeAlias23 = ''', system.fMaskSQL(GlobalAttributeAlias23), N'''' , N', @GlobalAttributeSource24 = ''', system.fMaskSQL(GlobalAttributeSource24), N'''' , N', @GlobalAttributeAlias24 = ''', system.fMaskSQL(GlobalAttributeAlias24), N'''' , N', @GlobalAttributeSource25 = ''', system.fMaskSQL(GlobalAttributeSource25), N'''' , N', @GlobalAttributeAlias25 = ''', system.fMaskSQL(GlobalAttributeAlias25), N'''' , N', @LayoutJSON = ''', system.fMaskSQL(LayoutJSON), N'''' , N';' ) FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey; -- POST Products INSERT INTO @ExportTable SELECT 2000 ,1 , CONCAT( N'EXEC planning.spPOST_ProductEmpty' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = ''', ProductLineID, N'''' , N', @FactoryID = @FactoryID' , N', @TimeType = ''', TimeType, N'''' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(system.fUnifyLinebreaks(CommentUser)), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ResponsiblePerson = ''', system.fMaskSQL(ResponsiblePerson), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @Status = ''', system.fMaskSQL([Status]), N'''' , N', @Template = ''', system.fMaskSQL(Template), N'''' , N', @TemplateVersion = ''', system.fMaskSQL(TemplateVersion), N'''' , N', @GA1 = ''', system.fMaskSQL(GlobalAttribute1), N'''' , N', @GA2 = ''', system.fMaskSQL(GlobalAttribute2), N'''' , N', @GA3 = ''', system.fMaskSQL(GlobalAttribute3), N'''' , N', @GA4 = ''', system.fMaskSQL(GlobalAttribute4), N'''' , N', @GA5 = ''', system.fMaskSQL(GlobalAttribute5), N'''' , N', @GA6 = ''', system.fMaskSQL(GlobalAttribute6), N'''' , N', @GA7 = ''', system.fMaskSQL(GlobalAttribute7), N'''' , N', @GA8 = ''', system.fMaskSQL(GlobalAttribute8), N'''' , N', @GA9 = ''', system.fMaskSQL(GlobalAttribute9), N'''' , N', @GA10 = ''', system.fMaskSQL(GlobalAttribute10), N'''' , N', @GA11 = ''', system.fMaskSQL(GlobalAttribute11), N'''' , N', @GA12 = ''', system.fMaskSQL(GlobalAttribute12), N'''' , N', @GA13 = ''', system.fMaskSQL(GlobalAttribute13), N'''' , N', @GA14 = ''', system.fMaskSQL(GlobalAttribute14), N'''' , N', @GA15 = ''', system.fMaskSQL(GlobalAttribute15), N'''' , N', @GA16 = ''', system.fMaskSQL(GlobalAttribute16), N'''' , N', @GA17 = ''', system.fMaskSQL(GlobalAttribute17), N'''' , N', @GA18 = ''', system.fMaskSQL(GlobalAttribute18), N'''' , N', @GA19 = ''', system.fMaskSQL(GlobalAttribute19), N'''' , N', @GA20 = ''', system.fMaskSQL(GlobalAttribute20), N'''' , N', @GA21 = ''', system.fMaskSQL(GlobalAttribute21), N'''' , N', @GA22 = ''', system.fMaskSQL(GlobalAttribute22), N'''' , N', @GA23 = ''', system.fMaskSQL(GlobalAttribute23), N'''' , N', @GA24 = ''', system.fMaskSQL(GlobalAttribute24), N'''' , N', @GA25 = ''', system.fMaskSQL(GlobalAttribute25), N'''' , N';' ) FROM planning.tdProducts WHERE FactoryKey = @FactoryKey; -- ValueSeries INSERT INTO @ExportTable SELECT 3000 , ROW_NUMBER() OVER (ORDER BY FactoryID, ProductLineID, ProductID, ValueSeriesNo) AS RowNumber , CONCAT( N'EXEC planning.spPOST_ValueSerie' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = ''', ProductLineID, N'''' , N', @FactoryID = @FactoryID' , N', @ValueSeriesID = ''', ValueSeriesID, N'''' , N', @RequestedValueSeriesNo = ''', ValueSeriesNo, N'''' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(system.fUnifyLinebreaks(CommentUser)), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @IsNumeric = ''', [IsNumeric], N'''' , N', @VisibilityLevel = ''', VisibilityLevel, N'''' , N', @ValueSource = ''', ValueSource, N'''' , N', @ValueListID = ''', ValueListID, N'''' , N', @ValueFormatID = ''', ValueFormatID, N'''' , N', @Unit = ''', Unit, N'''' , N', @Scale = ''', Scale, N'''' , N', @Effect = ''', Effect, N'''' , N', @EffectParameter = ''', EffectParameter, N'''' , N', @AllowZero = ''', AllowZero, N'''' , N';' ) FROM planning.tdValueSeries WHERE FactoryKey = @FactoryKey ORDER BY FactoryID , ProductLineID , ProductID , ValueSeriesNo; -- Time WITH tms AS ( SELECT dP.ProductID , dP.ProductLineID , ( SELECT N'[(' + CAST(t.TimeID AS NVARCHAR(10)) + N',0,0,''''' + FormatID + ''''')],' -- with DeleteFlag, AddValue,FormatID FROM planning.tdTime t WHERE t.ProductKey = dP.ProductKey ORDER BY t.TimeID FOR XML PATH(N''), TYPE ).value(N'.[1]', N'NVARCHAR(MAX)') AS vals FROM planning.tdProducts AS dP WHERE dP.FactoryKey = @FactoryKey ) INSERT INTO @ExportTable SELECT 4000 , 1 , CONCAT( N'EXEC planning.spPOST_Timeline' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = ''', ProductLineID, N'''' , N', @FactoryID = @FactoryID' , N', @IsIncrementalValuesFlag = 1' , N', @TimeIDsInBracketsCommaSeparated = ''', LEFT(vals, LEN(vals) - 1), N'''' , N';' ) FROM tms WHERE vals IS NOT NULL; -- POST ProductDataTableValues WITH tms AS ( SELECT dP.ProductID , dP.ProductLineID , ( SELECT CONCAT( N'[(''''' , ValueSeriesID, N''''',' , CAST(TimeID AS NVARCHAR(255)), N',''''' , ValueFormula, N''''',''''' , CAST(ValueInt AS NVARCHAR(255)), N''''',''''' , system.fMaskSQL(ValueText), N''''',''''' , system.fMaskSQL(system.fUnifyLinebreaks(ValueComment)) , N''''')],' ) FROM planning.tfValues AS t WHERE t.ProductKey = dP.ProductKey FOR XML PATH(N''), TYPE ).value(N'.[1]', N'NVARCHAR(MAX)') AS vals FROM planning.tdProducts AS dP WHERE dP.FactoryKey = @FactoryKey ) INSERT INTO @ExportTable SELECT 5000 , 1 , CONCAT( N'EXEC planning.spPOST_ProductDataTableValues' , N' @Username = @Username' , N', @ProductID = ''', ProductID, '''' , N', @ProductLineID = ''', ProductLineID, '''' , N', @FactoryID = @FactoryID' , N' @IsIncrementalValuesFlag = 0' , N', @ValuesInBracketsCommaSeparated = ''', LEFT(vals, LEN(vals) - 1), N'''' , N';' ) FROM tms WHERE vals IS NOT NULL; -- POST Factory Properties INSERT INTO @ExportTable SELECT 6000 , 1 , CONCAT( N'EXEC planning.spPOST_FactoryProperty' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @PropertyID = ''', PropertyID, '''' , N', @PropertyName = ''', system.fMaskSQL(PropertyName), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Unit = ''', Unit, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @IsROSystemProperty = ''', IsROSystemProperty, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.tgFactories WHERE FactoryKey = @FactoryKey; -- POST ProductLine Properties INSERT INTO @ExportTable SELECT 6001 , 1 , CONCAT( N'EXEC planning.spPOST_ProductLineProperty' , N' @Username = @Username' , N', @ProductLineID = ''', ProductLineID, '''' , N', @FactoryID = @FactoryID' , N', @PropertyID = ''', PropertyID, '''' , N', @PropertyName = ''', system.fMaskSQL(PropertyName), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Unit = ''', Unit, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @IsROSystemProperty = ''', IsROSystemProperty, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.tgProductLines WHERE FactoryKey = @FactoryKey; -- POST Product Properties INSERT INTO @ExportTable SELECT 6002 , 1 , CONCAT( N'EXEC planning.spPOST_ProductProperty' , N' @Username = @Username' , N', @ProductID = ''', ProductID, '''' , N', @ProductLineID = ''', ProductLineID, '''' , N', @FactoryID = @FactoryID' , N', @PropertyID = ''', PropertyID, '''' , N', @PropertyName = ''', system.fMaskSQL(PropertyName), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Unit = ''', Unit, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @IsROSystemProperty = ''', IsROSystemProperty, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.tgProducts WHERE FactoryKey = @FactoryKey; -- POST Tabs INSERT INTO @ExportTable SELECT 6003 , Row_Number() OVER (ORDER BY FactoryID, ProductLineID, ProductID, OrderIndex) AS Row , CONCAT( N'EXEC planning.spPOST_Tab' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @ProductLineID = ''', ProductLineID, '''' , N', @ProductID = ''', ProductID, '''' , N', @TabID = ''', TabID, '''' , N', @OrderIndex = ''', OrderIndex, '''' , N', @TabName = ''', system.fMaskSQL(TabName), '''' , N', @TabHint = ''', system.fMaskSQL(TabHint), '''' , N', @TabText = ''', system.fMaskSQL(TabText), '''' , N', @PresentationCODE = ''', system.fMaskSQL(PresentationCODE), '''' , N', @Datasource = ''', system.fMaskSQL(Datasource), '''' , N', @IsVisibleBOOL = ''', IsVisibleBOOL, '''' , N', @LayoutJSON = ''''' , N', @ParameterJSON = ''', system.fMaskSQL(ParameterJSON), '''' , N', @SQLCommand = ''', system.fMaskSQL(SQLCommand), '''' , N', @StartPage = ''', StartPage, '''' , N';' ) FROM planning.tTabs WHERE FactoryKey = @FactoryKey; -- POST TabLayouts INSERT INTO @ExportTable SELECT 6004 , Row_Number() OVER (ORDER BY FactoryID, ProductLineID, TabID, LayoutOwner, OrderIndex) AS Row , CONCAT( N'EXEC planning.spPOST_TabLayout' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @ProductLineID = ''', ProductLineID, '''' , N', @TabID = ''', TabID, '''' , N', @LayoutID = ''', LayoutID, '''' , N', @LayoutName = ''', system.fMaskSQL(LayoutName), '''' , N', @LayoutJSON = ''', system.fMaskSQL(LayoutJSON), '''' , N', @OrderIndex = ''', OrderIndex, '''' , N', @LayoutOwner = ''', LayoutOwner, '''' , N', @StartPage = ''', StartPage, '''' , N';' ) FROM planning.tTabLayouts WHERE FactoryID = @FactoryID; -- POST Lists INSERT INTO @ExportTable SELECT 7001 , 1 , CONCAT( N'EXEC planning.spPOST_List' , N' @Username = @Username' , N', @ListID = ''', ListID, '''' , N', @NameShort = ''', system.fMaskSQL(NameShort), '''' , N', @NameLong = ''', system.fMaskSQL(NameLong), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Datentyp = ''', Datentyp, '''' , N', @Source = ''', Source, '''' , N', @SourceFormula = ''', SourceFormula, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.thLists WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ); -- POST List Values INSERT INTO @ExportTable SELECT 7002 , 1 , CONCAT( N'EXEC planning.spPOST_ListValue' , N' @Username = @Username' , N', @ListValueKey = 0' , N', @ListID = ''', ListID, '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueComment = ''', system.fMaskSQL(ValueComment), '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.thListValues WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ); -- POST Formats WITH DependendFormats AS ( -- used in depended lists from global attributes SELECT DISTINCT FormatID FROM planning.thListValues WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ) -- used to format ValueSeries UNION SELECT DISTINCT ValueFormatID FROM planning.tdValueSeries WHERE FactoryKey = @FactoryKey -- used to format Timeline UNION SELECT DISTINCT FormatID FROM planning.tdTime WHERE FactoryKey = @FactoryKey -- used to format Ranges UNION SELECT DISTINCT FormatID FROM planning.tgProducts WHERE FactoryKey = @FactoryKey AND PropertyID LIKE N'PDTRange_%' ) INSERT INTO @ExportTable SELECT 7003 , 1 , CONCAT( N'EXEC planning.spPOST_Format' , N' @Username = @Username' , N', @FormatID = ''', FormatID, '''' , N', @BackgroundColor = ''', BackgroundColor, '''' , N', @FontColor = ''', FontColor, '''' , N', @ValueFormat = ''', ValueFormat, '''' , N', @Bold = ''', Bold, '''' , N', @Italic = ''', Italic, '''' , N', @AlignmentHorizontal = ''', AlignmentHorizontal, '''' , N', @AlignmentVertical = ''', AlignmentVertical, '''' , N', @TextUnderlined = ''', TextUnderlined, '''' , N', @BorderToNext = ''', BorderToNext, '''' , N', @BorderToPrevious = ''', BorderToPrevious, '''' , N';' ) FROM planning.thFormats WHERE FormatID IN ( SELECT DISTINCT FormatID FROM DependendFormats WHERE LEN(FormatID) > 0 ); INSERT INTO @ExportTable VALUES ( 8000 , 1 , N'GO' ); -- Output SELECT Command FROM @ExportTable ORDER BY StepNumber , RowNumber; SET @AffectedRows = @@ROWCOUNT; SET @ResultCode = 200 END TRY BEGIN CATCH SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spEXPORT_Factory'-- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'EXPORT operation of a single Factory, including, properties in gtables, global attributes, ProductLine, products, values, dependend lists which have to be merged in the existing lists during import in two styles. One for import as sql script, one for Import over the GUI Import'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'FactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@OutputForSQLServer'; SET @value = N'OutputForSQLServer'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spEXPORT_ProductLine; GO /* Procedure to EXPORT a ProductLine with all its dependend objects Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spEXPORT_ProductLine @Username = N'SQL' , @FactoryID = N'1' , @ProductLineID = N'1' , @OutputForSQLServer = 1; PRINT @RC; Testcall over BCP Results must be stored in table, if column width is to big for SSMS or SQLCMD 0a. Activate Stepnumber for output in Line 753 around and execute prodecedure 0b. Its difficult to send commands with german Umlaute over cmd, thats why name the database without Umlaute 1. Execute this to store the results in the table IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tmpout_Export') AND type in (N'U')) DROP TABLE tmpout_Export; CREATE TABLE tmpout_Export ( StepNumber INT, Command NVARCHAR(MAX) ) INSERT INTO tmpout_Export EXEC planning.spEXPORT_ProductLine 'SQL','ZT','U',1 2. Copy this table Content in a file over a .bat file with this command bcp.exe "SELECT Command FROM tmpout_Export ORDER BY StepNumber" queryout import.sql -T -S localhost -n -e error.log -c -C65001 Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_ProductLine', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_ProductLine', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spEXPORT_ProductLine @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @ProductLineID NVARCHAR(255) = N'' , @OutputForSQLServer INT = 1 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 4, @Username, @FactoryID, @ProductLineID, @OutputForSQLServer; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @ProductLineKey BIGINT = 0; -- Input parameter handling SET @Username = COALESCE(system.fProtectString(@Username), N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @OutputForSQLServer = COALESCE(@OutputForSQLServer, 1); -- Check input parameters IF @FactoryID = N'' OR @ProductLineID = N'' EXEC system.spSEND_Message N'ERROR', N'Invalid input parameters.'; -- Determine keys SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID; IF @ProductLineKey = 0 EXEC system.spSEND_Message N'ERROR', N'ProductLine doesn''t exist.'; -- Check rights EXEC @ResultCode = planning.spGET_ProductLineReadRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights.'; -- Determine dependend objects -- Determine dependend Lists and store in temporary table DECLARE @DependendListIDs AS TABLE ( ListID NVARCHAR(255) ); WITH lists AS ( -- MERGE dependend Lists, used in ProductDataTable SELECT ValueListID FROM planning.tdValueSeries WHERE ProductLineKey = @ProductLineKey -- MERGE dependend Lists, used in Globalattributes UNION ALL SELECT GlobalAttributeSource1 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource2 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource3 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource4 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource5 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource6 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource7 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource8 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource9 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource10 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource11 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource12 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource13 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource14 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource15 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource16 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource17 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource18 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource19 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource20 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource21 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource22 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource23 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource24 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey UNION ALL SELECT GlobalAttributeSource25 FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey ) INSERT INTO @DependendListIDs ( ListID ) SELECT DISTINCT ValueListID FROM lists; -- Declare temporary Table for export results DECLARE @ExportTable AS TABLE ( StepNumber INT NOT NULL , RowNumber INT NOT NULL , Command NVARCHAR(MAX) ); INSERT INTO @ExportTable VALUES (0, 1, N'-- CONFIG: Adjust variable names manually to fit your needs!') , (0, 1, N'DECLARE @Username NVARCHAR(255) = ''SQL''') , (0, 1, CONCAT(N'DECLARE @FactoryID NVARCHAR(255) = ''', @FactoryID, N'''')) , (0, 1, CONCAT(N'DECLARE @ProductLineID NVARCHAR(255) = ''', @ProductLineID, N'''')) , (0, 1, N'') , (0, 1, N'-- This ProductLineID will be deleted during import, if it exists. You should be sure!'); -- DELETE ProductLine if exists INSERT INTO @ExportTable VALUES ( 1000 , 1 , N'EXEC planning.spDELETE_ProductLine @Username, @FactoryID, @ProductLineID;' ); -- POST ProductLine INSERT INTO @ExportTable SELECT 1001 , 1 , CONCAT( N'EXEC planning.spPOST_ProductLine' , N' @Username = @Username' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ResponsiblePerson = ''', system.fMaskSQL(ResponsiblePerson), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @DefaultTemplate = ''', system.fMaskSQL(DefaultTemplate), N'''' , N', @GlobalAttributeSource1 = ''', system.fMaskSQL(GlobalAttributeSource1), N'''' , N', @GlobalAttributeAlias1 = ''', system.fMaskSQL(GlobalAttributeAlias1), N'''' , N', @GlobalAttributeSource2 = ''', system.fMaskSQL(GlobalAttributeSource2), N'''' , N', @GlobalAttributeAlias2 = ''', system.fMaskSQL(GlobalAttributeAlias2), N'''' , N', @GlobalAttributeSource3 = ''', system.fMaskSQL(GlobalAttributeSource3), N'''' , N', @GlobalAttributeAlias3 = ''', system.fMaskSQL(GlobalAttributeAlias3), N'''' , N', @GlobalAttributeSource4 = ''', system.fMaskSQL(GlobalAttributeSource4), N'''' , N', @GlobalAttributeAlias4 = ''', system.fMaskSQL(GlobalAttributeAlias4), N'''' , N', @GlobalAttributeSource5 = ''', system.fMaskSQL(GlobalAttributeSource5), N'''' , N', @GlobalAttributeAlias5 = ''', system.fMaskSQL(GlobalAttributeAlias5), N'''' , N', @GlobalAttributeSource6 = ''', system.fMaskSQL(GlobalAttributeSource6), N'''' , N', @GlobalAttributeAlias6 = ''', system.fMaskSQL(GlobalAttributeAlias6), N'''' , N', @GlobalAttributeSource7 = ''', system.fMaskSQL(GlobalAttributeSource7), N'''' , N', @GlobalAttributeAlias7 = ''', system.fMaskSQL(GlobalAttributeAlias7), N'''' , N', @GlobalAttributeSource8 = ''', system.fMaskSQL(GlobalAttributeSource8), N'''' , N', @GlobalAttributeAlias8 = ''', system.fMaskSQL(GlobalAttributeAlias8), N'''' , N', @GlobalAttributeSource9 = ''', system.fMaskSQL(GlobalAttributeSource9), N'''' , N', @GlobalAttributeAlias9 = ''', system.fMaskSQL(GlobalAttributeAlias9), N'''' , N', @GlobalAttributeSource10 = ''', system.fMaskSQL(GlobalAttributeSource10), N'''' , N', @GlobalAttributeAlias10 = ''', system.fMaskSQL(GlobalAttributeAlias10), N'''' , N', @GlobalAttributeSource11 = ''', system.fMaskSQL(GlobalAttributeSource11), N'''' , N', @GlobalAttributeAlias11 = ''', system.fMaskSQL(GlobalAttributeAlias11), N'''' , N', @GlobalAttributeSource12 = ''', system.fMaskSQL(GlobalAttributeSource12), N'''' , N', @GlobalAttributeAlias12 = ''', system.fMaskSQL(GlobalAttributeAlias12), N'''' , N', @GlobalAttributeSource13 = ''', system.fMaskSQL(GlobalAttributeSource13), N'''' , N', @GlobalAttributeAlias13 = ''', system.fMaskSQL(GlobalAttributeAlias13), N'''' , N', @GlobalAttributeSource14 = ''', system.fMaskSQL(GlobalAttributeSource14), N'''' , N', @GlobalAttributeAlias14 = ''', system.fMaskSQL(GlobalAttributeAlias14), N'''' , N', @GlobalAttributeSource15 = ''', system.fMaskSQL(GlobalAttributeSource15), N'''' , N', @GlobalAttributeAlias15 = ''', system.fMaskSQL(GlobalAttributeAlias15), N'''' , N', @GlobalAttributeSource16 = ''', system.fMaskSQL(GlobalAttributeSource16), N'''' , N', @GlobalAttributeAlias16 = ''', system.fMaskSQL(GlobalAttributeAlias16), N'''' , N', @GlobalAttributeSource17 = ''', system.fMaskSQL(GlobalAttributeSource17), N'''' , N', @GlobalAttributeAlias17 = ''', system.fMaskSQL(GlobalAttributeAlias17), N'''' , N', @GlobalAttributeSource18 = ''', system.fMaskSQL(GlobalAttributeSource18), N'''' , N', @GlobalAttributeAlias18 = ''', system.fMaskSQL(GlobalAttributeAlias18), N'''' , N', @GlobalAttributeSource19 = ''', system.fMaskSQL(GlobalAttributeSource19), N'''' , N', @GlobalAttributeAlias19 = ''', system.fMaskSQL(GlobalAttributeAlias19), N'''' , N', @GlobalAttributeSource20 = ''', system.fMaskSQL(GlobalAttributeSource20), N'''' , N', @GlobalAttributeAlias20 = ''', system.fMaskSQL(GlobalAttributeAlias20), N'''' , N', @GlobalAttributeSource21 = ''', system.fMaskSQL(GlobalAttributeSource21), N'''' , N', @GlobalAttributeAlias21 = ''', system.fMaskSQL(GlobalAttributeAlias21), N'''' , N', @GlobalAttributeSource22 = ''', system.fMaskSQL(GlobalAttributeSource22), N'''' , N', @GlobalAttributeAlias22 = ''', system.fMaskSQL(GlobalAttributeAlias22), N'''' , N', @GlobalAttributeSource23 = ''', system.fMaskSQL(GlobalAttributeSource23), N'''' , N', @GlobalAttributeAlias23 = ''', system.fMaskSQL(GlobalAttributeAlias23), N'''' , N', @GlobalAttributeSource24 = ''', system.fMaskSQL(GlobalAttributeSource24), N'''' , N', @GlobalAttributeAlias24 = ''', system.fMaskSQL(GlobalAttributeAlias24), N'''' , N', @GlobalAttributeSource25 = ''', system.fMaskSQL(GlobalAttributeSource25), N'''' , N', @GlobalAttributeAlias25 = ''', system.fMaskSQL(GlobalAttributeAlias25), N'''' , N', @LayoutJSON = ''', system.fMaskSQL(LayoutJSON), N'''' , N';' ) FROM planning.tdProductLines WHERE ProductLineKey = @ProductLineKey; -- POST Products INSERT INTO @ExportTable SELECT 2000 , 1 , CONCAT( N'EXEC planning.spPOST_ProductEmpty' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @TimeType = ''', TimeType, N'''' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(system.fUnifyLinebreaks(CommentUser)), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ResponsiblePerson = ''', system.fMaskSQL(ResponsiblePerson), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @Status = ''', system.fMaskSQL([Status]), N'''' , N', @Template = ''', system.fMaskSQL(Template), N'''' , N', @TemplateVersion = ''', system.fMaskSQL(TemplateVersion), N'''' , N', @GA1 = ''', system.fMaskSQL(GlobalAttribute1), N'''' , N', @GA2 = ''', system.fMaskSQL(GlobalAttribute2), N'''' , N', @GA3 = ''', system.fMaskSQL(GlobalAttribute3), N'''' , N', @GA4 = ''', system.fMaskSQL(GlobalAttribute4), N'''' , N', @GA5 = ''', system.fMaskSQL(GlobalAttribute5), N'''' , N', @GA6 = ''', system.fMaskSQL(GlobalAttribute6), N'''' , N', @GA7 = ''', system.fMaskSQL(GlobalAttribute7), N'''' , N', @GA8 = ''', system.fMaskSQL(GlobalAttribute8), N'''' , N', @GA9 = ''', system.fMaskSQL(GlobalAttribute9), N'''' , N', @GA10 = ''', system.fMaskSQL(GlobalAttribute10), N'''' , N', @GA11 = ''', system.fMaskSQL(GlobalAttribute11), N'''' , N', @GA12 = ''', system.fMaskSQL(GlobalAttribute12), N'''' , N', @GA13 = ''', system.fMaskSQL(GlobalAttribute13), N'''' , N', @GA14 = ''', system.fMaskSQL(GlobalAttribute14), N'''' , N', @GA15 = ''', system.fMaskSQL(GlobalAttribute15), N'''' , N', @GA16 = ''', system.fMaskSQL(GlobalAttribute16), N'''' , N', @GA17 = ''', system.fMaskSQL(GlobalAttribute17), N'''' , N', @GA18 = ''', system.fMaskSQL(GlobalAttribute18), N'''' , N', @GA19 = ''', system.fMaskSQL(GlobalAttribute19), N'''' , N', @GA20 = ''', system.fMaskSQL(GlobalAttribute20), N'''' , N', @GA21 = ''', system.fMaskSQL(GlobalAttribute21), N'''' , N', @GA22 = ''', system.fMaskSQL(GlobalAttribute22), N'''' , N', @GA23 = ''', system.fMaskSQL(GlobalAttribute23), N'''' , N', @GA24 = ''', system.fMaskSQL(GlobalAttribute24), N'''' , N', @GA25 = ''', system.fMaskSQL(GlobalAttribute25), N'''' , N';' ) FROM planning.tdProducts WHERE ProductLineKey = @ProductLineKey; -- ValueSeries INSERT INTO @ExportTable SELECT 3000 , ROW_NUMBER() OVER (ORDER BY FactoryID, ProductLineID, ProductID, ValueSeriesNo) AS RowNumber , CONCAT( N'EXEC planning.spPOST_ValueSerie' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @ValueSeriesID = ''', ValueSeriesID, N'''' , N', @RequestedValueSeriesNo = ''', ValueSeriesNo, N'''' , N', @NameShort = ''', system.fMaskSQL(NameShort), N'''' , N', @NameLong = ''', system.fMaskSQL(NameLong), N'''' , N', @CommentUser = ''', system.fMaskSQL(system.fUnifyLinebreaks(CommentUser)), N'''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), N'''' , N', @ImageName = ''', system.fMaskSQL(ImageName), N'''' , N', @IsNumeric = ''', [IsNumeric], N'''' , N', @VisibilityLevel = ''', VisibilityLevel, N'''' , N', @ValueSource = ''', ValueSource, N'''' , N', @ValueListID = ''', ValueListID, N'''' , N', @ValueFormatID = ''', ValueFormatID, N'''' , N', @Unit = ''', Unit, N'''' , N', @Scale = ''', Scale, N'''' , N', @Effect = ''', Effect, N'''' , N', @EffectParameter = ''', EffectParameter, N'''' , N', @AllowZero = ''', AllowZero, N'''' , N';' ) FROM planning.tdValueSeries WHERE ProductLineKey = @ProductLineKey ORDER BY FactoryID , ProductLineID , ProductID , ValueSeriesNo; -- Time WITH tms AS ( SELECT dP.ProductID , dP.ProductLineID , ( SELECT N'[(' + CAST(t.TimeID AS NVARCHAR(10)) + N',0,0,''''' + FormatID + ''''')],' -- with DeleteFlag, AddValue,FormatID FROM planning.tdTime t WHERE t.ProductKey = dP.ProductKey ORDER BY t.TimeID FOR XML PATH(N''), TYPE ).value(N'.[1]', N'NVARCHAR(MAX)') AS vals FROM planning.tdProducts AS dP WHERE dP.ProductLineKey = @ProductLineKey ) INSERT INTO @ExportTable SELECT 4000 , 1 , CONCAT( N'EXEC planning.spPOST_Timeline' , N' @Username = @Username' , N', @ProductID = ''', ProductID, N'''' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @IsIncrementalValuesFlag = 1' , N', @TimeIDsInBracketsCommaSeparated = ''', LEFT(vals, LEN(vals) - 1), N'''' , N';' ) FROM tms WHERE vals IS NOT NULL; -- POST ProductDataTableValues WITH tms AS ( SELECT dP.ProductID , dP.ProductLineID , ( SELECT CONCAT( N'[(''''' , ValueSeriesID, N''''',' , CAST(TimeID AS NVARCHAR(255)), N',''''' , ValueFormula, N''''',''''' , CAST(ValueInt AS NVARCHAR(255)), N''''',''''' , system.fMaskSQL(ValueText), N''''',''''' , system.fMaskSQL(system.fUnifyLinebreaks(ValueComment)) , N''''')],' ) FROM planning.tfValues AS t WHERE t.ProductKey = dP.ProductKey FOR XML PATH(N''), TYPE ).value(N'.[1]', N'NVARCHAR(MAX)') AS vals FROM planning.tdProducts AS dP WHERE dP.ProductLineKey = @ProductLineKey ) INSERT INTO @ExportTable SELECT 5000 , 1 , CONCAT( N'EXEC planning.spPOST_ProductDataTableValues' , N' @Username = @Username' , N', @ProductID = ''', ProductID, '''' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N' @IsIncrementalValuesFlag = 0' , N', @ValuesInBracketsCommaSeparated = ''', LEFT(vals, LEN(vals) - 1), N'''' , N';' ) FROM tms WHERE vals IS NOT NULL; -- POST ProductLine Properties INSERT INTO @ExportTable SELECT 6001 , 1 , CONCAT( N'EXEC planning.spPOST_ProductLineProperty' , N' @Username = @Username' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @PropertyID = ''', PropertyID, '''' , N', @PropertyName = ''', system.fMaskSQL(PropertyName), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Unit = ''', Unit, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @IsROSystemProperty = ''', IsROSystemProperty, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.tgProductLines WHERE ProductLineKey = @ProductLineKey; -- POST Product Properties INSERT INTO @ExportTable SELECT 6002 , 1 , CONCAT( N'EXEC planning.spPOST_ProductProperty' , N' @Username = @Username' , N', @ProductID = ''', ProductID, '''' , N', @ProductLineID = @ProductLineID' , N', @FactoryID = @FactoryID' , N', @PropertyID = ''', PropertyID, '''' , N', @PropertyName = ''', system.fMaskSQL(PropertyName), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Unit = ''', Unit, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @IsROSystemProperty = ''', IsROSystemProperty, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.tgProducts WHERE ProductLineKey = @ProductLineKey; -- POST Tabs INSERT INTO @ExportTable SELECT 6003 , Row_Number() OVER (ORDER BY FactoryID, ProductLineID, ProductID, OrderIndex) AS Row , CONCAT( N'EXEC planning.spPOST_Tab' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @ProductLineID = @ProductLineID' , N', @ProductID = ''', ProductID, '''' , N', @TabID = ''', TabID, '''' , N', @OrderIndex = ''', OrderIndex, '''' , N', @TabName = ''', system.fMaskSQL(TabName), '''' , N', @TabHint = ''', system.fMaskSQL(TabHint), '''' , N', @TabText = ''', system.fMaskSQL(TabText), '''' , N', @PresentationCODE = ''', system.fMaskSQL(PresentationCODE), '''' , N', @Datasource = ''', system.fMaskSQL(Datasource), '''' , N', @IsVisibleBOOL = ''', IsVisibleBOOL, '''' , N', @LayoutJSON = ''''' , N', @ParameterJSON = ''', system.fMaskSQL(ParameterJSON), '''' , N', @SQLCommand = ''', system.fMaskSQL(SQLCommand), '''' , N', @StartPage = ''', StartPage, '''' , N';' ) FROM planning.tTabs WHERE ProductLineKey = @ProductLineKey; -- POST TabLayouts INSERT INTO @ExportTable SELECT 6004 , Row_Number() OVER (ORDER BY FactoryID, ProductLineID, TabID, LayoutOwner, OrderIndex) AS Row , CONCAT( N'EXEC planning.spPOST_TabLayout' , N' @Username = @Username' , N', @FactoryID = @FactoryID' , N', @ProductLineID = @ProductLineID' , N', @TabID = ''', TabID, '''' , N', @LayoutID = ''', LayoutID, '''' , N', @LayoutName = ''', system.fMaskSQL(LayoutName), '''' , N', @LayoutJSON = ''', system.fMaskSQL(LayoutJSON), '''' , N', @OrderIndex = ''', OrderIndex, '''' , N', @LayoutOwner = ''', LayoutOwner, '''' , N', @StartPage = ''', StartPage, '''' , N';' ) FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID; -- POST Lists INSERT INTO @ExportTable SELECT 7001 , 1 , CONCAT( N'EXEC planning.spPOST_List' , N' @Username = @Username' , N', @ListID = ''', ListID, '''' , N', @NameShort = ''', system.fMaskSQL(NameShort), '''' , N', @NameLong = ''', system.fMaskSQL(NameLong), '''' , N', @CommentUser = ''', system.fMaskSQL(CommentUser), '''' , N', @CommentDev = ''', system.fMaskSQL(CommentDev), '''' , N', @Datentyp = ''', Datentyp, '''' , N', @Source = ''', Source, '''' , N', @SourceFormula = ''', SourceFormula, '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.thLists WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ); -- POST List Values INSERT INTO @ExportTable SELECT 7002 , 1 , CONCAT( N'EXEC planning.spPOST_ListValue' , N' @Username = @Username' , N', @ListValueKey = 0' , N', @ListID = ''', ListID, '''' , N', @ValueInt = ''', ValueInt, '''' , N', @Scale = ''', Scale, '''' , N', @ValueText = ''', system.fMaskSQL(ValueText), '''' , N', @ValueComment = ''', system.fMaskSQL(ValueComment), '''' , N', @FormatID = ''', FormatID, '''' , N';' ) FROM planning.thListValues WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ); -- POST Formats WITH DependendFormats AS ( -- used in depended lists from global attributes SELECT DISTINCT FormatID FROM planning.thListValues WHERE ListID IN ( SELECT ListID COLLATE DATABASE_DEFAULT FROM @DependendListIDs ) -- used to format ValueSeries UNION SELECT DISTINCT ValueFormatID FROM planning.tdValueSeries WHERE ProductLineKey = @ProductLineKey -- used to format Timeline UNION SELECT DISTINCT FormatID FROM planning.tdTime WHERE ProductLineKey = @ProductLineKey -- used to format Ranges UNION SELECT DISTINCT FormatID FROM planning.tgProducts WHERE ProductLineKey = @ProductLineKey AND PropertyID LIKE N'PDTRange_%' ) INSERT INTO @ExportTable SELECT 7003 , 1 , CONCAT( N'EXEC planning.spPOST_Format' , N' @Username = @Username' , N', @FormatID = ''', FormatID, '''' , N', @BackgroundColor = ''', BackgroundColor, '''' , N', @FontColor = ''', FontColor, '''' , N', @ValueFormat = ''', ValueFormat, '''' , N', @Bold = ''', Bold, '''' , N', @Italic = ''', Italic, '''' , N', @AlignmentHorizontal = ''', AlignmentHorizontal, '''' , N', @AlignmentVertical = ''', AlignmentVertical, '''' , N', @TextUnderlined = ''', TextUnderlined, '''' , N', @BorderToNext = ''', BorderToNext, '''' , N', @BorderToPrevious = ''', BorderToPrevious, '''' , N';' ) FROM planning.thFormats WHERE FormatID IN ( SELECT DISTINCT FormatID FROM DependendFormats WHERE LEN(FormatID) > 0 ); INSERT INTO @ExportTable VALUES ( 8000 , 1 , N'GO' ); -- Output SELECT Command FROM @ExportTable ORDER BY StepNumber , RowNumber; SET @AffectedRows = @@ROWCOUNT; SET @ResultCode = 200 END TRY BEGIN CATCH SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spEXPORT_ProductLine'-- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'EXPORT operation of a single productline, including,properties in gtables, global attributes, products, values, dependend lists, which have to be merged in the existing lists during import in two styles: one for import as sql script, one for Import over the GUI Import'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'FactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'ProductLineID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@OutputForSQLServer'; SET @value = N'OutputForSQLServer - no longer in use.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spPOST_ValueSerie; GO /* POST Operation for one ValueSeries Operation will create a ValueSeries if it not exist It will change an existing ValueSeries Works under the assumtion, that the ValueSeries ID is not changed ! The ID is used to identify the valueSeries Saxess Software GmbH Last modified: 01/2024 for OCT 5.10 Test call DECLARE @RC INT ,@Username NVARCHAR(255) ='SQL' ,@ProductID NVARCHAR(255) ='1' ,@ProductLineID NVARCHAR(255) ='U' ,@FactoryID NVARCHAR(255) ='ZT' ,@ValueSeriesID NVARCHAR(255) ='38550' ,@RequestedValueSeriesNo INT = 249 ,@NameShort NVARCHAR(255) ='<#NV>' ,@NameLong NVARCHAR(255) ='<#NV>' ,@CommentUser NVARCHAR(255) ='<#NV>' ,@CommentDev NVARCHAR(255) ='<#NV>' ,@ImageName NVARCHAR(255) ='<#NV>' ,@IsNumeric NVARCHAR(255) ='1' ,@VisibilityLevel NVARCHAR(255) ='<#NV>' ,@ValueSource NVARCHAR(255) ='<#NV>' ,@ValueListID NVARCHAR(255) ='<#NV>' ,@ValueFormatID NVARCHAR(255) ='<#NV>' ,@Unit NVARCHAR(255) ='<#NV>' ,@Scale NVARCHAR(255) ='100' ,@Effect NVARCHAR(255) ='<#NV>' ,@EffectParameter NVARCHAR(255) ='<#NV>' ,@AllowZero INT = 0 EXECUTE @RC = planning.spPOST_ValueSerie @Username, @ProductID, @ProductLineID, @FactoryID, @ValueSeriesID, @RequestedValueSeriesNo, @NameShort, @NameLong, @CommentUser, @CommentDev, @ImageName, @IsNumeric, @VisibilityLevel, @ValueSource, @ValueListID, @ValueFormatID, @Unit, @Scale, @Effect, @EffectParameter, @AllowZero PRINT @RC Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_ValueSerie',NULL,NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_ValueSerie','PARAMETER',NULL) */ CREATE PROCEDURE planning.spPOST_ValueSerie @Username NVARCHAR(255), @ProductID NVARCHAR(255), @ProductLineID NVARCHAR(255), @FactoryID NVARCHAR(255), @ValueSeriesID NVARCHAR(255), @RequestedValueSeriesNo INT, @NameShort NVARCHAR(255), @NameLong NVARCHAR(255), @CommentUser NVARCHAR(255), @CommentDev NVARCHAR(255), @ImageName NVARCHAR(255), @IsNumeric NVARCHAR(255), @VisibilityLevel NVARCHAR(255), @ValueSource NVARCHAR(255), @ValueListID NVARCHAR(255), @ValueFormatID NVARCHAR(255), @Unit NVARCHAR(255), @Scale NVARCHAR(255), @Effect NVARCHAR(255), @EffectParameter NVARCHAR(255), @AllowZero INT = 0 AS BEGIN SET NOCOUNT ON; DECLARE @TransactUsername NVARCHAR(255) = N''; DECLARE @FactoryKey INT = 0; DECLARE @ProductLineKey INT = 0; DECLARE @ProductKey INT = 0; DECLARE @ValueSeriesKey INT = 0; DECLARE @OldValueSeriesNo INT = 0; DECLARE @OldIsNumeric INT = 0; DECLARE @OldScale INT = 0; DECLARE @OldValueSource NVARCHAR(255) = N''; DECLARE @ProcedureName NVARCHAR (255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @ParameterString NVARCHAR (MAX) = N'''' + ISNULL(@Username, N'NULL') + N''',''' + ISNULL(@ProductID, N'NULL') + N''',''' + ISNULL(@ProductLineID, N'NULL') + N''',''' + ISNULL(@FactoryID, N'NULL') + N''',''' + ISNULL(@ValueSeriesID, N'NULL') + N''',' + ISNULL(CAST(@RequestedValueSeriesNo AS NVARCHAR(255)), N'NULL') + N',''' + ISNULL(@NameShort, N'NULL') + N''',''' + ISNULL(@NameLong, N'NULL') + N''',''' + ISNULL(@CommentUser, N'NULL') + N''',''' + ISNULL(@CommentDev, N'NULL') + N''',''' + ISNULL(@ImageName, N'NULL') + N''',''' + ISNULL(@IsNumeric, N'NULL') + N''',''' + ISNULL(@VisibilityLevel, N'NULL') + N''',''' + ISNULL(@ValueSource, N'NULL') + N''',''' + ISNULL(@ValueListID, N'NULL') + N''',''' + ISNULL(@ValueFormatID, N'NULL') + N''',''' + ISNULL(@Unit, N'NULL') + N''',''' + ISNULL(@Scale, N'NULL') + N''',''' + ISNULL(@Effect, N'NULL') + N''',''' + ISNULL(@EffectParameter, N'NULL') + N''',' + ISNULL(CAST(@AllowZero AS NVARCHAR(255)), N'NULL') ; DECLARE @EffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @Comment NVARCHAR(2000) = N''; -- STEP 0.1 - NULL Protection IF @Username IS NULL SET @Username = N''; IF @ProductID IS NULL SET @ProductID = N'NULL'; IF @ProductLineID IS NULL SET @ProductLineID = N'NULL'; IF @FactoryID IS NULL SET @FactoryID = N'NULL'; IF @ValueSeriesID IS NULL SET @ValueSeriesID = N'NULL'; IF @RequestedValueSeriesNo IS NULL SET @RequestedValueSeriesNo = 0; IF @NameShort IS NULL SET @NameShort = N'NULL'; IF @NameLong IS NULL SET @NameLong = N'NULL'; IF @CommentUser IS NULL SET @CommentUser = N'NULL'; IF @CommentDev IS NULL SET @CommentDev = N'NULL'; IF @ImageName IS NULL SET @ImageName = N'NULL'; IF @IsNumeric IS NULL SET @IsNumeric = N'NULL'; IF @VisibilityLevel IS NULL SET @VisibilityLevel = N'NULL'; IF @ValueSource IS NULL SET @ValueSource = N'NULL'; IF @ValueListID IS NULL SET @ValueListID = N'NULL'; IF @ValueFormatID IS NULL SET @ValueFormatID = N'NULL'; IF @Unit IS NULL SET @Unit = N'NULL'; IF @Scale IS NULL SET @Scale = N'NULL'; IF @Effect IS NULL SET @Effect = N'NULL'; IF @EffectParameter IS NULL SET @EffectParameter = N'NULL'; IF @AllowZero IS NULL SET @AllowZero = N'NULL'; BEGIN TRY BEGIN TRANSACTION sx_pf_POST_ValueSerie; -- STEP 0.1 - NULL Protection SET @ProductID = system.fProtectID (@ProductID); SET @ProductLineID = system.fProtectID (@ProductLineID); SET @FactoryID = system.fProtectID (@FactoryID); SET @ValueSeriesID = system.fProtectID (@ValueSeriesID); SET @NameShort = system.fProtectString (@NameShort); SET @NameLong = system.fProtectString (@NameLong); SET @CommentUser = system.fProtectString (@CommentUser); SET @CommentDev = system.fProtectString (@CommentDev); SET @ImageName = system.fProtectString (@ImageName); SET @IsNumeric = system.fProtectBoolean (@IsNumeric); SET @VisibilityLevel = system.fProtectString (@VisibilityLevel); SET @ValueSource = system.fProtectString (@ValueSource); SET @Unit = system.fProtectString (@Unit); SET @Scale = system.fProtectInt (@Scale); SET @Effect = system.fProtectString (@Effect); SET @EffectParameter = system.fProtectString (@EffectParameter); SET @Allowzero = system.fProtectInt (@AllowZero); IF @ValueListID <> N'<#NV>' SET @ValueListID = system.fProtectID (@ValueListID); IF @ValueFormatID <> N'<#NV>' SET @ValueFormatID = system.fProtectID (@ValueFormatID); IF @FactoryID = N'' OR @ProductLineID = N'' OR @ProductID = N'' OR @ValueSeriesID = N'' BEGIN SET @ResultCode = 404; RAISERROR('Empty input parameters', 16, 10); END; -- STEP 1.1 - Determine transaction user SELECT @TransactUsername = system.fDetermineTransactionUsername (@Username); IF @TransactUsername = N'403' BEGIN SET @ResultCode = 403; RAISERROR('Transaction user don`t exists', 16, 10); END; -- STEP 1.2 - Determine keys SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID; SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID; SELECT @ProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @ProductLinekey AND ProductID= @ProductID; SELECT @ValueSeriesKey = ValueSeriesKey ,@OldIsNumeric = IsNumeric ,@OldScale = Scale ,@OldValueSource = ValueSource FROM planning.tdValueSeries WHERE ProductKey = @ProductKey AND ValueSeriesID = @ValueSeriesID; IF @FactoryKey = 0 OR @ProductLineKey = 0 OR @ProductKey = 0 BEGIN SET @ResultCode = 404; RAISERROR('Keys don`t exists', 16, 10); END; -- STEP 2 - Check rights EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 RAISERROR('Invalid rights', 16, 10); -- if ValueSeriesID ends with '_0' then zeros are always allowed (old logic) IF RIGHT(@ValueSeriesID, 2) = '_0' SET @AllowZero = 1; -- STEP 3.1 - Insert the ValueSeries, if Key does not exist IF @ValueSeriesKey = 0 BEGIN -- INCREMENT all following Requested ValueSeriesNumbers based on requested No UPDATE planning.tdValueSeries SET ValueSeriesNo = ValueSeriesNo + 1 WHERE ProductKey = @ProductKey AND ValueSeriesNo >= @RequestedValueSeriesNo; IF @VisibilityLevel = '<#NV>' SET @VisibilityLevel = 1; SET @EffectedRows = @@ROWCOUNT; DECLARE @Keys AS TABLE ([Key] INT NOT NULL); -- Insert with requested number INSERT INTO planning.tdValueSeries ( ProductKey ,ProductLineKey ,FactoryKey ,ProductID ,ProductLineID ,FactoryID ,ValueSeriesID ,ValueSeriesNo ,NameShort ,NameLong ,CommentUser ,CommentDev ,ImageName ,IsNumeric ,VisibilityLevel ,ValueSource ,ValueListID ,ValueFormatID ,Unit ,Scale ,Effect ,EffectParameter ,AllowZero) OUTPUT INSERTED.ValueSeriesKey INTO @Keys([Key]) VALUES ( @ProductKey ,@ProductLineKey ,@FactoryKey ,@ProductID ,@ProductLineID ,@FactoryID ,@ValueSeriesID ,@RequestedValueSeriesNo ,@NameShort,@NameLong ,@CommentUser ,@CommentDev ,@ImageName ,@IsNumeric ,@VisibilityLevel ,@ValueSource ,@ValueListID ,@ValueFormatID ,@Unit ,@Scale ,@Effect ,@EffectParameter ,@AllowZero); SET @EffectedRows += @@ROWCOUNT; SELECT TOP (1) @ValueSeriesKey = [Key] FROM @Keys ORDER BY [Key]; END ELSE BEGIN -- STEP 3.2 - Update ValueSeries if it already exists SELECT @OldValueSeriesNo = ValueSeriesNo FROM planning.tdValueSeries WHERE ValueSeriesKey = @ValueSeriesKey; -- Use the old one, if no SeriesNo is commited (lower than one means not commited) IF @RequestedValueSeriesNo < 1 SET @RequestedValueSeriesNo = @OldValueSeriesNo; -- Adjust Numbers if not equal IF @OldValueSeriesNo < @RequestedValueSeriesNo BEGIN -- decrement all between actual and requsted Position UPDATE planning.tdValueSeries SET ValueSeriesNo = ValueSeriesNo - 1 WHERE ProductKey = @ProductKey AND ValueSeriesNo > @OldValueSeriesNo AND ValueSeriesNo <= @RequestedValueSeriesNo; SET @EffectedRows += @@ROWCOUNT; END ELSE IF @OldValueSeriesNo > @RequestedValueSeriesNo BEGIN -- increment all between actual and requsted Position UPDATE planning.tdValueSeries SET ValueSeriesNo = ValueSeriesNo + 1 WHERE ProductKey = @ProductKey AND ValueSeriesNo < @OldValueSeriesNo AND ValueSeriesNo >= @RequestedValueSeriesNo; SET @EffectedRows += @@ROWCOUNT; END; UPDATE planning.tdValueSeries SET ValueSeriesNo = @RequestedValueSeriesNo , NameShort = IIF(@NameShort = N'<#NV>', NameShort, @NameShort) , NameLong = IIF(@NameLong = N'<#NV>', NameLong, @NameLong) , CommentUser = IIF(@CommentUser = N'<#NV>', CommentUser, @CommentUser) , CommentDev = IIF(@CommentDev = N'<#NV>', CommentDev, @CommentDev) , ImageName = IIF(@ImageName = N'<#NV>', ImageName, @ImageName) , IsNumeric = IIF(@IsNumeric = N'<#NV>', IsNumeric, @IsNumeric) , VisibilityLevel = IIF(@VisibilityLevel = N'<#NV>', VisibilityLevel, @VisibilityLevel) , ValueSource = IIF(@ValueSource = N'<#NV>', ValueSource, @ValueSource) , ValueListID = IIF(@ValueListID = N'<#NV>', ValueListID, @ValueListID) , ValueFormatID = IIF(@ValueFormatID = N'<#NV>', ValueFormatID, @ValueFormatID) , Unit = IIF(@Unit = N'<#NV>', Unit, @Unit) , Scale = IIF(@Scale = N'<#NV>', Scale, @Scale) , Effect = IIF(@Effect = N'<#NV>', Effect, @Effect) , EffectParameter = IIF(@EffectParameter = N'<#NV>', EffectParameter, @EffectParameter) , AllowZero = @AllowZero FROM planning.tdValueSeries WHERE ValueSeriesKey = @ValueSeriesKey; SET @EffectedRows += @@ROWCOUNT; -- STEP 3.2a - Delete zero values if ValueSeries is now numeric input series IF @IsNumeric = '1' AND @ValueSource = N'Input' BEGIN DELETE FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey AND ValueInt = 0; END; -- Step 3.2b - Delete empty Strings if ValueSeries is now non-numeric input series IF @IsNumeric = '0' AND @ValueSource = N'Input' BEGIN DELETE FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey AND ValueText = N''; END; -- STEP 3.3 - Update exists Values due to possible rescaling or changing type from Numeric to Non-Numeric DECLARE @vals AS TABLE (ValueKey INT NOT NULL, ValueInt INT NOT NULL, ValueText NVARCHAR(MAX) NOT NULL); -- Changing type Numeric / Non Numeric IF (@IsNumeric <> N'<#NV>' AND @OldIsNumeric <> @IsNumeric) BEGIN -- Copy ValueText to ValueInt, after Try_Cast to Int to get only valid numbers and multiplied by OldScale, as the int values use scale, while the text value not IF @IsNumeric = N'1' BEGIN INSERT INTO @vals (ValueKey, ValueInt, ValueText) SELECT ValueKey, ISNULL(TRY_CAST(ValueText AS INT), 0) * @OldScale, '' FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey; END ELSE BEGIN -- If Numeric is made to non numeric the value in the Database must be be divided by scale and converted to text, as text dont uses scale IF (@OldScale <> 0) BEGIN INSERT INTO @vals (ValueKey, ValueInt, ValueText) SELECT ValueKey, 0, CAST(ValueInt / @OldScale AS NVARCHAR(MAX)) FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey; END ELSE BEGIN INSERT INTO @vals (ValueKey, ValueInt, ValueText) SELECT ValueKey, 0, CAST(ValueInt AS NVARCHAR(MAX)) FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey; END; END; END; -- changing scaling -- If Isnumeric = 0 and not changed Nothing happens with the value, if scale is changed, as text values dont use the scale property. IF (@Scale <> N'<#NV>' AND @OldScale <> @Scale) AND (@IsNumeric = N'1' OR (@IsNumeric = N'<#NV>' AND @OldIsNumeric = 1)) AND @OldScale <> 0 BEGIN -- Change Scale of existing values if scale is changed (when scale is changed, e.g. from 100 to 1000 the value in the database must be multiplied by 10) DECLARE @k FLOAT = @Scale / CAST(@OldScale AS FLOAT); IF NOT EXISTS(SELECT 1 FROM @vals) BEGIN INSERT INTO @vals (ValueKey, ValueInt, ValueText) SELECT ValueKey, ValueInt * @k, '' FROM planning.tfValues WHERE ValueSeriesKey = @ValueSeriesKey; END ELSE BEGIN UPDATE @vals SET ValueInt = ValueInt * @k; END; END; IF EXISTS(SELECT 1 FROM @vals) BEGIN UPDATE v SET v.ValueInt = newV.ValueInt ,v.ValueText = newV.ValueText FROM planning.tfValues v INNER JOIN @vals newV ON v.ValueKey = newV.ValueKey WHERE v.ValueSeriesKey = @ValueSeriesKey; SET @EffectedRows += @@ROWCOUNT; END; END; SET @Resultcode = 201; COMMIT TRANSACTION sx_pf_POST_ValueSerie; END TRY BEGIN CATCH DECLARE @Error_state INT = ERROR_STATE(); SET @Comment = ERROR_MESSAGE(); ROLLBACK TRANSACTION sx_pf_POST_ValueSerie; IF @Error_state <> 10 BEGIN SET @ResultCode = 500; PRINT 'Rollback due to not executable command.'; END ELSE IF @ResultCode IS NULL OR @ResultCode/100 = 2 BEGIN SET @ResultCode = 500; END; END CATCH EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @EffectedRows, @ResultCode, @TimestampCall, @Comment; RETURN @ResultCode; END GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spPOST_ValueSerie' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'POST Operation for one ValueSeries Operation will create a ValueSeries if it not exist It will change an existing ValueSeries Works under the assumtion, that the ValueSeries ID is not changed ! The ID is used to identify the valueSeries'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductID'; SET @value = N'ProductID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'ProductLineID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'FactoryID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ValueSeriesID'; SET @value = N'ValueSeriesID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@RequestedValueSeriesNo'; SET @value = N'RequestedValueSeriesNo'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@NameShort'; SET @value = N'NameShort'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@NameLong'; SET @value = N'NameLong'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@CommentUser'; SET @value = N'CommentUser'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@CommentDev'; SET @value = N'CommentDev'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ImageName'; SET @value = N'ImageName'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@IsNumeric'; SET @value = N'IsNumeric'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@VisibilityLevel'; SET @value = N'VisibilityLevel'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ValueSource'; SET @value = N'ValueSource'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ValueListID'; SET @value = N'ValueListID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ValueFormatID'; SET @value = N'ValueFormatID'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Unit'; SET @value = N'Unit'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Scale'; SET @value = N'Scale'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Effect'; SET @value = N'Effect'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@EffectParameter'; SET @value = N'EffectParameter'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spCOPY_Tab; GO /* Procedure to COPY a Tab inside a object or to another target Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spCOPY_Tab @Username = N'SQL' , @SourceFactoryID = N'' , @SourceProductLineID = N'' , @SourceProductID = N'' , @SourceTabID = N'TAB1' , @TargetFactoryID = N'' , @TargetProductLineID = N'' , @TargetProductID = N'' , @TargetTabID = N'TAB2' , @TargetOrderIndex = 99 , @TargetTabName = 'TAB2' , @SourceStartPage = 0 , @TargetStartPage = 0; PRINT @RC; SELECT * FROM planning.tTabs; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_Tab',NULL,NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spCOPY_Tab','PARAMETER',NULL) */ CREATE PROCEDURE planning.spCOPY_Tab @Username NVARCHAR(255) , @SourceFactoryID NVARCHAR(255) = N'' , @SourceProductLineID NVARCHAR(255) = N'' , @SourceProductID NVARCHAR(255) = N'' , @SourceTabID NVARCHAR(255) , @TargetFactoryID NVARCHAR(255) = N'' , @TargetProductLineID NVARCHAR(255) = N'' , @TargetProductID NVARCHAR(255) = N'' , @TargetTabID NVARCHAR(255) , @TargetOrderIndex INT = 1 , @TargetTabName NVARCHAR(255) , @SourceStartPage BIT = 0 , @TargetStartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 13, @Username, @SourceFactoryID, @SourceProductLineID, @SourceProductID, @SourceTabID, @TargetFactoryID, @TargetProductLineID, @TargetProductID, @TargetTabID, @TargetOrderIndex, @TargetTabName, @SourceStartPage, @TargetStartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @SourceFactoryKey INT = 0; DECLARE @SourceProductLineKey INT = 0; DECLARE @SourceProductKey INT = 0; DECLARE @TargetFactoryKey INT = 0; DECLARE @TargetProductLineKey INT = 0; DECLARE @TargetProductKey INT = 0; DECLARE @RowKey BIGINT = 0; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @SourceFactoryID = COALESCE(system.fProtectID(@SourceFactoryID), N''); SET @SourceProductLineID = COALESCE(system.fProtectID(@SourceProductLineID), N''); SET @SourceProductID = COALESCE(system.fProtectID(@SourceProductID), N''); SET @SourceTabID = COALESCE(system.fProtectID(@SourceTabID), N''); SET @TargetFactoryID = COALESCE(system.fProtectID(@TargetFactoryID), N''); SET @TargetProductLineID = COALESCE(system.fProtectID(@TargetProductLineID), N''); SET @TargetProductID = COALESCE(system.fProtectID(@TargetProductID), N''); SET @TargetTabID = COALESCE(system.fProtectID(@TargetTabID), N''); SET @TargetOrderIndex = COALESCE(@TargetOrderIndex, 1); SET @TargetTabName = COALESCE(@TargetTabName, N''); SET @SourceStartPage = COALESCE(@SourceStartPage, 0); SET @TargetStartPage = COALESCE(@TargetStartPage, 0); BEGIN TRANSACTION spCOPY_Tab -- Determine Keys IF @SourceFactoryID = '' SET @SourceFactoryKey = -1; IF @SourceProductLineID = '' SET @SourceProductLineKey = -1; IF @SourceProductID = '' SET @SourceProductKey = -1; IF @TargetFactoryID = '' SET @TargetFactoryKey = -1; IF @TargetProductLineID = '' SET @TargetProductLineKey = -1; IF @TargetProductID = '' SET @TargetProductKey = -1; SELECT @SourceFactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @SourceFactoryID AND @SourceFactoryKey <> -1; SELECT @SourceProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @SourceFactoryKey AND ProductLineID = @SourceProductLineID AND @SourceProductLineKey <> -1; SELECT @SourceProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @SourceProductLineKey AND ProductID = @SourceProductID AND @SourceProductKey <> -1; SELECT @TargetFactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @TargetFactoryID AND @TargetFactoryKey <> -1; SELECT @TargetProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @TargetFactoryKey AND ProductLineID = @TargetProductLineID AND @TargetProductLineKey <> -1; SELECT @TargetProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @TargetProductLineKey AND ProductID = @TargetProductID AND @TargetProductKey <> -1; -- Check if IDs exist IF @SourceFactoryKey = 0 EXEC system.spSEND_Message 'ERROR', 'SourceFactory doesn''t exists.'; IF @SourceProductLineKey = 0 EXEC system.spSEND_Message 'ERROR', 'SourceProductLine doesn''t exists.'; IF @SourceProductKey = 0 EXEC system.spSEND_Message 'ERROR', 'SourceProduct doesn''t exists.'; IF @TargetFactoryKey = 0 EXEC system.spSEND_Message 'ERROR', 'TargetFactory doesn''t exists.'; IF @TargetProductLineKey = 0 EXEC system.spSEND_Message 'ERROR', 'TargetProductLine doesn''t exists.'; IF @TargetProductKey = 0 EXEC system.spSEND_Message 'ERROR', 'TargetProduct doesn''t exists.'; -- Check if SourceTabID exists IF NOT EXISTS ( SELECT 1 FROM planning.tTabs WHERE FactoryKey = @SourceFactoryKey AND ProductLineKey = @SourceProductLineKey AND ProductKey = @SourceProductKey AND TabID = @SourceTabID AND StartPage = @SourceStartPage ) BEGIN EXEC system.spSEND_Message 'ERROR', 'Source TabID doesn''t exist.'; END; -- TabID 0 can't be moved IF @SourceTabID = '0' OR @TargetTabID = '0' BEGIN EXEC system.spSEND_Message 'ERROR', 'Tab with ID 0 can''t be copied.'; END -- Check user rights IF @TargetStartPage = 0 BEGIN -- Cluster IF @SourceFactoryKey = -1 BEGIN EXEC @ResultCode = planning.spGET_ClusterPropertiesReadRight @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Cluster read.'; END IF @TargetFactoryKey = -1 BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Cluster write.'; END -- Factory IF @SourceFactoryKey <> -1 AND @SourceProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryReadRight @TransactUsername, @SourceFactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Factory read.'; END IF @TargetFactoryKey <> -1 AND @TargetProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @TargetFactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Factory write.'; END -- ProductLine IF @SourceFactoryKey <> -1 AND @SourceProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineReadRight @TransactUsername, @SourceFactoryID, @SourceProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for ProductLine read.'; END IF @TargetFactoryKey <> -1 AND @TargetProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @TargetFactoryID, @TargetProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for ProductLine write.'; END END ELSE BEGIN IF( SELECT IsAdministratorFlag FROM system.trUser WHERE Username = @TransactUsername ) = 0 BEGIN EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for StartPage write (Administrators only).'; END END -- check if new TabID is free IF EXISTS ( SELECT 1 FROM planning.tTabs WHERE FactoryKey = @TargetFactoryKey AND ProductLineKey = @TargetProductLineKey AND ProductKey = @TargetProductKey AND TabID = @TargetTabID AND StartPage = @TargetStartPage ) BEGIN EXEC system.spSEND_Message 'ERROR', 'New TabID is already in use.'; END -- Copy TabLayouts INSERT INTO planning.tTabLayouts ( FactoryID , ProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage ) SELECT @TargetFactoryID , @TargetProductLineID , @TargetTabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , @TargetStartPage FROM planning.tTabLayouts WHERE FactoryID = @SourceFactoryID AND ProductLineID = @SourceProductLineID AND TabID = @SourceTabID AND StartPage = @SourceStartPage; -- Insert new Tab INSERT INTO planning.tTabs ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage ) SELECT @TargetFactoryKey , @TargetProductLineKey , @TargetProductKey , @TargetFactoryID , @TargetProductLineID , @TargetProductID , @TargetTabID , @TargetOrderIndex , @TargetTabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , @TargetStartPage FROM planning.tTabs WHERE FactoryKey = @SourceFactoryKey AND ProductLineKey = @SourceProductLineKey AND ProductKey = @SourceProductKey AND TabID = @SourceTabID AND StartPage = @SourceStartPage; -- Increment all Tabs after the inserted Tab and the Tab with the same OrderIndex UPDATE planning.tTabs SET Orderindex = Orderindex + 1 WHERE FactoryKey = @TargetFactoryKey AND ProductLineKey = @TargetProductLineKey AND ProductKey = @TargetProductKey AND Orderindex >= @TargetOrderIndex AND TabID <> @TargetTabID AND StartPage = @TargetStartPage; -- Eliminate all Gaps in Tab OrderIndex UPDATE planning.tTabs SET Orderindex = Rownumbers.Number FROM planning.tTabs AS tT INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY Orderindex) AS Number , TabID FROM planning.tTabs WHERE FactoryKey = @TargetFactoryKey AND ProductLineKey = @TargetProductLineKey AND ProductKey = @TargetProductKey AND StartPage = @TargetStartPage ) AS Rownumbers ON tT.TabID = Rownumbers.TabID AND tT.FactoryKey = @TargetFactoryKey AND tT.ProductLineKey = @TargetProductLineKey AND tT.ProductKey = @TargetProductKey AND tT.StartPage = @TargetStartPage; COMMIT TRANSACTION spCOPY_Tab; SET @ResultCode = 201 END TRY BEGIN CATCH ROLLBACK TRANSACTION spCOPY_Tab; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spCOPY_Tab' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = not shiped from saxess -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- 10 = shiped from saxess as customer specific object -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag',@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to Copy a Tab - inside an object or to a different. The copied tab is always puted at the end.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Name of the user this action is requested for.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceFactoryID'; SET @value = N'FactoryID, skip / NULL / empty string if POST is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceProductLineID'; SET @value = N'SourceProductLineID, skip / NULL / empty string if POST is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceProductID'; SET @value = N'SourceProductD, skip / NULL / empty string if POST is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceTabID'; SET @value = N'SourceBusiness Identifier for the Tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetFactoryID'; SET @value = N'FactoryID, skip / NULL / empty string if POST is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetProductLineID'; SET @value = N'TargetProductLineID, skip / NULL / empty string if POST is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetProductID'; SET @value = N'TargetProductD, skip / NULL / empty string if POST is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetTabID'; SET @value = N'TargetBusiness Identifier for the Tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SourceStartPage'; SET @value = N'Determines if the source tab is on the start page.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TargetStartPage'; SET @value = N'Determines if the target tab is on the start page.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spDELETE_Tab; GO /* Procedure to DELETE a Tab Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spDELETE_Tab @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @ProductID = N'' , @TabID = N'TAB1' , @StartPage = 0; PRINT @RC SELECT * FROM planning.tTabs; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spDELETE_Tab', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spDELETE_Tab', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spDELETE_Tab @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = '' , @ProductLineID NVARCHAR(255) = '' , @ProductID NVARCHAR(255) = '' , @TabID NVARCHAR(255) , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 6, @Username, @FactoryID, @ProductLineID, @ProductID, @TabID, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @FactoryKey INT = 0; DECLARE @ProductLineKey INT = 0; DECLARE @ProductKey INT = 0; DECLARE @RowKey BIGINT = 0; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @ProductID = COALESCE(system.fProtectID(@ProductID), N''); SET @TabID = COALESCE(system.fProtectID(@TabID), N''); SET @StartPage = COALESCE(@StartPage, 0); BEGIN TRANSACTION spDELETE_Tab; IF @TabID = '0' EXEC system.spSEND_Message 'ERROR', 'TabID 0 can''t be deleted.'; IF @FactoryID = '' SET @FactoryKey = -1; IF @ProductLineID = '' SET @ProductLineKey = -1; IF @ProductID = '' SET @ProductKey = -1; SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID AND @FactoryKey <> -1; SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID AND @ProductLineKey <> -1; SELECT @ProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @ProductLineKey AND ProductID = @ProductID AND @ProductKey <> -1; IF @FactoryKey = 0 EXEC system.spSEND_Message 'WARNING', 'Factory doesn''t exist.'; IF @ProductLineKey = 0 EXEC system.spSEND_Message 'WARNING', 'ProductLine doesn''t exist.'; IF @ProductKey = 0 EXEC system.spSEND_Message 'WARNING', 'Product doesn''t exist.'; -- Check if TabID exists IF NOT EXISTS ( SELECT 1 FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @TabID AND StartPage = @StartPage ) BEGIN EXEC system.spSEND_Message 'WARNING', 'Tab doesn''t exist.'; END -- RowKey ermitteln SELECT @RowKey = RowKey FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @TabID AND StartPage = @StartPage; -- Check user rights IF @StartPage = 0 BEGIN -- Cluster IF @FactoryKey = -1 BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Cluster write.'; END -- Factory IF @FactoryKey <> -1 AND @ProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Factory write.'; END -- ProductLine IF @FactoryKey <> -1 AND @ProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for ProductLine write.'; END END ELSE BEGIN IF ( SELECT IsAdministratorFlag FROM system.trUser WHERE Username = @TransactUsername ) = 0 BEGIN EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for StartPage write (Administrators only).'; END END -- Delete TabLayouts DELETE FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage; -- Delete Tab DELETE FROM planning.tTabs WHERE RowKey = @RowKey; -- Eliminate all Gaps UPDATE planning.tTabs SET Orderindex = Rownumbers.Number FROM planning.tTabs AS tT INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY Orderindex) AS Number , TabID FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND StartPage = @StartPage ) AS Rownumbers ON tT.TabID = Rownumbers.TabID AND tT.FactoryKey = @FactoryKey AND tT.ProductLineKey = @ProductLineKey AND tT.ProductKey = @ProductKey AND tT.StartPage = @StartPage; COMMIT TRANSACTION spDELETE_Tab; SET @ResultCode = 200 END TRY BEGIN CATCH ROLLBACK TRANSACTION spDELETE_Tab; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spDELETE_Tab' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = not shiped from saxess -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- 10 = shiped from saxess as customer specific object -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag',@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to delete a Tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Name of the user this action is requested for.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if DELETE is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if DELETE is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductID'; SET @value = N'optional ProductD, skip / NULL / empty string if DELETE is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'TabID which is deleted.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@StartPage'; SET @value = N'Determines if the tab is on the start page.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spDELETE_TabLayout; GO /* Procedure to DELETE a layout for a tab Saxess Software GmbH Testcall DECLARE @RC INT; EXEC @RC = planning.spDELETE_TabLayout @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @TabID = N'TAB1' , @LayoutID = N'1' , @StartPage = 0; SELECT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spDELETE_TabLayout', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spDELETE_TabLayout', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spDELETE_TabLayout @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @ProductLineID NVARCHAR(255) = N'' , @TabID NVARCHAR(255) , @LayoutID NVARCHAR(255) , @StartPage BIT = 0 AS BEGIN BEGIN TRY BEGIN TRANSACTION planning_spDELETE_TabLayout; -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 6, @Username, @FactoryID, @ProductLineID, @TabID, @LayoutID, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Parameter protection SET @Username = COALESCE(@Username, N''); SET @FactoryID = system.fProtectID(COALESCE(@FactoryID, N'')); SET @ProductLineID = system.fProtectID(COALESCE(@ProductLineID, N'')); SET @TabID = system.fProtectID(COALESCE(@TabID, N'')); SET @LayoutID = system.fProtectID(COALESCE(@LayoutID, N'')); SET @StartPage = COALESCE(@StartPage, 0); -- Variables DECLARE @SettingUserEditPublicLayouts BIT; DECLARE @IsPublicLayout BIT; DECLARE @IsUserOwnedLayout BIT; DECLARE @IsUserAdministrator BIT; -- Get setting: regular users can edit public layouts? SELECT @SettingUserEditPublicLayouts = COALESCE(ValueInt, 0) FROM system.fGET_Setting('TabPreferencesUserEditPublicLayouts'); -- Public layout? SELECT @IsPublicLayout = IIF(LayoutOwner = '', 1, 0), @IsUserOwnedLayout = IIF(LayoutOwner = @Username, 1, 0) FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND LayoutID = @LayoutID AND StartPage = @StartPage; -- Layout exists? IF @IsPublicLayout IS NULL EXEC system.spSEND_Message N'ERROR', N'Layout doesn''t exist.'; -- Is user administrator? SELECT @IsUserAdministrator = IsAdministratorFlag FROM system.trUser WHERE UserName = @Username; -- Right rules: -- Administrators are allowed to delete all layouts -- only Administrators can delete layouts on the start page -- Regular users can delete their own personal layouts -- Regular users can not delete other personal layouts -- Regular users can delete public layouts if the setting "UserEditPublicLayouts" = 1 but they need write rights on the location of the tab -- only Administrators can edit layouts on the start page IF @IsUserAdministrator = 0 AND @StartPage = 1 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to delete this layout.'; -- Check if regular user is allowed to delete public layout or trying to delete layout from other user IF @IsUserAdministrator = 0 AND ((@SettingUserEditPublicLayouts = 0 AND @IsPublicLayout = 1) OR (@IsUserOwnedLayout = 0 AND @IsPublicLayout = 0)) EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to delete this layout.'; -- Regular users can edit public layouts but need to have write rights IF @IsUserAdministrator = 0 AND @SettingUserEditPublicLayouts = 1 AND @IsPublicLayout = 1 BEGIN -- Cluster level IF @FactoryID = '' BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to delete this layout.'; END ELSE BEGIN -- Factory level IF @ProductLineID = '' BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to delete this layout.'; END ELSE BEGIN -- ProductLine level EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to delete this layout.'; END END END -- Delete layout DELETE FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND LayoutID = @LayoutID AND StartPage = @StartPage; SET @AffectedRows = @@ROWCOUNT; -- Rearrange Orderindex WITH Layouts AS ( SELECT * , ROW_NUMBER() OVER (PARTITION BY LayoutOwner ORDER BY OrderIndex) AS NewOrderIndex FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage ) UPDATE Layouts SET OrderIndex = NewOrderIndex; COMMIT TRANSACTION planning_spDELETE_TabLayout; SET @ResultCode = 200 END TRY BEGIN CATCH ROLLBACK TRANSACTION planning_spDELETE_TabLayout; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spDELETE_TabLayout' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure for POST Bulkload'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if request is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if request is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'TabID which is requested'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spEXPORT_Tab; GO /* Procedure to EXPORT a tab Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spEXPORT_Tab @Username = N'SQL' , @FactoryID = N'ZT' , @ProductLineID = N'' , @ProductID = N'' , @TabID = N'TAB1' , @StartPage = 0; PRINT @RC Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_Tab', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spEXPORT_Tab', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spEXPORT_Tab @Username NVARCHAR(255) , @FactoryID NVARCHAR(50) , @ProductLineID NVARCHAR(50) , @ProductID NVARCHAR(50) , @TabID NVARCHAR(50) , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 6, @Username, @FactoryID, @ProductLineID, @ProductID, @TabID, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @SourceClusterName NVARCHAR(255) = N''; DECLARE @SourceClusterAPI NVARCHAR(255) = N''; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @ProductID = COALESCE(system.fProtectID(@ProductID), N''); SET @TabID = COALESCE(system.fProtectID(@TabID), N''); SET @StartPage = COALESCE(@StartPage, 0); -- Create temp table DROP TABLE IF EXISTS #tExport; CREATE TABLE #tExport ( RowKey BIGINT IDENTITY (1,1) NOT NULL , MainOrderNumber INT NOT NULL , SubOrderNumber INT NOT NULL , Command NVARCHAR(MAX) COLLATE DATABASE_DEFAULT NOT NULL , PRIMARY KEY CLUSTERED (RowKey) ); -- Determine Metadata SELECT @SourceClusterName = ValueText FROM system.fGET_Setting('Clustername'); SET @SourceClusterName = CONCAT(DB_Name(), ' ', @SourceClusterName); SELECT @SourceClusterAPI = ValueText FROM system.fGET_Setting('DBVersion'); -- Metadata header INSERT INTO #tExport VALUES (0, 1, N'-- {') , (0, 2, N'-- "Type": "Tab",') , (0, 3, CONCAT(N'-- "SourceClusterName": "', @SourceClusterName, '",')) , (0, 4, CONCAT(N'-- "SourceClusterAPI": "', @SourceClusterAPI, '",')) , (0, 5, CONCAT(N'-- "SourceFactoryID": "', @FactoryID, '",')) , (0, 6, CONCAT(N'-- "SourceProductLineID": "', @ProductLineID, '",')) , (0, 7, CONCAT(N'-- "SourceProductID": "', @ProductID, '",')) , (0, 8, CONCAT(N'-- "SourceTabID": "', @TabID, '"')) , (0, 9, N'-- }'); INSERT INTO #tExport VALUES (10, 1, N'-- CONFIG: Adjust variable values manually to fit your needs !') , (10, 2, N'DECLARE @Username NVARCHAR(255) = ''SQL''') , (10, 3, CONCAT(N'DECLARE @FactoryID NVARCHAR(255) = ''', @FactoryID, N'''')) , (10, 4, CONCAT(N'DECLARE @ProductLineID NVARCHAR(255) = ''', @ProductLineID, N'''')) , (10, 5, CONCAT(N'DECLARE @ProductID NVARCHAR(255) = ''', @ProductID, N'''')) , (10, 6, CONCAT(N'DECLARE @TabID NVARCHAR(255) = ''', @TabID, N'''')) , (10, 7, CONCAT(N'DECLARE @StartPage BIT = ', @StartPage)) , (10, 8, N'') , (10, 9, N'-- This Tab will be deleted during import, if it exists. You should be sure !'); -- Delete existing tab INSERT INTO #tExport SELECT 900 AS MainOrderNumber , 1000 AS SubOrderNumber , CONCAT( N'EXEC planning.spDELETE_Tab ' , N'@Username = ''SQL''' , N', @FactoryID = @FactoryID' , N', @ProductLineID = @ProductLineID' , N', @ProductID = @ProductID' , N', @TabID = @TabID' , N', @StartPage = @StartPage' , N';' ) AS Command FROM planning.tTabs WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND ProductID = @ProductID AND TabID = @TabID AND StartPage = @StartPage; -- Create the Tab as new Tab INSERT INTO #tExport SELECT 1000 AS MainOrderNumber , 1000 AS SubOrderNumber , CONCAT( N'EXEC planning.spPOST_Tab ' , N'@Username = ''SQL''' , N', @FactoryID = @FactoryID' , N', @ProductLineID = @ProductLineID' , N', @ProductID = @ProductID' , N', @TabID = @TabID' , N', @OrderIndex = ', Orderindex , N', @TabName = ''', system.fMaskSQL(TabName), '''' , N', @TabHint = ''', system.fMaskSQL(TabHint), '''' , N', @TabText = ''', system.fMaskSQL(TabText), '''' , N', @PresentationCODE = ''', PresentationCODE, '''' , N', @Datasource = ''', Datasource, '''' , N', @IsVisibleBOOL = ', IsVisibleBOOL , N', @LayoutJSON = ''''' -- LayoutJSON compatibility , N', @ParameterJSON = ''', system.fMaskSQL(ParameterJSON), '''' , N', @SQLCommand = ''', system.fMaskSQL(SQLCommand), '''' , N', @StartPage = @StartPage' , N';' ) AS Command FROM planning.tTabs WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND ProductID = @ProductID AND TabID = @TabID AND StartPage = @StartPage; -- Create tab layouts INSERT INTO #tExport SELECT 1100 AS MainOrderNumber , 1000 AS SubOrderNumber , CONCAT( N'EXEC planning.spPOST_TabLayout ' , N'@UserName = ''SQL''' , N', @FactoryID = @FactoryID' , N', @ProductLineID = @ProductLineID' , N', @TabID = @TabID' , N', @LayoutID = ''', LayoutID, '''' , N', @LayoutName = ''', system.fMaskSQL(LayoutName), '''' , N', @LayoutJSON = ''', system.fMaskSQL(LayoutJSON), '''' , N', @OrderIndex = ', OrderIndex , N', @LayoutOwner = ''', LayoutOwner, '''' , N', @StartPage = @StartPage' , N';' ) AS Command FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage; -- Footer INSERT INTO #tExport VALUES (9999, 1, N'GO'); -- Output SELECT Command FROM #tExport ORDER BY MainOrderNumber , SubOrderNumber; SET @AffectedRows = @@ROWCOUNT; SET @ResultCode = 200 END TRY BEGIN CATCH SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spEXPORT_Tab' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to create an SQL Script, which imports a Tab in OCT.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- optional SET parameter documentation (only for Core / Standardmodules) SET @level2name = N'@TabID'; SET @value = N'ID of the Tab to be exported.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spGET_TabLayouts; GO /* Procedure to GET a layout of a tab Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spGET_TabLayouts @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @TabID = N'TAB1' , @StartPage = 0; SELECT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spGET_TabLayouts', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spGET_TabLayouts', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spGET_TabLayouts @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @ProductLineID NVARCHAR(255) = N'' , @TabID NVARCHAR(255) , @ReturnAllLayouts BIT = 0 , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 6, @Username, @FactoryID, @ProductLineID, @TabID, @ReturnAllLayouts, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Parameter protection SET @Username = COALESCE(@Username, N''); SET @FactoryID = system.fProtectID(COALESCE(@FactoryID, N'')); SET @ProductLineID = system.fProtectID(COALESCE(@ProductLineID, N'')); SET @TabID = system.fProtectID(COALESCE(@TabID, N'')); SET @ReturnAllLayouts = COALESCE(@ReturnAllLayouts, 0); SET @StartPage = COALESCE(@StartPage, 0); -- Output SELECT LayoutID , LayoutName , LayoutJSON , OrderIndex , IIF(LayoutOwner = N'', 1, 0) AS IsPublicLayout , LayoutOwner FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage AND ( COALESCE(NULLIF(LayoutOwner, ''), @Username) = @Username OR @ReturnAllLayouts = 1 ) ORDER BY IsPublicLayout , OrderIndex; SET @AffectedRows = @@ROWCOUNT; SET @ResultCode = 200 END TRY BEGIN CATCH SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spGET_TabLayouts' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure for POST Bulkload'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if request is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if request is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'TabID which is requested'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spGET_Tabs; GO /* Procedure to GET Tabs for - the start page - the cluster - the factory - the productline - the product Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spGET_Tabs @Username = N'SQL' , @FactoryID = N'ZT' , @ProductLineID = N'U' , @ProductID = N'' , @StartPage = 0; PRINT @RC Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spGET_Tabs', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spGET_Tabs', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spGET_Tabs @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @ProductLineID NVARCHAR(255) = N'' , @ProductID NVARCHAR(255) = N'' , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 5, @Username, @FactoryID, @ProductLineID, @ProductID, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @FactoryKey INT = 0; DECLARE @ProductLineKey INT = 0; DECLARE @ProductKey INT = 0; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @ProductID = COALESCE(system.fProtectID(@ProductID), N''); SET @StartPage = COALESCE(@StartPage, 0); IF @FactoryID = '' SET @FactoryKey = -1; IF @ProductLineID = '' SET @ProductLineKey = -1; IF @ProductID = '' SET @ProductKey = -1; SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID AND @FactoryKey <> -1; SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID AND @ProductLineKey <> -1; SELECT @ProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @ProductLineKey AND ProductID = @ProductID AND @ProductKey <> -1; IF @FactoryKey = 0 EXEC system.spSEND_Message N'ERROR', N'Factory doesn''t exist.'; IF @ProductLineKey = 0 EXEC system.spSEND_Message N'ERROR', N'ProductLine doesn''t exist.'; IF @ProductKey = 0 EXEC system.spSEND_Message N'ERROR', N'Product doesn''t exist.'; IF @StartPage = 0 BEGIN -- Check user rights: Cluster IF @FactoryKey = -1 BEGIN EXEC @ResultCode = planning.spGET_ClusterPropertiesReadRight @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights for Cluster read.'; END -- Check user rights: Factory IF @FactoryKey <> -1 AND @ProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryReadRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights for Factory read.'; END -- Check user rights: ProductLine IF @FactoryKey <> -1 AND @ProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineReadRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights for ProductLine read.'; END END -- Output SELECT FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND StartPage = @StartPage ORDER BY Orderindex; SET @AffectedRows = @@ROWCOUNT; SET @ResultCode = 200 END TRY BEGIN CATCH SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spGET_Tabs' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = not shiped from saxess -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- 10 = shiped from saxess as customer specific object -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag',@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to get the Tabs for given planning Tree object. This may be the root level (Cluster), a Factory, a ProductLine or a Product.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Name of the user this action is requested for.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if request is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if request is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductID'; SET @value = N'optional ProductD, skip / NULL / empty string if request is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@StartPage'; SET @value = N'Determines if tabs from start page should be loaded'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spMOVE_Tab; GO /* Procedure to move a Tab to - another ID - another OrderIndex Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spMOVE_Tab @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @ProductID = N'' , @TabID = N'0' , @NewTabID = N'TAB1' , @NewOrderIndex = 99 , @StartPage = 0; PRINT @RC SELECT * FROM planning.tTabs; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spMOVE_Tab', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spMOVE_Tab', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spMOVE_Tab @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = '' , @ProductLineID NVARCHAR(255) = '' , @ProductID NVARCHAR(255) = '' , @TabID NVARCHAR(255) , @NewTabID NVARCHAR(255) , @NewOrderIndex INT , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 8, @Username, @FactoryID, @ProductLineID, @ProductID, @TabID, @NewTabID, @NewOrderIndex, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @FactoryKey INT = 0; DECLARE @ProductLineKey INT = 0; DECLARE @ProductKey INT = 0; DECLARE @RowKey BIGINT = 0; DECLARE @OldOrderIndex INT = 0; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @ProductID = COALESCE(system.fProtectID(@ProductID), N''); SET @TabID = COALESCE(system.fProtectID(@TabID), N''); SET @NewTabID = COALESCE(system.fProtectID(@NewTabID), N''); SET @NewOrderIndex = COALESCE(@NewOrderIndex, 0); SET @StartPage = COALESCE(@StartPage, 0); IF @NewOrderIndex <= 0 SET @NewOrderIndex = 1; BEGIN TRANSACTION spMOVE_Tab; -- Determine Keys IF @FactoryID = '' SET @FactoryKey = -1; IF @ProductLineID = '' SET @ProductLineKey = -1; IF @ProductID = '' SET @ProductKey = -1; SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID AND @FactoryKey <> -1; SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID AND @ProductLineKey <> -1; SELECT @ProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @ProductLineKey AND ProductID = @ProductID AND @ProductKey <> -1; -- Check if IDs exist IF @FactoryKey = 0 EXEC system.spSEND_Message 'ERROR', 'Factory doesn''t exists.'; IF @ProductLineKey = 0 EXEC system.spSEND_Message 'ERROR', 'ProductLine doesn''t exists.'; IF @ProductKey = 0 EXEC system.spSEND_Message 'ERROR', 'Product doesn''t exists.'; -- Check if TabID exists IF NOT EXISTS ( SELECT 1 FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @TabID AND StartPage = @StartPage ) BEGIN EXEC system.spSEND_Message 'ERROR', 'TabID to move doesn''t exist.'; END; -- TabID 0 can't be moved IF @TabID = '0' OR @NewTabID = '0' BEGIN EXEC system.spSEND_Message 'ERROR', 'Tab with ID 0 can''t be moved'; END -- Check user rights IF @StartPage = 0 BEGIN -- Cluster IF @FactoryKey = -1 BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Cluster write.'; END -- Factory IF @FactoryKey <> -1 AND @ProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Factory write.'; END -- ProductLine IF @FactoryKey <> -1 AND @ProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for ProductLine write.'; END END ELSE BEGIN IF ( SELECT IsAdministratorFlag FROM system.trUser WHERE Username = @TransactUsername ) = 0 BEGIN EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for StartPage write (Administrators only).'; END END -- check if new TabID is free IF EXISTS ( SELECT 1 FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @NewTabID AND TabID <> @TabID AND StartPage = @StartPage ) BEGIN EXEC system.spSEND_Message 'ERROR', 'New TabID is already in use.'; END -- Determine current Key and OrderIndex SELECT @Rowkey = RowKey , @OldOrderIndex = Orderindex FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @TabID AND StartPage = @StartPage; -- Update tab layouts UPDATE planning.tTabLayouts SET TabID = @NewTabID WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage; -- Insert new Tab UPDATE planning.tTabs SET TabID = @NewTabID , Orderindex = @NewOrderIndex WHERE RowKey = @RowKey; -- Update other numbers if Number is changed IF @OldOrderIndex <> @NewOrderIndex BEGIN -- case if OrderIndex is bigger now and existed before - decrement all in move window IF @OldOrderIndex < @NewOrderIndex BEGIN UPDATE planning.tTabs SET Orderindex = Orderindex - 1 WHERE Orderindex >= @OldOrderIndex AND Orderindex <= @NewOrderIndex AND FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID <> @NewTabID AND StartPage = @StartPage; END -- case if OrderIndex is smaller now and existed before - increment all in move window IF @OldOrderIndex > @NewOrderIndex BEGIN UPDATE planning.tTabs SET Orderindex = Orderindex + 1 WHERE Orderindex <= @OldOrderIndex AND Orderindex >= @NewOrderIndex AND FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID <> @NewTabID AND StartPage = @StartPage; END -- eliminate all Gaps UPDATE planning.tTabs SET Orderindex = Rownumbers.Number FROM planning.tTabs AS tT INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY Orderindex) AS Number , TabID FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND StartPage = @StartPage ) AS Rownumbers ON tT.TabID = Rownumbers.TabID AND tT.FactoryKey = @FactoryKey AND tT.ProductLineKey = @ProductLineKey AND tT.ProductKey = @ProductKey AND tT.StartPage = @StartPage; END COMMIT TRANSACTION spMOVE_Tab; SET @ResultCode = 200 END TRY BEGIN CATCH ROLLBACK TRANSACTION spMOVE_Tab; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spMOVE_Tab' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = not shiped from saxess -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- 10 = shiped from saxess as customer specific object -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag',@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to Move a Tab to a different ID and different OrderIndex. The requested TabID must be free. The requested Orderposition may be in use, reordering is done automaticly. To put a tab to the end, any high order number (like 100) can be submitted. The Tab with ID 0 can''t be moved.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Name of the user this action is requested for.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if MOVE is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if MOVE is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductID'; SET @value = N'optional ProductD, skip / NULL / empty string if MOVE is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'TabID which is moved. ID 0 is not accepted, its reserved for the system tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@NewTabID'; SET @value = N'TabID the tab will get. This must not be already in use.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@NewOrderIndex'; SET @value = N'Position in the list of Tabs. Any Number > 0 can be passed in, tabs reorder themself.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@StartPage'; SET @value = N'Determines if the tab is on the start page.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spPOST_TabLayout; GO /* Procedure to POST a layout for a tab Saxess Software GmbH Testcall Procedure DECLARE @RC INT; DECLARE @OutputID NVARCHAR(255); EXEC @RC = planning.spPOST_TabLayout @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @TabID = N'TAB1' , @LayoutID = N'*' , @LayoutName = N'Test Layout' , @LayoutJSON = N'{}' , @OrderIndex = 1 , @LayoutOwner = N'' , @OutputID = @OutputID OUTPUT , @StartPage = 0; SELECT @RC; SELECT @OutputID; SELECT * FROM planning.tTabLayouts ORDER BY RowKey DESC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_TabLayout', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_TabLayout', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spPOST_TabLayout @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = N'' , @ProductLineID NVARCHAR(255) = N'' , @TabID NVARCHAR(255) , @LayoutID NVARCHAR(255) , @LayoutName NVARCHAR(255) , @LayoutJSON NVARCHAR(MAX) , @OrderIndex INT , @LayoutOwner NVARCHAR(255) , @OutputID NVARCHAR(255) = NULL OUTPUT , @StartPage BIT = 0 AS BEGIN BEGIN TRY BEGIN TRANSACTION planning_spPOST_TabLayout; -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 10, @Username, @FactoryID, @ProductLineID, @TabID, @LayoutID, @LayoutName, @LayoutJSON, @OrderIndex, @LayoutOwner, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Parameter protection SET @Username = COALESCE(@Username, N''); SET @FactoryID = system.fProtectID(COALESCE(@FactoryID, N'')); SET @ProductLineID = system.fProtectID(COALESCE(@ProductLineID, N'')); SET @TabID = system.fProtectID(COALESCE(@TabID, N'')); SET @LayoutID = system.fProtectID(COALESCE(@LayoutID, N'')); SET @LayoutName = COALESCE(@LayoutName, N''); SET @LayoutJSON = COALESCE(@LayoutJSON, N''); SET @OrderIndex = COALESCE(@OrderIndex, 999); SET @LayoutOwner = COALESCE(@LayoutOwner, N''); SET @StartPage = COALESCE(@StartPage, 0); -- Variables DECLARE @SettingUserEditPublicLayouts BIT; DECLARE @SettingPrivateLayouts BIT; DECLARE @SettingMultipleLayouts BIT; DECLARE @IsUserAdministrator BIT; DECLARE @IsPublicLayout BIT = CASE WHEN @LayoutOwner = N'' THEN 1 ELSE 0 END; DECLARE @IsSingleLayout BIT; -- Get setting: regular users can edit public layouts? SELECT @SettingUserEditPublicLayouts = COALESCE(ValueInt, 0) FROM system.fGET_Setting('TabPreferencesUserEditPublicLayouts'); -- Get setting: are private layouts allowed in general? SELECT @SettingPrivateLayouts = COALESCE(ValueInt, 1) FROM system.fGET_Setting('TabPreferencesPrivateLayouts'); -- Get setting: are multiple layouts allowed in general? SELECT @SettingMultipleLayouts = COALESCE(ValueInt, 1) FROM system.fGET_Setting('TabPreferencesMultipleLayouts'); -- Is user administrator? SELECT @IsUserAdministrator = IsAdministratorFlag FROM system.trUser WHERE UserName = @Username; -- Does the tab type support multiple layouts? SELECT @IsSingleLayout = CASE WHEN PresentationCODE IN ('Flowchart', 'Editor', 'ExternalWebsite', 'HTMLFromSQLQuery') THEN 1 ELSE 0 END FROM planning.tTabs WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND StartPage = @StartPage AND TabID = @TabID; -- Right rules: -- Administrators are allowed to create and edit all layouts -- only Administrators can edit layouts on the start page -- Regular users can only create/edit private layouts -- Regular users can create/edit public layouts if the setting "UserEditPublicLayouts" = 1 but they need write rights on the location of the tab -- only Administrators can edit layouts on the start page IF @IsUserAdministrator = 0 AND @StartPage = 1 AND @IsPublicLayout = 1 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to save this layout.'; -- Regular users can only create/edit private layouts IF @IsUserAdministrator = 0 AND @SettingUserEditPublicLayouts = 0 AND @IsPublicLayout = 1 AND @IsSingleLayout = 0 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to save this layout.'; -- Are private layouts allowed? IF @IsUserAdministrator = 0 AND @IsPublicLayout = 0 AND @SettingPrivateLayouts = 0 EXEC system.spSEND_Message N'ERROR', N'Private layouts are not allowed.'; -- Regular users can create/edit public layouts but need to have write rights IF @IsUserAdministrator = 0 AND @SettingUserEditPublicLayouts = 1 AND @IsPublicLayout = 1 BEGIN -- Cluster level IF @FactoryID = '' BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to save this layout.'; END ELSE BEGIN -- Factory level IF @ProductLineID = '' BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to save this layout.'; END ELSE BEGIN -- ProductLine level EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message N'ERROR', N'Insufficient rights to save this layout.'; END END END -- New layout? IF @LayoutID = '*' OR NOT EXISTS( SELECT 1 FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND LayoutID = @LayoutID AND StartPage = @StartPage ) BEGIN IF NOT EXISTS( SELECT 1 FROM planning.tTabs WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage ) EXEC system.spSEND_Message N'ERROR', N'Tab doesn''t exist.'; -- Get next free LayoutID IF @LayoutID = '*' BEGIN SELECT @LayoutID = COALESCE(MAX(CAST(LayoutID AS INT)), 0) + 1 FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage; END -- Are multiple layouts allowed? IF @IsUserAdministrator = 0 AND @LayoutID > 1 AND @SettingMultipleLayouts = 0 BEGIN EXEC system.spSEND_Message N'ERROR', N'Can''t create another layout because multiple layouts are not allowed.'; END -- Insert new layout INSERT INTO planning.tTabLayouts ( FactoryID , ProductLineID , TabID , LayoutID , LayoutName , LayoutJSON , OrderIndex , LayoutOwner , StartPage ) VALUES ( @FactoryID , @ProductLineID , @TabID , @LayoutID , @LayoutName , @LayoutJSON , @OrderIndex , @LayoutOwner , @StartPage ); END ELSE BEGIN -- Update existing layout UPDATE planning.tTabLayouts SET LayoutName = @LayoutName , LayoutJSON = @LayoutJSON , OrderIndex = @OrderIndex , LayoutOwner = @LayoutOwner WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND LayoutID = @LayoutID AND StartPage = @StartPage; END SET @AffectedRows = @@ROWCOUNT; SET @OutputID = @LayoutID; -- Rearrange OrderIndex WITH Layouts AS ( SELECT * , ROW_NUMBER() OVER (PARTITION BY LayoutOwner ORDER BY OrderIndex, CASE WHEN LayoutID = @LayoutID THEN 0 ELSE 1 END) AS NewOrderIndex FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage ) UPDATE Layouts SET OrderIndex = NewOrderIndex; COMMIT TRANSACTION planning_spPOST_TabLayout; SET @ResultCode = 200 END TRY BEGIN CATCH ROLLBACK TRANSACTION planning_spPOST_TabLayout; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spPOST_TabLayout' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure for POST Bulkload'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if request is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if request is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'TabID which is requested'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@LayoutID'; SET @value = N'ID of the layout which is updated. If LayoutID is * then a new layout is created.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@LayoutName'; SET @value = N'The name of the layout.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@LayoutJSON'; SET @value = N'The JSON definition of the layout.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@OrderIndex'; SET @value = N'Index to help with ordering the layouts. Needs to have unique values for all combinations of FactoryID, ProductLineID, TabID & LayoutOwner.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@LayoutOwner'; SET @value = N'Username if it is a private layout. Empty if it is a public layout.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS planning.spPOST_Tab; GO /* Procedure to POST a Tab for - a start page - a cluster - a factory - a productline - a product Saxess Software GmbH Testcall Procedure DECLARE @RC INT; EXEC @RC = planning.spPOST_Tab @Username = N'SQL' , @FactoryID = N'' , @ProductLineID = N'' , @ProductID = N'' , @TabID = N'TAB1' , @OrderIndex = 99 , @TabName = N'TabName' , @TabHint = N'' , @TabText = N'Text' , @PresentationCODE = N'Pivot' , @Datasource = N'' , @IsVisibleBOOL = 1 , @LayoutJSON = N'' , @ParameterJSON = N'' , @SQLCommand = N'' , @StartPage = 0; PRINT @RC SELECT * FROM planning.tTabs; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_Tab', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'planning', 'PROCEDURE', 'spPOST_Tab', 'PARAMETER', NULL) */ CREATE PROCEDURE planning.spPOST_Tab @Username NVARCHAR(255) , @FactoryID NVARCHAR(255) = '' , @ProductLineID NVARCHAR(255) = '' , @ProductID NVARCHAR(255) = '' , @TabID NVARCHAR(255) , @OrderIndex INT , @TabName NVARCHAR(255) , @TabHint NVARCHAR(2000) , @TabText NVARCHAR(2000) , @PresentationCODE NVARCHAR(255) , @Datasource NVARCHAR(2000) , @IsVisibleBOOL INT , @LayoutJSON NVARCHAR(MAX) = NULL , @ParameterJSON NVARCHAR(MAX) , @SQLCommand NVARCHAR(MAX) = NULL , @StartPage BIT = 0 AS BEGIN BEGIN TRY -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 16, @Username, @FactoryID, @ProductLineID, @ProductID, @TabID, @OrderIndex, @TabName, @TabHint, @TabText, @PresentationCODE, @Datasource, @IsVisibleBOOL, @LayoutJSON, @ParameterJSON, @SQLCommand, @StartPage; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @FactoryKey INT = 0; DECLARE @ProductLineKey INT = 0; DECLARE @ProductKey INT = 0; DECLARE @RowKey BIGINT = 0; DECLARE @OldOrderIndex INT = 0; -- Input parameter handling SET @Username = COALESCE(@Username, N''); SET @FactoryID = COALESCE(system.fProtectID(@FactoryID), N''); SET @ProductLineID = COALESCE(system.fProtectID(@ProductLineID), N''); SET @ProductID = COALESCE(system.fProtectID(@ProductID), N''); SET @TabID = COALESCE(system.fProtectID(@TabID), N''); SET @OrderIndex = COALESCE(@OrderIndex, 0); SET @TabName = COALESCE(@TabName, N''); SET @TabHint = COALESCE(@TabHint, N''); SET @TabText = COALESCE(@TabText, N''); SET @PresentationCODE = COALESCE(@PresentationCODE, N''); SET @Datasource = COALESCE(@Datasource, N''); SET @IsVisibleBOOL = COALESCE(@IsVisibleBOOL, 0); SET @LayoutJSON = COALESCE(@LayoutJSON, N''); SET @ParameterJSON = COALESCE(@ParameterJSON, N''); SET @SQLCommand = COALESCE(@SQLCommand, N''); SET @StartPage = COALESCE(@StartPage, 0); IF @OrderIndex < 0 SET @OrderIndex = 1; IF @IsVisibleBOOL <> 1 SET @IsVisibleBOOL = 0; -- Handle updated PresentationCODEs IF @PresentationCODE = 'HTML_URL' SET @PresentationCODE = 'ExternalWebsite' IF @PresentationCODE = 'HTML_Static' SET @PresentationCODE = 'HTMLFromSQLQuery' IF @PresentationCODE = 'HTML_Editor' SET @PresentationCODE = 'Editor' BEGIN TRANSACTION spPOST_Tab; -- Determine Keys IF @FactoryID = '' SET @FactoryKey = -1; IF @ProductLineID = '' SET @ProductLineKey = -1; IF @ProductID = '' SET @ProductKey = -1; SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID AND @FactoryKey <> -1; SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID AND @ProductLineKey <> -1; SELECT @ProductKey = ProductKey FROM planning.tdProducts WHERE ProductLineKey = @ProductLineKey AND ProductID = @ProductID AND @ProductKey <> -1; -- Check if IDs exist IF @FactoryKey = 0 EXEC system.spSEND_Message 'ERROR', 'Factory doesn''t exists.'; IF @ProductLineKey = 0 EXEC system.spSEND_Message 'ERROR', 'ProductLine doesn''t exists.'; IF @ProductKey = 0 EXEC system.spSEND_Message 'ERROR', 'Product doesn''t exists.'; -- Check user rights IF @StartPage = 0 BEGIN -- Cluster IF @FactoryKey = -1 BEGIN EXEC @ResultCode = system.spGET_ClusterWriteRightTransactionUser @TransactUsername; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Cluster write.'; END -- Factory IF @FactoryKey <> -1 AND @ProductLineKey = -1 BEGIN EXEC @ResultCode = planning.spGET_FactoryWriteRight @TransactUsername, @FactoryID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for Factory write.'; END -- ProductLine IF @FactoryKey <> -1 AND @ProductLineKey <> -1 BEGIN EXEC @ResultCode = planning.spGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID; IF @ResultCode <> 200 EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for ProductLine write.'; END END ELSE BEGIN IF ( SELECT IsAdministratorFlag FROM system.trUser WHERE Username = @TransactUsername ) = 0 BEGIN EXEC system.spSEND_Message 'ERROR', 'Insufficient rights for StartPage write (Administrators only).'; END END -- Tab already exists? SELECT @Rowkey = RowKey , @OldOrderIndex = COALESCE(Orderindex, CASE WHEN TabID = '0' THEN 0 END) FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID = @TabID AND StartPage = @StartPage; -- Delete if exists IF @RowKey > 0 BEGIN -- delete tab layouts if tab type was changed IF @PresentationCODE <> ( SELECT PresentationCODE FROM planning.tTabs WHERE RowKey = @RowKey ) BEGIN DELETE FROM planning.tTabLayouts WHERE FactoryID = @FactoryID AND ProductLineID = @ProductLineID AND TabID = @TabID AND StartPage = @StartPage; END DELETE FROM planning.tTabs WHERE RowKey = @RowKey; END -- System Tab with TabID 0 can only change visibility IF @TabID = '0' BEGIN INSERT INTO planning.tTabs ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage ) VALUES ( @FactoryKey , @ProductLineKey , @ProductKey , @FactoryID , @ProductLineID , @ProductID , @TabID , @OrderIndex , @TabName , N'' , N'' , N'System' , N'' , @IsVisibleBOOL , N'' , N'' , @StartPage ); END ELSE BEGIN INSERT INTO planning.tTabs ( FactoryKey , ProductLineKey , ProductKey , FactoryID , ProductLineID , ProductID , TabID , Orderindex , TabName , TabHint , TabText , PresentationCODE , Datasource , IsVisibleBOOL , ParameterJSON , SQLCommand , StartPage ) VALUES ( @FactoryKey , @ProductLineKey , @ProductKey , @FactoryID , @ProductLineID , @ProductID , @TabID , @OrderIndex , @TabName , @TabHint , @TabText , @PresentationCODE , @Datasource , @IsVisibleBOOL , @ParameterJSON , @SQLCommand , @StartPage ); END -- Update other numbers if Number is changed or new IF @OldOrderIndex <> @OrderIndex BEGIN -- case if OrderIndex is bigger now and existed before - decrement all in move window IF @OldOrderIndex < @OrderIndex AND @RowKey <> 0 BEGIN UPDATE planning.tTabs SET Orderindex = Orderindex - 1 WHERE Orderindex >= @OldOrderIndex AND Orderindex <= @OrderIndex AND FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID <> @TabID AND StartPage = @StartPage; END -- case if OrderIndex is smaller now and existed before - increment all in move window IF @OldOrderIndex > @OrderIndex AND @RowKey <> 0 BEGIN UPDATE planning.tTabs SET Orderindex = Orderindex + 1 WHERE Orderindex <= @OldOrderIndex AND Orderindex >= @OrderIndex AND FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID <> @TabID AND StartPage = @StartPage; END -- case new Tab - increment all following IF @RowKey = 0 BEGIN UPDATE planning.tTabs SET Orderindex = Orderindex + 1 WHERE Orderindex >= @OrderIndex AND FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND TabID <> @TabID AND StartPage = @StartPage; END -- eliminate all Gaps UPDATE planning.tTabs SET Orderindex = Rownumbers.Number FROM planning.tTabs AS tT INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY Orderindex) AS Number , TabID FROM planning.tTabs WHERE FactoryKey = @FactoryKey AND ProductLineKey = @ProductLineKey AND ProductKey = @ProductKey AND StartPage = @StartPage ) AS Rownumbers ON tT.TabID = Rownumbers.TabID AND tT.FactoryKey = @FactoryKey AND tT.ProductLineKey = @ProductLineKey AND tT.ProductKey = @ProductKey AND tT.StartPage = @StartPage; END -- Save TabLayout IF @LayoutJSON <> '' BEGIN EXEC planning.spPOST_TabLayout @Username = @Username, @FactoryID = @FactoryID, @ProductLineID = @ProductLineID, @TabID = @TabID, @LayoutID = '*', @LayoutName = 'Default', @LayoutJSON = @LayoutJSON, @OrderIndex = 1, @LayoutOwner = '', @StartPage = @StartPage; END COMMIT TRANSACTION spPOST_Tab; SET @ResultCode = 200 END TRY BEGIN CATCH ROLLBACK TRANSACTION spPOST_Tab; SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message N'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'planning' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spPOST_Tab' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom) ,@SX_Module NVARCHAR(255) = N'CORE' -- enter module name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = not shiped from saxess -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- 10 = shiped from saxess as customer specific object -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Module; EXEC sys.sp_addextendedproperty N'SX_Module',@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag',@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to POST a Tab. The Tab with ID 0 is the special system tab, but does not get special handling in databae.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Name of the user this action is requested for.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@FactoryID'; SET @value = N'optional FactoryID, skip / NULL / empty string if POST is for Cluster level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductLineID'; SET @value = N'optional ProductLineID, skip / NULL / empty string if POST is for Cluster or Factory level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ProductID'; SET @value = N'optional ProductD, skip / NULL / empty string if POST is for Cluster, Factory or ProductLine level'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabID'; SET @value = N'Business Identifier for the Tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@OrderIndex'; SET @value = N'Position in the list of Tabs. Any Number > 0 can be passed in, tabs reorder themself.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabName'; SET @value = N'Name of the Tab, used as Label.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabHint'; SET @value = N'Hint on the Tab, displayed as Tooltip.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@TabText'; SET @value = N'Text for the headerarea inside the tab.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@PresentationCODE'; SET @value = N'CODE word for the type of presentation, e.g PIVOT, DATAGRID, HTML_URL, HTML_STATIC.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Datasource'; SET @value = N'Datasource fitting to PresentationCODE - name of the stored procedure or URL.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@IsVisibleBOOL'; SET @value = N'1 for visible, 0 for not visible'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@LayoutJSON'; SET @value = N'The JSON definition of the layout.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ParameterJSON'; SET @value = N'Parameter definition (List and default value) as JSON String'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SQLCommand'; SET @value = N'A custom SQL command that needs to return a result set which can be displayed by pivot tables and data grids.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@StartPage'; SET @value = N'Determines if the tab is on the start page.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO DROP PROCEDURE IF EXISTS system.spPOST_Action; GO /* Procedure to POST Action information Saxess Software GmbH Testcall DECLARE @RC INT; DECLARE @ReturnedActionID NVARCHAR(50); EXEC @RC = system.spPOST_Action @Username = 'SQL' , @ActionID = '*' , @OrderIndex = NULL , @Active = 1 , @Name = 'ActionTest' , @Description = 'Short description.' , @RequiresClusterWriteRights = 0 , @RequiresWriteRights = 1 , @Condition = '' , @ListCustomTitle = 'Eine Action' , @ListSQL = 'SELECT * FROM global.tCodes' , @ListLayout = '' , @ListExcelExport = 1 , @SetCellValueAsFilter = 0 , @ReloadListAfterChangingFilter = 0 , @ActionSQL = '' , @ApplyFromField = '' , @SaveBeforeAction = 'NO' , @SaveAfterAction = 0 , @ReloadTreeAfterAction = 0 , @ReloadDetailsAfterAction = 0 , @ApplyToReadonlyCells = 1 , @OutputID = @ReturnedActionID OUTPUT; SELECT @ReturnedActionID; SELECT @RC; Testcall Documentation SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'system', 'PROCEDURE', 'spPOST_Action', NULL, NULL) UNION ALL SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'system', 'PROCEDURE', 'spPOST_Action', 'PARAMETER', NULL) */ CREATE PROCEDURE system.spPOST_Action @Username NVARCHAR(255) , @ActionID NVARCHAR(255) = NULL , @OrderIndex INT = NULL , @Active BIT = NULL , @Name NVARCHAR(255) = NULL , @Description NVARCHAR(4000) = NULL , @RequiresClusterWriteRights BIT = NULL , @RequiresWriteRights BIT = NULL , @Condition NVARCHAR(MAX) = NULL , @ListCustomTitle NVARCHAR(255) = NULL , @ListSQL NVARCHAR(MAX) = NULL , @ListLayout NVARCHAR(MAX) = NULL , @ListExcelExport BIT = NULL , @SetCellValueAsFilter BIT = NULL , @ReloadListAfterChangingFilter BIT = NULL , @ActionSQL NVARCHAR(MAX) = NULL , @ApplyFromField NVARCHAR(255) = NULL , @SaveBeforeAction NVARCHAR(20) = NULL , @SaveAfterAction BIT = NULL , @ReloadTreeAfterAction BIT = NULL , @ReloadDetailsAfterAction BIT = NULL , @ApplyToReadonlyCells BIT = NULL , @OutputID NVARCHAR(50) = NULL OUTPUT AS BEGIN BEGIN TRY -- Start transaction BEGIN TRANSACTION spPOST_Action -- Logging DECLARE @TimestampCall DATETIME = GETUTCDATE(); DECLARE @ProcedureName NVARCHAR(255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID); DECLARE @AffectedRows INT = 0; DECLARE @ResultCode INT = 501; DECLARE @Comment NVARCHAR(4000) = N''; DECLARE @ParameterString NVARCHAR(MAX) = N''; DECLARE @TransactUsername NVARCHAR(255) = N''; EXEC system.spGET_ParameterString @ParameterString OUTPUT, 22, @Username, @ActionID, @OrderIndex, @Active, @Name, @Description, @RequiresClusterWriteRights, @RequiresWriteRights, @Condition, @ListCustomTitle, @ListSQL, @ListLayout, @ListExcelExport, @SetCellValueAsFilter, @ReloadListAfterChangingFilter, @ActionSQL, @ApplyFromField, @SaveBeforeAction, @SaveAfterAction, @ReloadTreeAfterAction, @ReloadDetailsAfterAction, @ApplyToReadonlyCells; EXEC system.spGET_TransactUsername @TransactUsername OUTPUT, @Username; -- Variables DECLARE @ActionKey BIGINT = 0; DECLARE @OldOrderIndex INT = 0; -- Input parameter handling SET @ActionID = COALESCE(system.fProtectID(@ActionID), N''); SET @Name = COALESCE(system.fProtectString(@Name), N''); SET @Description = COALESCE(system.fProtectString(@Description), N''); IF COALESCE(@ActionID, N'') = N'' EXEC system.spSEND_Message 'ERROR', 'No ActionID provided'; IF COALESCE(@Name, N'') = N'' EXEC system.spSEND_Message 'ERROR', 'No name provided'; -- Determine existing Action SELECT @ActionKey = ActionKey , @OldOrderIndex = OrderIndex FROM system.tActions WHERE ActionID = @ActionID; IF @ActionKey <> 0 BEGIN -- Update existing data UPDATE system.tActions SET OrderIndex = @OrderIndex , Active = @Active , Name = @Name , Description = @Description , RequiresClusterWriteRights = @RequiresClusterWriteRights , RequiresWriteRights = @RequiresWriteRights , Condition = @Condition , ListCustomTitle = @ListCustomTitle , ListSQL = @ListSQL , ListLayout = @ListLayout , ListExcelExport = @ListExcelExport , SetCellValueAsFilter = @SetCellValueAsFilter , ReloadListAfterChangingFilter = @ReloadListAfterChangingFilter , ActionSQL = @ActionSQL , ApplyFromField = @ApplyFromField , SaveBeforeAction = @SaveBeforeAction , SaveAfterAction = @SaveAfterAction , ReloadTreeAfterAction = @ReloadTreeAfterAction , ReloadDetailsAfterAction = @ReloadDetailsAfterAction , ApplyToReadonlyCells = @ApplyToReadonlyCells WHERE ActionID = @ActionID; SET @AffectedRows = @@ROWCOUNT END ELSE BEGIN -- Insert new data -- Get next free ActionID IF @ActionID IN (N'', N'*') BEGIN SET @ActionID = ( SELECT TOP 1 TRY_CAST(RIGHT(ActionID, LEN(ActionID) - 1) AS INT) + 1 FROM system.tActions WHERE ActionID LIKE N'A%' AND LEN(ActionID) > 1 AND TRY_CAST(RIGHT(ActionID, LEN(ActionID) - 1) AS INT) IS NOT NULL ORDER BY TRY_CAST(RIGHT(ActionID, LEN(ActionID) - 1) AS INT) DESC ); SET @ActionID = COALESCE(N'A' + @ActionID, N'A1'); END INSERT INTO system.tActions ( ActionID , OrderIndex , Active , Name , Description , RequiresClusterWriteRights , RequiresWriteRights , Condition , ListCustomTitle , ListSQL , ListLayout , ListExcelExport , SetCellValueAsFilter , ReloadListAfterChangingFilter , ActionSQL , ApplyFromField , SaveBeforeAction , SaveAfterAction , ReloadTreeAfterAction , ReloadDetailsAfterAction , ApplyToReadonlyCells ) VALUES ( @ActionID , (SELECT COALESCE(@OrderIndex, MAX(OrderIndex), 0) + 1 FROM system.tActions) , COALESCE(@Active, 0) , COALESCE(@Name, N'Unknown') , COALESCE(@Description, N'') , COALESCE(@RequiresClusterWriteRights, 0) , COALESCE(@RequiresWriteRights, 0) , COALESCE(@Condition, N'') , COALESCE(@ListCustomTitle, N'') , COALESCE(@ListSQL, N'') , COALESCE(@ListLayout, N'') , COALESCE(@ListExcelExport, 1) , COALESCE(@SetCellValueAsFilter, 0) , COALESCE(@ReloadListAfterChangingFilter, 0) , COALESCE(@ActionSQL, N'') , COALESCE(@ApplyFromField, N'') , COALESCE(@SaveBeforeAction, N'NO') , COALESCE(@SaveAfterAction, 0) , COALESCE(@ReloadTreeAfterAction, 0) , COALESCE(@ReloadDetailsAfterAction, 0) , COALESCE(@ApplyToReadonlyCells, 1) ); SET @AffectedRows = @@ROWCOUNT; END -- Update other numbers if Number is changed or new IF @OldOrderIndex <> @OrderIndex BEGIN -- case if OrderIndex is bigger now and existed before - decrement all in move window IF @OldOrderIndex < @OrderIndex AND @ActionKey <> 0 BEGIN UPDATE system.tActions SET Orderindex = Orderindex - 1 WHERE Orderindex >= @OldOrderIndex AND Orderindex <= @OrderIndex AND ActionID <> @ActionID; END -- case if OrderIndex is smaller now and existed before - increment all in move window IF @OldOrderIndex > @OrderIndex AND @ActionKey <> 0 BEGIN UPDATE system.tActions SET Orderindex = Orderindex + 1 WHERE Orderindex <= @OldOrderIndex AND Orderindex >= @OrderIndex AND ActionID <> @ActionID; END -- case new Action - increment all following IF @ActionKey = 0 BEGIN UPDATE system.tActions SET Orderindex = Orderindex + 1 WHERE Orderindex >= @OrderIndex AND ActionID <> @ActionID; END -- eliminate all Gaps UPDATE system.tActions SET Orderindex = Rownumbers.Number FROM system.tActions AS tA INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY OrderIndex) AS Number , ActionID FROM system.tActions ) AS Rownumbers ON tA.ActionID = Rownumbers.ActionID END SET @OutputID = @ActionID; SET @ResultCode = 200 COMMIT TRANSACTION spPOST_Action END TRY BEGIN CATCH ROLLBACK TRANSACTION spPOST_Action SET @ResultCode = 500; SET @Comment = ERROR_MESSAGE(); END CATCH; EXEC system.spPOST_APILogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @AffectedRows, @ResultCode, @TimestampCall, @Comment; IF @ResultCode >= 500 EXEC system.spSEND_Message 'ERROR', @Comment; RETURN @ResultCode; END; GO -- SET documentation variables *********************************************************************** DECLARE @level0name NVARCHAR(255) = N'system' -- enter schema name of the table ,@level1name NVARCHAR(255) = N'spPOST_Action' -- enter procedure name ,@SX_Owner NVARCHAR(255) = N'OCT.core' -- enter owner name of the procedure from list (OCT.core, OCT.Actions, Custom) ,@SX_Action NVARCHAR(255) = N'CORE' -- enter Action name as free text (CORE,FIN, DEBKRED, HR, ...) ,@SX_ShipmentFlag INT = 1 -- 0 = Demo object - out of shipment process -- STANDARD OBJECTS -- 1 = shiped from saxess standard without modification -- 2 = shiped from saxess standard modified FOR customer from saxess -- 3 = shiped from saxess standard modified FOR customer from partner -- 4 = shiped from saxess standard modified FROM customer themself for own needs -- CUSTOM OBJECTS -- 10 = shiped from saxess as customer specific object -- 11 = shiped from partner as customer specific object -- 12 = shiped from customer as own specific object ,@SX_UserHint NVARCHAR(2000) = N'' -- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage) -- KEEP this default constants ************************************************************************* DECLARE @name NVARCHAR(255) = N'MS_Description' ,@level0type NVARCHAR(255) = N'SCHEMA' ,@level1type NVARCHAR(255) = N'PROCEDURE' ,@level2type NVARCHAR(255) = N'PARAMETER' ,@level2name NVARCHAR(255) = N'' ,@value NVARCHAR(1000) = N''; SET @value = @SX_Owner; EXEC sys.sp_addextendedproperty N'SX_Owner' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_Action; EXEC sys.sp_addextendedproperty N'SX_Action' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_ShipmentFlag; EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag' ,@value,@level0type,@level0name,@level1type,@level1name; SET @value = @SX_UserHint; EXEC sys.sp_addextendedproperty N'SX_UserHint' ,@value,@level0type,@level0name,@level1type,@level1name; -- SET documententation ************************************************************************* -- SET Procedure documentation SET @value = N'Procedure to POST Action information'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name; -- SET parameter documentation SET @level2name = N'@Username'; SET @value = N'Username'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ActionID'; SET @value = N'Unique ActionID for row identity.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@OrderIndex'; SET @value = N'Index which determines the order when displaying the list of all actions.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Active'; SET @value = N'Determines if the action is enabled or disabled.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Name'; SET @value = N'Name for the action which is displayed in the selection menu.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Description'; SET @value = N'Details about the action. Displayed in tooltips.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@RequiresClusterWriteRights'; SET @value = N'Determines if the action is available only if the user has cluster write rights.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@RequiresWriteRights'; SET @value = N'Determines if the action is available only if the user has write rights on the current object.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@Condition'; SET @value = N'The condition JSON object that is created by the filter builder.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ListCustomTitle'; SET @value = N'Custom title for list SQL dialog.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ListSQL'; SET @value = N'SQL script which is executed when displaying the intial list.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ListLayout'; SET @value = N'Layout information for the list as JSON object.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ListExcelExport'; SET @value = N'Allow export of list dialog to Excel.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SetCellValueAsFilter'; SET @value = N'Apply cell value as filter for the list table.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ReloadListAfterChangingFilter '; SET @value = N'Determines if the list should be reloaded each time the filter in the list dialog is changed.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ActionSQL'; SET @value = N'SQL script which is executed during the action.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ApplyFromField'; SET @value = N'The value of this field is applied to the cell where the action originates from.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SaveBeforeAction'; SET @value = N'Save the system tab or PDT before executing the ActionSQL.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@SaveAfterAction'; SET @value = N'Save the system tab or PDT after executing the ActionSQL.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ReloadTreeAfterAction'; SET @value = N'Reload the tree after executing the ActionSQL.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ReloadDetailsAfterAction'; SET @value = N'Reload the system tab or PDT after executing the ActionSQL.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; SET @level2name = N'@ApplyToReadonlyCells'; SET @value = N'Determines if the action should be applied to readonly cells.'; EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name; GO UPDATE system.tSettings SET ValueText = '2026.08.0', ValueInt = 2026080 WHERE SettingID = 'DBVersion'