TR_INVOICE_DELETE
Definition
Copy
CREATE trigger TR_INVOICE_DELETE on dbo.INVOICE for delete not for replication
as begin
set nocount on;
begin try
if exists(
select D.ID
from Deleted D
inner join dbo.FINANCIALTRANSACTION F on F.ID = D.ID
where F.POSTSTATUSCODE = 2)
begin
raiserror('The invoice cannot be deleted because it has been posted.', 13,1)
end
if exists(
select D.ID
from Deleted D
inner join dbo.DISBURSEMENTPROCESS DP on DP.ID = D.DISBURSEMENTPROCESSID)
begin
raiserror('The invoice cannot be deleted because it is being processed.', 13,1)
end
if exists(
select D.ID
from Deleted D
inner join dbo.FINANCIALTRANSACTION F on F.ID = D.ID
where D.ZEROBALANCE = 1)
begin
raiserror('The invoice cannot be deleted because it has been paid.', 13,1)
end
end try
begin catch
exec dbo.USP_RAISE_ERROR;
end catch
end