USP_EDIT_REVENUE_VALIDATE_DEPOSIT_STATUS

Raises an error if the deposit associated with the specified revenue ID should not be modified

Parameters

Parameter Parameter Type Mode Description
@REVENUEID uniqueidentifier IN

Definition

Copy


CREATE procedure [dbo].[USP_EDIT_REVENUE_VALIDATE_DEPOSIT_STATUS]
(
    @REVENUEID uniqueidentifier
)
as 
    set nocount on;

        --see if the deposit is locked - if so, raise an error (cannot add to, nor delete from locked deposits)

        if exists(Select BANKACCOUNTDEPOSITPAYMENT.ID from DBO.BANKACCOUNTDEPOSITPAYMENT 
            INNER JOIN DBO.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=BANKACCOUNTDEPOSITPAYMENT.DEPOSITID 
            INNER JOIN DBO.FINANCIALTRANSACTION BANKACCOUNTTRANSACTION on BANKACCOUNTTRANSACTION.ID = BANKACCOUNTDEPOSIT.ID
            where BANKACCOUNTDEPOSITPAYMENT.ID=@REVENUEID AND BANKACCOUNTDEPOSIT.STATUSCODE=0 and BANKACCOUNTTRANSACTION.POSTSTATUSCODE != 2) BEGIN
                RAISERROR ('Payments linked to locked deposits cannot be edited.',  16, 1)
        END

        --see if the original bank is closed - if so, raise an error (cannot add to, nor delete from deposits in a closed bankaccount)

        if exists(Select BANKACCOUNTDEPOSITPAYMENT.ID from DBO.BANKACCOUNTDEPOSITPAYMENT 
            INNER JOIN DBO.BANKACCOUNTTRANSACTION_EXT DEPOSIT1 ON BANKACCOUNTDEPOSITPAYMENT.DEPOSITID=DEPOSIT1.ID
            INNER JOIN DBO.BANKACCOUNT ON BANKACCOUNT.ID=DEPOSIT1.BANKACCOUNTID
            where BANKACCOUNTDEPOSITPAYMENT.ID=@REVENUEID AND BANKACCOUNT.STATUSCODE=0) BEGIN
                RAISERROR ('Payments linked to deposits associated with closed bank accounts cannot be edited.',  16, 1)
        END

        if exists(Select I.ID
            from dbo.FINANCIALTRANSACTION I
            inner join dbo.BANKACCOUNTDEPOSITPAYMENT on BANKACCOUNTDEPOSITPAYMENT.ID = I.ID
            inner join dbo.FINANCIALTRANSACTION BANKACCOUNTTRANSACTION on BANKACCOUNTDEPOSITPAYMENT.DEPOSITID = BANKACCOUNTTRANSACTION.ID
            where I.ID=@REVENUEID AND ((I.POSTSTATUSCODE != 3 and BANKACCOUNTTRANSACTION.POSTSTATUSCODE = 3) or (I.POSTSTATUSCODE = 3 and BANKACCOUNTTRANSACTION.POSTSTATUSCODE = 1))) BEGIN
                RAISERROR ('ERR_REVENUE_BANKACCOUNTDEPOSITPAYMENT_POSTSTATUS',  16, 1
        END