USP_DISBURSEMENTPROCESS_DELETE

Executes the "Disbursement Process: Delete" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


CREATE procedure dbo.USP_DISBURSEMENTPROCESS_DELETE
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier
)
as begin
  begin try
      --check deletion rules, if any

     if exists
      select * 
      from dbo.DISBURSEMENTPROCESS as DP
      where
        DP.ID = @ID
        and DP.STATUSCODE != 0 -- 0 = Started

      )
    raiserror ('ERR_CANNOT_DELETE_UNLESS_JUSTCREATED', 16, 1);

    update dbo.INVOICE
      set DISBURSEMENTPROCESSID = null
    where
      DISBURSEMENTPROCESSID = @ID;


    update dbo.CREDITMEMO
      set DISBURSEMENTPROCESSID = null
    where
      DISBURSEMENTPROCESSID = @ID;

    delete 
        dbo.FINANCIALTRANSACTIONAPPLICATION 
    from 
        dbo.FINANCIALTRANSACTIONAPPLICATION as FTA
        join dbo.FINANCIALTRANSACTION as FT on FT.ID = FTA.FINANCIALTRANSACTIONID
        join dbo.DISBURSEMENTPROCESSDISBURSEMENT as DPD on DPD.ID = FT.ID
    where 
        FT.TYPECODE = 255    
      and DPD.DISBURSEMENTPROCESSID = @ID;

    delete 
      dbo.FINANCIALTRANSACTION 
    from 
      dbo.FINANCIALTRANSACTION as FT
      join dbo.DISBURSEMENTPROCESSDISBURSEMENT as DPD on DPD.ID = FT.ID  
    where 
      FT.TYPECODE = 255
      and DPD.DISBURSEMENTPROCESSID = @ID;    

      -- use the system generated delete routine to allow proper recording of the deleting agent

      exec USP_DISBURSEMENTPROCESS_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
      return 0;
    end try
    begin catch
        exec dbo.USP_RAISE_ERROR;
        return 1;
    end catch;  
end