Stored Procedures [dbo].[BATBuildExpenseGLNumber_Legacy]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inSessionIDvarchar(50)50
@inOrderIDint4
@inItemCodeIDint4
@inLaborTypeIDint4
@inBranchIDint4
@inDivisionIDint4
@inSourcevarchar(50)50
@inSourceIDint4
@inObjectvarchar(15)15
@inObjectIDint4
@outExpenseGLNumbervarchar(66)66Out
@outAccountingAccountIdint4Out
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
*    
*    This procedure concatenates the Natural, Sub, Company, Branch, and Division
*    segments into a general ledger number for the Expense account mapped to a particular item code.
*    
*    Input Parameters:
*    @param @inSessionID                ID to uniquely identify current BAT Session.
*    @param @inOrderID                Primary key of the Order record.
*    @param @inItemCodeID            Primary key of the ItemCode record.
*    @param @inLaborTypeID            Primary key of the LaborType record.
*    @param @inBranchID                The primary key for the branch.
*    @param @inDivisionID            The primary key for the division.
*    @param @inSource                The source used to log errors.
*    @param @inSourceID                The primary key for the source.
*    @param @inObject                The object(more generic than source i.e. Orders) used to log errors.
*    @param @inObjectID                The primary key for the object.
*    @param @outExpenseGLNumber        The concatenated Expense general ledger number.
* @param @outAccountingAccountId Always returns null (this only returns a value from the XLedger version of this stored proc, BATBuildExpenseGLNumber_XLedger).
*    @param @outErrorCode            Error code indicating what happened during the call.
*/


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

-- Local Variables
declare @theICDetailID            int
set        @theICDetailID            = -1
declare @theICCommissionsID        int
set        @theICCommissionsID        = -1
declare @theExpenseMainAccount varchar(16)
declare @theExpenseSubAccount    varchar(16)
declare @theErrorCode int

-- Constants
declare @ERROR_MISSING_GLNUMBER int
set @ERROR_MISSING_GLNUMBER = 751

-- Set the output parameters.
set    @outExpenseGLNumber    = ''
set    @outErrorCode    = 0
set @outAccountingAccountId = null
set    @theErrorCode    = 0
        
-- Get the ICDetail record matching the incoming parameters
exec BATGetRevenueGLICMapID
    @inSessionID        = @inSessionID,
    @inOrderID            = @inOrderID,
    @inItemCodeID        = @inItemCodeID,
    @inSource            = @inSource,
    @inSourceID            = @inSourceID,
    @inObject            = @inObject,
    @inObjectID            = @inObjectID,
    @outICDetailID        = @theICDetailID output,
    @outErrorCode        = @theErrorCode output
    
-- Make sure an error is returned if present
if( 0 != @theErrorCode )
begin
    set @outErrorCode = 1
    set @theErrorCode = 0
end
else
begin
    -- Get the ICCommissions record matching the incoming parameters
    exec BATGetExpenseGLICMapID
        @inSessionID = @inSessionID,
        @inOrderID            = @inOrderID,
        @inICDetailID        = @theICDetailID,
        @inLaborTypeID        = @inLaborTypeID,
        @inSource            = @inSource,
        @inSourceID            = @inSourceID,
        @inObject            = @inObject,
        @inObjectID            = @inObjectID,
        @outICCommissionsID    = @theICCommissionsID output,
        @outErrorCode        = @theErrorCode output
        
    -- Make sure an error is returned if present
    if( 0 != @theErrorCode )
    begin
        set @outErrorCode = 1
        set @theErrorCode = 0
    end
    else
    begin
        -- Get the main and sub accounts for the given ICCommissions record
        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
        
        -- Make sure an error is returned if present
        if( 0 != @theErrorCode )
        begin
            set @outErrorCode = 1
            set @theErrorCode = 0
        end
        else
        begin
            -- If the segments are valid, build the general ledger number.
            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
            
        -- Make sure an error is returned if present
        if( 0 != @theErrorCode )
        begin
            -- Get the descriptions of the parameters to give a better error message
            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
Uses
Used By