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
end
|