USP_DATAFORMTEMPLATE_ADD_PDACCOUNTSYSTEM

The save procedure used by the add dataform template "Account System Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@NAME nvarchar(50) IN Name
@DESCRIPTION nvarchar(255) IN Description
@ISDEFAULT bit IN Use this account system for users without site permissions
@SITES xml IN Sites
@CURRENCYSETID uniqueidentifier IN Currency set

Definition

Copy


                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_PDACCOUNTSYSTEM
                    (
                        @ID uniqueidentifier = null output,
                        @CHANGEAGENTID uniqueidentifier = null,
                        @NAME nvarchar(50) = '',
                        @DESCRIPTION nvarchar(255) = '',
                        @ISDEFAULT bit = 0,
                        @SITES xml = null,
                        @CURRENCYSETID uniqueidentifier = null
                    )
                    as

                    set nocount on;

                    if @ID is null
                        set @ID = newid()

                    if @CHANGEAGENTID is null  
                        exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

                    declare @CURRENTDATE datetime
                    set @CURRENTDATE = getdate()

                    begin try
                        -- Only one system can be set to default.

                        if @ISDEFAULT = 1 
                            update PDACCOUNTSYSTEM set ISDEFAULT = 0 where ISDEFAULT = 1

                        -- handle inserting the data

                        insert into dbo.PDACCOUNTSYSTEM(
                            ID, 
                            NAME, 
                            DESCRIPTION, 
                            ISDEFAULT, 
                            ADDEDBYID, 
                            CHANGEDBYID, 
                            DATEADDED, 
                            DATECHANGED,
                            CURRENCYSETID
                        )
                        values(
                            @ID
                            @NAME
                            @DESCRIPTION
                            @ISDEFAULT
                            @CHANGEAGENTID
                            @CHANGEAGENTID
                            @CURRENTDATE
                            @CURRENTDATE,
                            @CURRENCYSETID
                        )

                        if @SITES is not null
                            exec dbo.USP_PDACCOUNTSYSTEM_SITES_ADDFROMXML @ID, @SITES, @CHANGEAGENTID, @CURRENTDATE


                        -- Create the default Struture items:

                        declare @STRUCTUREID uniqueidentifier
                        declare @STRUCTURENAME nvarchar(100)

                        -- Add the new default structure. when we can figure out how!

                        set @STRUCTUREID = newid()
                        set @STRUCTURENAME = 'Account Code'
                        insert into dbo.PDACCOUNTSTRUCTURE(ID,DESCRIPTION,SEQUENCE,LENGTH,PDACCOUNTTABLESAVAILABLEFORSEGMENTID,SEPARATORCODE,SEGMENTTYPE, PDACCOUNTSYSTEMID,ELEMENTDEFINITIONCODE, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                            values(@STRUCTUREID,@STRUCTURENAME, 1, 0, 'E27FB5F2-A56F-424A-9E9F-72EA9B8FA816', 1, 1, @ID,1, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

                        insert into dbo.GLACCOUNTMAPPINGERRORUPDATEPROCESS(ID, PDACCOUNTSYSTEMID) values (NEWID(), @ID);

                    end try

                    begin catch
                        exec dbo.USP_RAISE_ERROR
                        return 1
                    end catch

                    return 0