USP_DATAFORMTEMPLATE_EDIT_DISCOUNTGLDISTRIBUTION

The save procedure used by the edit dataform template "Discount GL Distribution Edit Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@GLDISTRIBUTION xml IN GL distribution
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_DISCOUNTGLDISTRIBUTION
(
    @ID uniqueidentifier,
    @GLDISTRIBUTION xml,
    @CHANGEAGENTID uniqueidentifier = null
)
as
    set nocount on;

    begin try
        if (dbo.UFN_GLDISTRIBUTION_ACCOUNTEXISTS_2(@GLDISTRIBUTION,@ID) = 0)
            raiserror('One or more of the edited accounts do not exist.', 13, 1)

        declare @POSTSTATUSCODE tinyint;
        declare @POSTDATE datetime;

        select
            @POSTSTATUSCODE = POSTSTATUSCODE,
            @POSTDATE = POSTDATE
        from
            dbo.FINANCIALTRANSACTION
        where
            ID = @ID
            and DELETEDON is null;

        --validate post status
        if @POSTSTATUSCODE = 2
            raiserror('You cannot edit a posted order.', 13, 1)

        if (dbo.UFN_GLDISTRIBUTION_DEBITSEQUALCREDITS(@GLDISTRIBUTION) = 0)
            raiserror('The sum of the debit accounts must equal the sum of the credit accounts.', 13, 1)

        if @CHANGEAGENTID is null  
            exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

        exec dbo.USP_REVENUE_GETCREDITGLDISTRIBUTION_CUSTOMUPDATEFROMXML @ID, @GLDISTRIBUTION, @POSTDATE, @CHANGEAGENTID;
    end try

    begin catch
        exec dbo.USP_RAISE_ERROR;
        return 1;
    end catch

    return 0;