
[dbo].[spBATGenerateFirstRevGLNumber_XLedger]
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
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