
[dbo].[ClaimsBATBuildSettlementClearingAccount_Legacy]
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 @outGLNumber = ' '
set @outErrorResult = 0
set @outAccountingAccountId = null
declare @SETTLEMENT_CLEARING_ACCOUNT_DOES_NOT_EXIST int
set @SETTLEMENT_CLEARING_ACCOUNT_DOES_NOT_EXIST = 5001
declare @theErrorCode int
declare @theMainAccount varchar(16)
declare @theSubAccount varchar(16)
set @theMainAccount = ''
set @theSubAccount = ''
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
select
@theMainAccount = ClaimSettlementClearingAccount.GLAccount,
@theSubAccount = ClaimSettlementClearingAccount.GLSubAccount
from ClaimSettlementClearingAccount
where ClaimSettlementClearingAccount.IsGLDefault = 1
end
if( @theMainAccount = '' )
begin
declare @theBranchID varchar(5)
set @theBranchID = ( select BranchID from Branch where BranchPriKey = @inBranchID )
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 ( 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