
[dbo].[spBATGenerateFirstCommGLNumber_XLedger]
CREATE PROCEDURE [dbo].[spBATGenerateFirstCommGLNumber_XLedger]
@ICPriKey int,
@BranchPriKey int,
@DivisionID int,
@OrdPriKey int,
@CommissionSysuser int,
@BATProcessPriKey int,
@Source varchar(50),
@SourcePriKey int
as
set nocount on
declare @batErrorCode int = 0
declare @firstGLNumberAccountingAccountId int
declare @itemCode int
declare @theBlankSessionID varchar( 50 )
set @theBlankSessionID = ''
select
@itemCode = BATProcess.ItemCode,
@firstGLNumberAccountingAccountId = XLedgerItemCodeMap.AccountingAccountFid
from BATProcess
left outer join XLedgerItemCodeMapAccountType on XLedgerItemCodeMapAccountType.MappingType = 'Commissions'
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
@theBlankSessionID,
@Source,
@SourcePriKey,
1605,
'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].[spBATGenerateFirstCommGLNumber_XLedger] TO [MssExec]
GO