
[dbo].[BATBuildExpenseGLNumber_XLedger]
create procedure [dbo].[BATBuildExpenseGLNumber_XLedger]
@inSessionID varchar(50),
@inOrderID int,
@inItemCodeID int,
@inLaborTypeID int,
@inBranchID int,
@inDivisionID int,
@inSource varchar(50),
@inSourceID int,
@inObject varchar(15),
@inObjectID int,
@outExpenseGLNumber varchar(66) output,
@outAccountingAccountId int output,
@outErrorCode int output
as
set nocount on
declare @ERROR_MISSING_ACCOUNT int
set @ERROR_MISSING_ACCOUNT = 758
set @outExpenseGLNumber = ''
set @outErrorCode = 0
set @outAccountingAccountId = null
select
@outAccountingAccountId = XLedgerItemCodeMap.AccountingAccountFid,
@outExpenseGLNumber = isnull( AccountingAccount.Code, '' )
from XLedgerItemCodeMap
inner join XLedgerItemCodeMapAccountType on
XLedgerItemCodeMapAccountType.XLedgerItemCodeMapAccountTypeId = XLedgerItemCodeMap.XLedgerItemCodeMapAccountTypeFid
inner join AccountingAccount on AccountingAccount.AccountingAccountId = XLedgerItemCodeMap.AccountingAccountFid
where
XLedgerItemCodeMapAccountType.MappingType = 'Expense' and
XLedgerItemCodeMap.ItemCodeFid = @inItemCodeID
if( @outAccountingAccountId is null or @outExpenseGLNumber = '' )
begin
set @outErrorCode = 1
declare @theItemCode int
select @theItemCode = isnull( ItemCode, -1 )
from ItemCode
where ICPriKey = @inItemCodeID
exec spBATRecordError
@inSessionID,
@inSource,
@inSourceID,
@ERROR_MISSING_ACCOUNT,
@inObject,
@inObjectID,
@outExpenseGLNumber,
@theItemCode,
null
end
GO
GRANT EXECUTE ON [dbo].[BATBuildExpenseGLNumber_XLedger] TO [MssExec]
GO