Stored Procedures [dbo].[BATBuildARAPGLNumber_XLedger]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inSessionIDvarchar(50)50
@inOrderIDint4
@inTransactionTypevarchar(30)30
@inSourcevarchar(50)50
@inSourceIDint4
@inObjectvarchar(15)15
@inObjectIDint4
@inBranchIDint4
@inDivisionIDint4
@inAuthorityIDint4
@outGLNumbervarchar(66)66Out
@outAccountingAccountIdint4Out
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
*    
*    Gets a GL number and an AccountingAccount primary key for an AR or AP account.
*    
*    Parameters:
*    @param @inSessionID The unique id of the current session.
*    @param @inOrderID The primary key of the order.
*    @param @inTransactionType The description of the type of transaction (i.e. AR or AP)
*    @param @inSource The source used to log errors.
*    @param @inSourceID The primary key for the source.
*    @param @inObject The object(more generic than source i.e. Orders) used to log errors.
*    @param @inObjectID The primary key for the object.
*    @param @inBranchID The primary key for the branch.
*    @param @inDivisionID The primary key for the division.
*    @param @inAuthorityID The primary key for the authority type.
*    @param @outGLNumber The general ledger number.
* @param @outAccountingAccountId Primary key of an AccountingAccount record.
*    @param @outErrorCode Error code indicating what happened during the call.
*/


create procedure [dbo].[BATBuildARAPGLNumber_XLedger]
    @inSessionID varchar(50),
    @inOrderID int,
    @inTransactionType varchar(30),
    @inSource varchar(50),
    @inSourceID int,
    @inObject varchar(15),
    @inObjectID int,
    @inBranchID int,
    @inDivisionID int,
    @inAuthorityID int,
    @outGLNumber varchar(66) output,
    @outAccountingAccountId int output,
    @outErrorCode     int output
as
set nocount on

-- Initialize the output parameters.
set @outGLNumber = null
set @outErrorCode = 0
set @outAccountingAccountId = null

-- Error codes
declare @ERROR_TRANSACTION_TYPE_IS_INVALID int = 1263
declare @ERROR_TRANSACTION_TYPE_IS_NOT_MAPPED_IN_XLEDGERGLARAP int = 1264

if( @inTransactionType not in ( 'AR', 'AP' ) )
begin
    exec @outErrorCode = spBATRecordError
        @inSessionID,
        @inSource,
        @inSourceID,
        @ERROR_TRANSACTION_TYPE_IS_INVALID,
        @inObject,
        @inObjectID,
        @inTransactionType
end

if( @outErrorCode = 0 )
begin
    select @outAccountingAccountId = AccountingAccountFid
    from XLedgerGLARAP
    where TypeName = @inTransactionType

    if( @outAccountingAccountId is null )
    begin
        exec @outErrorCode = spBATRecordError
            @inSessionID,
            @inSource,
            @inSourceID,
            @ERROR_TRANSACTION_TYPE_IS_NOT_MAPPED_IN_XLEDGERGLARAP,
            @inObject,
            @inObjectID,
            @inTransactionType
    end
end

if( @outErrorCode = 0 )
begin
    select @outGLNumber = AccountingAccount.Code
    from AccountingAccount
    where AccountingAccountId = @outAccountingAccountId
end
GO
GRANT EXECUTE ON  [dbo].[BATBuildARAPGLNumber_XLedger] TO [MssExec]
GO
Uses