Stored Procedures [dbo].[ClaimsBATBuildSettlementClearingAccount_XLedger]
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
/**
*    
*    Gets the GL number and AccountingAccount ID for the Claims Settlement Clearing Account for the specified branch,
* or if those don't exist for the branch, gets the default GL number and AccountingAccountID (if a default exists).
*    
*    Error Codes:
*    5001 - No GL account could be found for the branch and no default account exists.
*    
*    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 Primary key of the AccountingAccount record for the GL account.
*    @param @outErrorResult            Error flag indicating that an error was logged.
*/


create procedure [dbo].[ClaimsBATBuildSettlementClearingAccount_XLedger]
    @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 GL number and AccountingAccount ID for the branch (or if none exists for the branch, get the default).
if exists ( select top 1 1 from ClaimSettlementClearingAccount where ClaimSettlementClearingAccount.BranchFID = @inBranchID )
begin
    select    
        @outGLNumber = AccountingAccount.Code,
        @outAccountingAccountId = AccountingAccount.AccountingAccountId
    from ClaimSettlementClearingAccount
    inner join AccountingAccount on AccountingAccount.AccountingAccountId = ClaimSettlementClearingAccount.AccountingAccountFid
    where ClaimSettlementClearingAccount.BranchFID = @inBranchID
end
else if exists ( select top 1 1 from ClaimSettlementClearingAccount where ClaimSettlementClearingAccount.IsGLDefault = 1 )
begin
    -- Get the default account.
    select    
        @outGLNumber = AccountingAccount.Code,
        @outAccountingAccountId = AccountingAccount.AccountingAccountId
    from ClaimSettlementClearingAccount
    inner join AccountingAccount on AccountingAccount.AccountingAccountId = ClaimSettlementClearingAccount.AccountingAccountFid
    where ClaimSettlementClearingAccount.IsGLDefault = 1
end

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

    set @outErrorResult = 1
end
GO
GRANT EXECUTE ON  [dbo].[ClaimsBATBuildSettlementClearingAccount_XLedger] TO [MssExec]
GO
Uses