TR_MISCELLANEOUSPAYMENT_IUD
Definition
Copy
CREATE trigger [dbo].[TR_MISCELLANEOUSPAYMENT_IUD]
ON [dbo].[MISCELLANEOUSPAYMENT]
AFTER INSERT, UPDATE, DELETE
NOT FOR REPLICATION
AS
--NOTE: if making changes to this trigger see also the trigger(s) on the bankaccountdepositpayment
-- table to and make sure they are in synch
BEGIN
SET NOCOUNT ON
--see if the deposit is locked - if so, raise an error
if exists(Select INSERTED.ID from INSERTED INNER JOIN DBO.BANKACCOUNTDEPOSITPAYMENT ON INSERTED.ID=BANKACCOUNTDEPOSITPAYMENT.ID
INNER JOIN DBO.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=BANKACCOUNTDEPOSITPAYMENT.DEPOSITID
where BANKACCOUNTDEPOSIT.STATUSCODE=0) BEGIN
RAISERROR ('Payments linked to locked deposits cannot be edited.', 16, 1)
ROLLBACK
END
if exists(Select DELETED.ID from DELETED INNER JOIN DBO.BANKACCOUNTDEPOSITPAYMENT ON DELETED.ID=BANKACCOUNTDEPOSITPAYMENT.ID
INNER JOIN DBO.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=BANKACCOUNTDEPOSITPAYMENT.DEPOSITID
where BANKACCOUNTDEPOSIT.STATUSCODE=0) BEGIN
RAISERROR ('Payments linked to locked deposits cannot be edited.', 16, 1)
ROLLBACK
END
--see if the original bank is closed - if so, raise an error
if exists(Select INSERTED.ID from INSERTED INNER JOIN DBO.BANKACCOUNTDEPOSITPAYMENT ON INSERTED.ID=BANKACCOUNTDEPOSITPAYMENT.ID
INNER JOIN DBO.BANKACCOUNTTRANSACTION DEPOSIT1 ON BANKACCOUNTDEPOSITPAYMENT.DEPOSITID=DEPOSIT1.ID
INNER JOIN DBO.BANKACCOUNT ON BANKACCOUNT.ID=DEPOSIT1.BANKACCOUNTID
where BANKACCOUNT.STATUSCODE=0) BEGIN
RAISERROR ('Payments linked to deposits associated with closed bank accounts cannot be edited.', 16, 1)
ROLLBACK
END
if exists(Select DELETED.ID from DELETED INNER JOIN DBO.BANKACCOUNTDEPOSITPAYMENT ON DELETED.ID=BANKACCOUNTDEPOSITPAYMENT.ID
INNER JOIN DBO.BANKACCOUNTTRANSACTION DEPOSIT1 ON BANKACCOUNTDEPOSITPAYMENT.DEPOSITID=DEPOSIT1.ID
INNER JOIN DBO.BANKACCOUNT ON BANKACCOUNT.ID=DEPOSIT1.BANKACCOUNTID
where BANKACCOUNT.STATUSCODE=0) BEGIN
RAISERROR ('Payments linked to deposits associated with closed bank accounts cannot be edited.', 16, 1)
ROLLBACK
END
--*********************************************
--place all error conditions ABOVE this comment
--*********************************************
END