USP_DATAFORMTEMPLATE_EDIT_NAMINGOPPORTUNITY

The save procedure used by the edit dataform template "Naming Opportunity Edit Form".

Parameters

Parameter Parameter Type Mode Description
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@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.
@NAME nvarchar(100) IN Name
@DESCRIPTION nvarchar(100) IN Description
@TYPECODEID uniqueidentifier IN Type
@CONTACTID uniqueidentifier IN Contact
@QUANTITY int IN Quantity
@PURPOSEID uniqueidentifier IN Fundraising purpose
@FACILITYID uniqueidentifier IN Facility
@CAMPAIGNID uniqueidentifier IN Campaign
@MINIMUMAMOUNT money IN Minimum gift amount
@SITEID uniqueidentifier IN Site

Definition

Copy


                    CREATE procedure USP_DATAFORMTEMPLATE_EDIT_NAMINGOPPORTUNITY
                    (
                        @CURRENTAPPUSERID uniqueidentifier,
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null,
                        @NAME nvarchar(100),
                        @DESCRIPTION nvarchar(100),
                        @TYPECODEID uniqueidentifier,
                        @CONTACTID uniqueidentifier,
                        @QUANTITY int,
                        @PURPOSEID uniqueidentifier,
                        @FACILITYID uniqueidentifier,
                        @CAMPAIGNID uniqueidentifier,
                        @MINIMUMAMOUNT money,
                        @SITEID uniqueidentifier
                    )
                    as
                    begin

                        set nocount on;

                        begin try
                            if @SITEID is null
                            begin 
                                if dbo.UFN_SITEREQUIREDFORUSER(@CURRENTAPPUSERID) = 1 
                                begin
                                    raiserror('Site is required.',13,1)
                                    return
                                end
                            end

                            declare @CHANGEDATE datetime;

                            if @ID is null
                                set @ID = newid();
                            if @CHANGEAGENTID is null
                                exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
                            set @CHANGEDATE = getdate();

                            declare @BASECURRENCYID uniqueidentifier;
                            declare @DATEADDED datetime;
                            declare @CURRENCYEXCHANGERATEID uniqueidentifier;
                            declare @ORGANIZATIONMINIMUMAMOUNT money;
                            declare @ORGANIZATIONCURRENCYID uniqueidentifier;
                            set @ORGANIZATIONCURRENCYID = dbo.UFN_CURRENCY_GETORGANIZATIONCURRENCY();

                            select
                                @BASECURRENCYID = NAMINGOPPORTUNITY.BASECURRENCYID,
                                @DATEADDED = NAMINGOPPORTUNITY.DATEADDED,
                                @CURRENCYEXCHANGERATEID = NAMINGOPPORTUNITY.ORGANIZATIONEXCHANGERATEID
                            from
                                dbo.NAMINGOPPORTUNITY
                            where
                                NAMINGOPPORTUNITY.ID = @ID;

                            if (@ORGANIZATIONCURRENCYID = @BASECURRENCYID)
                            begin
                                set @ORGANIZATIONMINIMUMAMOUNT = @MINIMUMAMOUNT;
                            end
                            else
                            begin
                                if @CURRENCYEXCHANGERATEID is null
                                    set @CURRENCYEXCHANGERATEID = dbo.UFN_CURRENCYEXCHANGERATE_GETLATEST(@BASECURRENCYID, @ORGANIZATIONCURRENCYID, @DATEADDED, 0, null);

                                set @ORGANIZATIONMINIMUMAMOUNT = dbo.UFN_CURRENCY_CONVERT(@MINIMUMAMOUNT, @CURRENCYEXCHANGERATEID);
                            end

                            update
                                dbo.NAMINGOPPORTUNITY
                            set
                                NAME = @NAME,
                                DESCRIPTION = @DESCRIPTION,
                                NAMINGOPPORTUNITYTYPECODEID = @TYPECODEID,
                                CONTACTID = @CONTACTID,
                                QUANTITY = @QUANTITY,
                                PURPOSEID = @PURPOSEID,
                                FACILITYID = @FACILITYID,
                                CAMPAIGNID = @CAMPAIGNID,
                                MINIMUMAMOUNT = @MINIMUMAMOUNT,
                                SITEID = @SITEID,
                                ORGANIZATIONMINIMUMAMOUNT = @ORGANIZATIONMINIMUMAMOUNT,
                                ORGANIZATIONEXCHANGERATEID = @CURRENCYEXCHANGERATEID,

                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CHANGEDATE
                            where
                                ID = @ID
                        end try

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

                        return 0;
                    end