Stored Procedures [dbo].[spBATGenerateFirstRevGLNumber_XLedger]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inSessionIDvarchar(50)50
@ICPriKeyint4
@BranchPriKeyint4
@DivisionIDint4
@OrdPriKeyint4
@BATProcessPriKeyint4
@Sourcevarchar(50)50
@SourcePriKeyint4
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
* Don't use this stored proc directly but instead use spBATGenerateFirstRevGLNumber_Synonym.
* spBATGenerateFirstRevGLNumber_Synonym will either point to this stored proc or to
* spBATGenerateFirstRevGLNumber_Legacy if that is active.
*
*
* Description: If parameters are valid, new AccountingAccount is looked up and no error is logged.
*
* Error Codes that get logged via spBATRecordError:
* =================================================
* 1500 if no XLedgerItemCodeMap exists for this ItemCode for account type 'Revenue'
*/


CREATE PROCEDURE [dbo].[spBATGenerateFirstRevGLNumber_XLedger]
    @inSessionID varchar( 50 ),
    @ICPriKey int,
    @BranchPriKey int,
    @DivisionID int,
    @OrdPriKey int,
    @BATProcessPriKey int,
    @Source varchar(50),
    @SourcePriKey int
as

set nocount on

declare @batErrorCode int = 0
declare @firstGLNumberAccountingAccountId int
declare @itemCode int

select
    @itemCode = BATProcess.ItemCode,
    @firstGLNumberAccountingAccountId = XLedgerItemCodeMap.AccountingAccountFid
from BATProcess
left outer join XLedgerItemCodeMapAccountType on XLedgerItemCodeMapAccountType.MappingType = 'Revenue'
left outer join XLedgerItemCodeMap on XLedgerItemCodeMap.ItemCodeFid = BATProcess.ICPriKey and
    XLedgerItemCodeMap.XLedgerItemCodeMapAccountTypeFid = XLedgerItemCodeMapAccountType.XLedgerItemCodeMapAccountTypeId
where BATProcess.BATProcessPriKey = @BATProcessPriKey

if( @firstGLNumberAccountingAccountId is null )
begin
    exec @batErrorCode = spBATRecordError
        @inSessionID,
        @Source,
        @SourcePriKey,
        1500,
        'Order',
        @OrdPriKey,
        @itemCode
end

-- Only if no errors then we can update the record in BATProcess
if( @batErrorCode = 0 )
begin
    update BATProcess set
        GLNumber = AccountingAccount.Code,
        NominalAccountingAccountFid = @firstGLNumberAccountingAccountId
    from BATProcess
    inner join AccountingAccount on AccountingAccount.AccountingAccountId = @firstGLNumberAccountingAccountId
    where BATProcessPriKey = @BATProcessPriKey
end
GO
GRANT EXECUTE ON  [dbo].[spBATGenerateFirstRevGLNumber_XLedger] TO [MssExec]
GO
Uses