USP_DATAFORMTEMPLATE_ADD_BENEFIT

The save procedure used by the add dataform template "Benefit 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(100) IN Name
@DESCRIPTION nvarchar(255) IN Description
@BENEFITCATEGORYCODEID uniqueidentifier IN Category
@VALUE money IN Value
@SENDBENEFITCODE tinyint IN Send benefit when pledge is
@USEPERCENT bit IN Use percent
@VALUEPERCENT numeric(20, 2) IN Percent
@SITES xml IN Sites
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@BENEFITVENDORID uniqueidentifier IN
@FULFILLMENTVENDORID uniqueidentifier IN
@BENEFITDESC nvarchar(100) IN
@COST money IN

Definition

Copy


                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_BENEFIT
                    (
                        @ID uniqueidentifier = null output,
                        @CHANGEAGENTID uniqueidentifier = null,    
                        @NAME nvarchar(100) = '',
                        @DESCRIPTION nvarchar(255) = '',
                        @BENEFITCATEGORYCODEID uniqueidentifier = null,
                        @VALUE money = 0,
                        @SENDBENEFITCODE tinyint = 0,
                        @USEPERCENT bit = 0,
                        @VALUEPERCENT numeric(20,2) = 0,
                        @SITES xml = null,
                        @CURRENTAPPUSERID uniqueidentifier = null,
            @BENEFITVENDORID uniqueidentifier = null,
            @FULFILLMENTVENDORID uniqueidentifier = null,
            @BENEFITDESC nvarchar(100) = '',
            @COST money = 0
                    )
                    as
                    begin
                        set nocount on;

                        if @SITES is null
                        begin 
                            if dbo.UFN_SITEREQUIREDFORUSER(@CURRENTAPPUSERID) = 1 
                            begin
                                raiserror('ERR_BENEFITSITE_SITEID',13,1);
                                return 1;
                            end
                        end

                        declare @CURRENTDATE datetime;
                        declare @BASECURRENCYID uniqueidentifier;

                        --If the benefit is a percent benefit, don't save the base currency

                        if @USEPERCENT = 0
                            set @BASECURRENCYID = dbo.UFN_APPUSER_GETBASECURRENCY(@CURRENTAPPUSERID);

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

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

                        set @CURRENTDATE = getdate()

                        begin try                                   
                            insert into dbo.BENEFIT
                                (ID,NAME,DESCRIPTION,BENEFITCATEGORYCODEID,VALUE,USEPERCENT,VALUEPERCENT,SENDBENEFITCODE,BASECURRENCYID,BENEFITVENDORID,FULFILLMENTVENDORID,BENEFITDESC,COST,ADDEDBYID,CHANGEDBYID,DATEADDED,DATECHANGED)
                            VALUES
                                (@ID,@NAME,@DESCRIPTION,@BENEFITCATEGORYCODEID,@VALUE,@USEPERCENT,@VALUEPERCENT,@SENDBENEFITCODE,@BASECURRENCYID,@BENEFITVENDORID,@FULFILLMENTVENDORID,@BENEFITDESC,@COST,@CHANGEAGENTID,@CHANGEAGENTID,@CURRENTDATE,@CURRENTDATE)

                            exec dbo.USP_BENEFITSITE_GETSITES_ADDFROMXML @ID, @SITES, @CHANGEAGENTID;  
                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch

                        return 0

                    end