
[dbo].[ClaimsBATBuildSettlementClearingAccount_XLedger]
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 @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
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
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 )
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