USP_BATCHDIRECTDEBITRETURN_DELETEBATCH
Executes the "Direct Debit Return Batch: 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. |
@CURRENTAPPUSERID | uniqueidentifier | IN | Input parameter indicating the ID of the current user. |
Definition
Copy
CREATE PROCEDURE dbo.USP_BATCHDIRECTDEBITRETURN_DELETEBATCH(@ID uniqueidentifier, @CHANGEAGENTID uniqueidentifier, @CURRENTAPPUSERID uniqueidentifier = null)
AS
BEGIN
set nocount on;
declare @CURRENTDATE datetime;
set @CURRENTDATE = getdate();
begin try
declare @lockName nvarchar(36);
set @lockName = upper(cast(@ID as nvarchar(36)));
declare @result int;
exec @result = sp_getapplock @Resource=@lockName, @LockMode='Exclusive', @LockOwner='Session', @LockTimeout=0;
if @result = 0
begin
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
if @CURRENTAPPUSERID is not null
begin
declare @GRANTED bit
select @GRANTED=dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHOWNER(@CURRENTAPPUSERID, @ID)
if @GRANTED = 0
raiserror('You do not have permission to delete this batch.', 13, 1);
end;
delete from dbo.BATCHDIRECTDEBITRETURN where BATCHID = @ID;
exec sp_releaseapplock @Resource=@lockName, @LockOwner='Session';
end;
else
raiserror('This batch is in use and cannot be deleted.', 13, 1);
end try
begin catch
exec dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;
END