USP_DATAFORMTEMPLATE_EDIT_REGISTRANTDESIGNATION

The save procedure used by the edit dataform template "Registrant Designation Edit Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@REGISTRANTDESIGNATIONS xml IN Designations

Definition

Copy


                                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_REGISTRANTDESIGNATION (
                                        @ID uniqueidentifier,
                                        @CHANGEAGENTID uniqueidentifier = null,
                                        @REGISTRANTDESIGNATIONS xml
                                    )
                                    as

                                        set nocount on;

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

                                        declare @CURRENTDATE datetime
                                        set @CURRENTDATE = getdate()

                                        begin try
                                                    declare @temp table (
                                                            [ID] uniqueidentifier,
                                                            [DESIGNATIONID] uniqueidentifier,
                                                            [AMOUNT] money
                                                    )

                                                    insert into @temp
                                                    select 
                                                            ID, DESIGNATIONID, AMOUNT
                                                    from dbo.UFN_REGISTRANT_GETDESIGNATIONS_FROMITEMLISTXML(@REGISTRANTDESIGNATIONS)

                                                        declare @TOTALRECEIPTAMOUNT money
                                                        declare @SUMAMOUNT money
                                                        select @TOTALRECEIPTAMOUNT = coalesce((select sum(REGISTRANTREGISTRATION.RECEIPTAMOUNT) 
                                                            from dbo.REGISTRANTREGISTRATION 
                                                            where REGISTRANTREGISTRATION.REGISTRANTID = @ID),0)

                                                        select @SUMAMOUNT = coalesce((select sum(AMOUNT) 
                                                        from @temp),0)

                                                        if @SUMAMOUNT > 0 and @TOTALRECEIPTAMOUNT > 0 and @TOTALRECEIPTAMOUNT <> @SUMAMOUNT 
                                                                raiserror('The amount distributed must equal the total receipt amount.',13,1);

                                                    exec dbo.USP_REGISTRANT_GETDESIGNATIONS_UPDATEFROMXML @ID, @REGISTRANTDESIGNATIONS, @CHANGEAGENTID, @CURRENTDATE;

                                        end try
                                        begin catch
                                            exec dbo.USP_RAISE_ERROR
                                            return 1
                                        end catch

                                    return 0;