Stored Procedures [dbo].[BATBuildRevenueGLNumber_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
@outRevenueGLNumbervarchar(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 Revenue 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 @outRevenueGLNumber The concatenated Revenue general ledger number.
* @param @outAccountingAccountId Always returns null (this only returns a value from the XLedger version of this stored proc, BATBuildRevenueGLNumber_XLedger).
*    @param @outErrorCode Error code indicating what happened during the call.
*/


create procedure [dbo].[BATBuildRevenueGLNumber_Legacy]
    @inSessionID varchar(50),
    @inOrderID int,
    @inItemCodeID int,
    @inLaborTypeID int,
    @inBranchID int,
    @inDivisionID int,
    @inSource varchar(50),
    @inSourceID int,
    @inObject varchar(15),
    @inObjectID int,
    @outRevenueGLNumber 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 @theRevenueMainAccount varchar(16)
declare @theRevenueSubAccount varchar(16)
declare @theErrorCode int

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

-- Set the output parameters.
set @outRevenueGLNumber = ''
set @outErrorCode = 0
set @theErrorCode = 0
set @outAccountingAccountId = null
        
-- 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 main and sub accounts for the given ICDetail record
    select
        @theRevenueMainAccount    = ICDetail.RevGLAccount,
        @theRevenueSubAccount    = ICDetail.RevGLSubAccount
    from ICDetail
    where ICDetail.ICDPriKey = @theICDetailID
    
    -- Check the Revenue GL Account
    exec BATCheckSegmentLengths
        @inSessionID = @inSessionID,
        @inSource = @inSource,
        @inSourceID = @inSourceID,
        @inObject = @inObject,
        @inObjectID = @inObjectID,
        @inMainAccount = @theRevenueMainAccount,
        @inSubAccount = @theRevenueSubAccount,
        @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 = @theRevenueMainAccount,
            @inSubAccount = @theRevenueSubAccount,
            @inBranchID = @inBranchID,
            @inDivisionID = @inDivisionID,
            @outGlNumber = @outRevenueGLNumber output,
            @outErrorCode = @theErrorCode output

        if( @theErrorCode != 0 )
        begin
            exec @outErrorCode = spBATRecordError @inSessionID, @inSource, @inSourceID, @theErrorCode, @inObject, @inObjectID
        end
        
        exec @theErrorCode    =
            spBATCheckGLNumber
                @inSessionID = @inSessionID,
                @GLNumber = @outRevenueGLNumber,
                @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
            set @theItemCode =
            isnull( (
                select ItemCode
                from ItemCode
                where ICPriKey = @inItemCodeID    
            ), -1 )
            
            set @outRevenueGLNumber = isnull( @outRevenueGLNumber, '' )
            
            exec spBATRecordError
                @inSessionID,
                @inSource,
                @inSourceID,
                @ERROR_MISSING_GLNUMBER,
                @inObject,
                @inObjectID,
                @outRevenueGLNumber,
                @theItemCode
                
            set @outErrorCode = 1
        end
    end
end
GO
GRANT EXECUTE ON  [dbo].[BATBuildRevenueGLNumber_Legacy] TO [MssExec]
GO
Uses
Used By