Stored Procedures [dbo].[ClaimsBATBuildSettlementClearingAccount_Legacy]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inSessionIDvarchar(50)50
@inClaimIDint4
@inSourcevarchar(50)50
@inSourceIDint4
@inObjectvarchar(15)15
@inObjectIDint4
@inBranchIDint4
@inDivisionIDint4
@outGLNumbervarchar(66)66Out
@outAccountingAccountIdint4Out
@outErrorResultbit1Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
*    
*    This procedure concatenates the Claims Settlement Clearing Natural, Sub, Company, Branch, and Division
*    segments into a general ledger number.
*    
*    Error Codes:
*    @ERROR_CODE_NO_MANUAL_GL
*    
*    Input Parameters:
*    @param @inSessionID                The unique id of the current session.
*    @param @inClaimID                The primary key of the claim.
*    @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 @inBranchID                The primary key for the branch.
*    @param @inDivisionID            The primary key for the division.
*    @param @outGLNumber                The concatenated general ledger number.
* @param @outAccountingAccountId Always returns null (this only returns a value from the XLedger version of this stored proc).
*    @param @outErrorResult            Error flag indicating that an error was logged.
*/


create procedure [dbo].[ClaimsBATBuildSettlementClearingAccount_Legacy]
    @inSessionID varchar(50),
    @inClaimID int,
    @inSource varchar(50),
    @inSourceID int,
    @inObject varchar(15),
    @inObjectID int,
    @inBranchID int,
    @inDivisionID int,
    @outGLNumber varchar(66) output,
    @outAccountingAccountId int output,
    @outErrorResult bit output
as
set nocount on

-- Set the output parameters.
set    @outGLNumber = ' '
set    @outErrorResult = 0
set @outAccountingAccountId = null

-- Error codes and constants.
declare @SETTLEMENT_CLEARING_ACCOUNT_DOES_NOT_EXIST int
set    @SETTLEMENT_CLEARING_ACCOUNT_DOES_NOT_EXIST = 5001

declare @theErrorCode int

-- Get the 'Natural' and 'Sub' Settlement Clearing account segments
-- that we use to build the general ledger number.

declare @theMainAccount varchar(16)
declare @theSubAccount    varchar(16)
    
set @theMainAccount = ''
set @theSubAccount = ''

-- Get the main and sub accounts for the given Settlement Clearing record
if exists ( select * from ClaimSettlementClearingAccount where ClaimSettlementClearingAccount.BranchFID = @inBranchID )
begin
    select    
        @theMainAccount = ClaimSettlementClearingAccount.GLAccount,
        @theSubAccount = ClaimSettlementClearingAccount.GLSubAccount
    from ClaimSettlementClearingAccount
    where ClaimSettlementClearingAccount.BranchFID = @inBranchID
end
else if exists ( select * from ClaimSettlementClearingAccount where ClaimSettlementClearingAccount.IsGLDefault = 1 )
begin
    -- get the default
    select    
        @theMainAccount = ClaimSettlementClearingAccount.GLAccount,
        @theSubAccount = ClaimSettlementClearingAccount.GLSubAccount
    from ClaimSettlementClearingAccount
    where ClaimSettlementClearingAccount.IsGLDefault = 1
end
-- otherwise we have an error

if( @theMainAccount = '' )
begin
    declare @theBranchID varchar(5)
    set @theBranchID = ( select BranchID from Branch where BranchPriKey = @inBranchID )
    -- Report an error getting the main account info from the ClaimSettlementClearingAccount
    exec ClaimsAddClaimErrorLog    
        @inSessionID,
        @inClaimID,
        @inSource,
        @inSourceID,
        @inObject,
        @inObjectID,
        @SETTLEMENT_CLEARING_ACCOUNT_DOES_NOT_EXIST,
        @theBranchID

    set @outErrorResult = 1
end
else
begin
    exec BATCheckSegmentLengths
        @inSessionID = @inSessionID,
        @inSource                = @inSource,
        @inSourceID                = @inSourceID,
        @inObject                = @inObject,
        @inObjectID                = @inObjectID,
        @inMainAccount            = @theMainAccount,
        @inSubAccount            = @theSubAccount,
        @inBranchID                = @inBranchID,
        @inDivisionID            = @inDivisionID,
        @outErrorCode            = @theErrorCode output
            
    -- If the segments are valid, build the general ledger number.
    if ( 0 = @theErrorCode )
    begin
        exec BATBuildGLNumber
            @inMainAccount = @theMainAccount,
            @inSubAccount = @theSubAccount,
            @inBranchID = @inBranchID,
            @inDivisionID = @inDivisionID,
            @outGlNumber = @outGLNumber output,
            @outErrorCode = @theErrorCode output

        if( @theErrorCode != 0 )
        begin
            exec @outErrorResult = spBATRecordError @inSessionID, @inSource, @inSourceID, @theErrorCode, @inObject, @inObjectID
        end
    end
    else
    begin
        set @outErrorResult = 1
    end
end
GO
GRANT EXECUTE ON  [dbo].[ClaimsBATBuildSettlementClearingAccount_Legacy] TO [MssExec]
GO
Uses
Used By