USP_AUCTIONDONATIONWRITEOFF_DELETE

Executes the "Auction Donation Write-off: Delete" record operation.

Parameters

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

Definition

Copy


                    CREATE procedure dbo.USP_AUCTIONDONATIONWRITEOFF_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as

                    set nocount on;

                    --Cache CONTEXT INFO

                    declare @contextCache varbinary(128);
                    set @contextCache = CONTEXT_INFO();

                    if not @CHANGEAGENTID is null
                        set CONTEXT_INFO @CHANGEAGENTID;

                    if (select POSTSTATUSCODE from dbo.WRITEOFF where ID = @ID) = 0
                    begin
                        raiserror('This write-off has been posted and cannot be deleted.', 13, 1);
                        return 0;
                    end

                    if (select top 1 REVENUE.TRANSACTIONTYPECODE from dbo.WRITEOFF inner join dbo.REVENUE on REVENUE.ID = WRITEOFF.REVENUEID where WRITEOFF.ID = @ID) <> 7
                    begin
                        raiserror('This record operation can only delete write-offs for auction donations.', 13, 1);
                        return 0;
                    end

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

                    -- Delete unposted write-off distributions.

                    delete from dbo.WRITEOFFGLDISTRIBUTION where ID in (
                        select WRITEOFFGLDISTRIBUTION.ID
                        from WRITEOFFGLDISTRIBUTION
                        inner join dbo.GLTRANSACTION on WRITEOFFGLDISTRIBUTION.GLTRANSACTIONID = GLTRANSACTION.ID
                        where WRITEOFFGLDISTRIBUTION.WRITEOFFID = @ID and GLTRANSACTION.POSTSTATUSCODE <> 0
                    );

                    --Restore CONTEXT_INFO

                    if not @contextCache is null
                        set CONTEXT_INFO @contextCache;

                    exec dbo.USP_WRITEOFF_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;

                    return 0;