
[dbo].[BATBuildExpenseGLNumber_Legacy]
create procedure [dbo].[BATBuildExpenseGLNumber_Legacy]
@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 @theICDetailID int
set @theICDetailID = -1
declare @theICCommissionsID int
set @theICCommissionsID = -1
declare @theExpenseMainAccount varchar(16)
declare @theExpenseSubAccount varchar(16)
declare @theErrorCode int
declare @ERROR_MISSING_GLNUMBER int
set @ERROR_MISSING_GLNUMBER = 751
set @outExpenseGLNumber = ''
set @outErrorCode = 0
set @outAccountingAccountId = null
set @theErrorCode = 0
exec BATGetRevenueGLICMapID
@inSessionID = @inSessionID,
@inOrderID = @inOrderID,
@inItemCodeID = @inItemCodeID,
@inSource = @inSource,
@inSourceID = @inSourceID,
@inObject = @inObject,
@inObjectID = @inObjectID,
@outICDetailID = @theICDetailID output,
@outErrorCode = @theErrorCode output
if( 0 != @theErrorCode )
begin
set @outErrorCode = 1
set @theErrorCode = 0
end
else
begin
exec BATGetExpenseGLICMapID
@inSessionID = @inSessionID,
@inOrderID = @inOrderID,
@inICDetailID = @theICDetailID,
@inLaborTypeID = @inLaborTypeID,
@inSource = @inSource,
@inSourceID = @inSourceID,
@inObject = @inObject,
@inObjectID = @inObjectID,
@outICCommissionsID = @theICCommissionsID output,
@outErrorCode = @theErrorCode output
if( 0 != @theErrorCode )
begin
set @outErrorCode = 1
set @theErrorCode = 0
end
else
begin
select
@theExpenseMainAccount = ICCommissions.CommGLAccount,
@theExpenseSubAccount = ICCommissions.CommGLSubAccount
from ICCommissions
where ICCommissions.ICCommPriKey = @theICCommissionsID
exec BATCheckSegmentLengths
@inSessionID = @inSessionID,
@inSource = @inSource,
@inSourceID = @inSourceID,
@inObject = @inObject,
@inObjectID = @inObjectID,
@inMainAccount = @theExpenseMainAccount,
@inSubAccount = @theExpenseSubAccount,
@inBranchID = @inBranchID,
@inDivisionID = @inDivisionID,
@outErrorCode = @theErrorCode output
if( 0 != @theErrorCode )
begin
set @outErrorCode = 1
set @theErrorCode = 0
end
else
begin
exec BATBuildGLNumber
@inMainAccount = @theExpenseMainAccount,
@inSubAccount = @theExpenseSubAccount,
@inBranchID = @inBranchID,
@inDivisionID = @inDivisionID,
@outGlNumber = @outExpenseGLNumber output,
@outErrorCode = @theErrorCode output
if( @theErrorCode != 0 )
begin
exec @outErrorCode = spBATRecordError @inSessionID, @inSource, @inSourceID, @theErrorCode, @inObject, @inObjectID
set @theErrorCode = 0
end
end
exec @theErrorCode =
spBATCheckGLNumber
@inSessionID = @inSessionID,
@GLNumber = @outExpenseGLNumber,
@BranchPriKey = @inBranchID,
@Source = @inSource,
@SourcePriKey = @inSourceID,
@inObject = @inObject,
@inObjectID = @inObjectID
if( 0 != @theErrorCode )
begin
declare @theItemCode int
declare @theLaborType varchar(20)
set @theItemCode =
isnull( (
select ItemCode
from ItemCode
where ICPriKey = @inItemCodeID
), -1 )
set @theLaborType =
isnull( (
select LaborType
from LaborType
where PriKey = @inLaborTypeID
), '' )
set @outExpenseGLNumber = isnull( @outExpenseGLNumber, '' )
exec spBATRecordError
@inSessionID,
@inSource,
@inSourceID,
@ERROR_MISSING_GLNUMBER,
@inObject,
@inObjectID,
@outExpenseGLNumber,
@theItemCode,
@theLaborType
set @outErrorCode = 1
end
end
end
GO
GRANT EXECUTE ON [dbo].[BATBuildExpenseGLNumber_Legacy] TO [MssExec]
GO