TR_FINANCIALTRANSACTION_DELETE
Definition
Copy
CREATE trigger TR_FINANCIALTRANSACTION_DELETE on dbo.FINANCIALTRANSACTION for delete not for replication
as begin
set nocount on;
begin try
if exists(
select D.ID
from Deleted D
inner join FINANCIALTRANSACTIONLINEITEM FTLI on D.ID = FTLI.FINANCIALTRANSACTIONID
where FTLI.POSTSTATUSCODE = 2)
begin
raiserror('The financial transaction cannot be deleted because it has been posted', 13,1)
end
if exists(
select D.ID
from Deleted D
where D.TYPECODE = 103)
begin
raiserror('Journal entry batches cannot be deleted from the database. Set the DELETED flag instead.', 13,1)
end
end try
begin catch
exec dbo.USP_RAISE_ERROR;
end catch
--TR_REVENUE_DELETE_DEPOSITLINK
declare @ChangeAgentID uniqueidentifier
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENTFROMCONTEXT @ChangeAgentID output
--TR_REVENUE_DELETE_BBNCREVENUEIDMAP
delete from dbo.BBNCREVENUEIDMAP where REVENUEID in (select ID from deleted where TYPECODE in (0,1,2,3,4,5,6,7,8))
--TR_BANKACCOUNTDEPOSITCORRECTION_UD
--see if the original deposit is locked - if so, raise an error
if exists(Select PARENTID from DELETED INNER JOIN DBO.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=DELETED.PARENTID where
DELETED.PARENTID is not null AND BANKACCOUNTDEPOSIT.STATUSCODE=0 and DELETED.TYPECODE in (24,25)) BEGIN
RAISERROR ('Deposit corrections cannot be removed from locked deposits.', 16, 1)
ROLLBACK
END
end