USP_DONORCHALLENGEENCUMBEREDFUND_REMOVE

Executes the "Donor Challenge Encumbered Fund: Remove" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.

Definition

Copy


create procedure dbo.USP_DONORCHALLENGEENCUMBEREDFUND_REMOVE
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier
)
as
  set nocount on

  begin try

    declare @CURRENTDATE datetime = getdate();

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

    --if this is not reserve and not a pledge payment then set the status as removed otherwise delete

    if exists(select DONORCHALLENGEENCUMBERED.ID from dbo.DONORCHALLENGEENCUMBERED inner join dbo.REVENUESPLIT on REVENUESPLIT.ID = DONORCHALLENGEENCUMBERED.REVENUESPLITID where DONORCHALLENGEENCUMBERED.ID = @ID and REVENUESPLIT.APPLICATIONCODE <> 2)
      update dbo.DONORCHALLENGEENCUMBERED set
        STATUSTYPECODE = 2,
        DATECHANGED = @CURRENTDATE,
        CHANGEDBYID = @CHANGEAGENTID
      where
        ID = @ID;
    else
      exec dbo.USP_DONORCHALLENGEENCUMBERED_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID

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