Stored Procedures [dbo].[AdvanceBATBuildGLNumber_XLedger]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inSessionIDvarchar(50)50
@inSourcevarchar(50)50
@inSourceIDint4
@inBranchIDint4
@inDivisionIDint4
@outGLNumbervarchar(66)66Out
@outAccountingAccountIdint4Out
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/*
*    Don't call this stored proc directly but instead use AdvanceBATBuildGLNumber_Synonym.
*    AdvanceBATBuildGLNumber_Synonym will either point to:
* AdvanceBATBuildGLNumber_XLedger if XLedger is active, or
*    AdvanceBATBuildGLNumber_Legacy otherwise.
*
*    Description: Gets the GL number and AccountingAccount ID for the expense account to use for advances.
*
* Parameters:
* @param @inSessionID Current BAT session ID
* @param @inSource Source of BAT errors ('Advance')
* @param @inSourceID ID of the record from the Source table that caused a BAT error.
* @param @inBranchID Primary key of the Branch for the advance
* @param @inDivisionID Primary key of the Division for the advance
* @param @outGLNumber GL number of the expense account for the advance
* @param @outAccountingAccountId Primary key of the AccountingAccount for the expense account for the advance
* @param @outErrorCode Error code if an error occurs
*/


create procedure [dbo].[AdvanceBATBuildGLNumber_XLedger]
    @inSessionID varchar(50),
    @inSource varchar(50),
    @inSourceID int,
    @inBranchID int,
    @inDivisionID int,
    @outGLNumber varchar(66) output,
    @outAccountingAccountId int output,
    @outErrorCode     int output
as

set nocount on

declare @theManualGLFlag bit
declare @theAdvanceSetupAccount varchar(16)
declare @theAdvanceSetupSubAccount varchar(16)
declare @ERROR_EXPENSE_ACCOUNT_NOT_SET_UP int = 7020

-- Initialize the AccountingAccount ID.
set @outAccountingAccountId = null

-- For advances, we need to get the AccountingAccount ID for the expense GL account from the AdvanceSetup table.
select @outAccountingAccountId = ExpenseAccountingAccountFid
from AdvanceSetup

if( @outAccountingAccountId is null )
begin
    exec @outErrorCode = spBATRecordError
        @inSessionID,
        @inSource,
        @inSourceID,
        @ERROR_EXPENSE_ACCOUNT_NOT_SET_UP,
        null,
        null
end
else
begin
    select @outGLNumber = AccountingAccount.Code
    from AccountingAccount
    where AccountingAccountId = @outAccountingAccountId
end
GO
GRANT EXECUTE ON  [dbo].[AdvanceBATBuildGLNumber_XLedger] TO [MssExec]
GO
Uses