
[dbo].[XLedgerGetEnqueuedAccountTransactionApplyTos]
CREATE PROCEDURE [dbo].[XLedgerGetEnqueuedAccountTransactionApplyTos]
@queueId int
AS
BEGIN
set nocount on
select
XLedgerJournalEntryBatchItemId = XLedgerJournalEntryBatchItem.XLedgerJournalEntryBatchItemId,
ApplyToJournalEntryBatchItemId = ApplyToAccountTransaction.ApplyToJournalEntryBatchItemId,
Id = AcctTransactionsApplyToInfo.AcctTransactionsApplyToInfoID,
MatchIdentifier = ApplyToAccountTransaction.MatchIdentifier,
Amount = dbo.AcctTransactionsApplyToInfo.ApplyAmount,
AccountExternalDbId = ApplyToAccountTransaction.AccountExternalDbId,
BranchObjectValueExternalDbId = ApplyToAccountTransaction.BranchObjectValueXLedgerDbId,
BranchCompanyExternalDbId = ApplyToAccountTransaction.BranchCompanyExternalDbId,
XLedgerSubledgerExternalDbId = ApplyToAccountTransaction.XLedgerSubledgerExternalDbId,
XglExternalDbId = ApplyToAccountTransaction.XglExternalDbId,
[Description] = ApplyToAccountTransaction.[Description]
from XLedgerJournalEntryBatchQueue
inner join XLedgerJournalEntryBatchItem on
XLedgerJournalEntryBatchQueue.XLedgerJournalEntryBatchFid = XLedgerJournalEntryBatchItem.XLedgerJournalEntryBatchFid
inner join AcctTransactions on XLedgerJournalEntryBatchItem.AcctTransactionFid = AcctTransactions.ATPriKey
inner join AcctTransactionsApplyToInfo on AcctTransactions.ATPriKey = AcctTransactionsApplyToInfo.AcctTransactionsFID
cross apply (
select top 1
MatchIdentifier = XLedgerTransactionHeader.ArApMatchIdentifier,
AccountExternalDbId = XLedgerAccount.ExternalDbId,
BranchObjectValueXLedgerDbId = ApplyToJournalBatchItem.OpposingBranchObjectValueXLedgerDbId,
BranchCompanyExternalDbId = ApplyToJournalBatchItem.OpposingXLedgerCompanyXLedgerDbId,
XLedgerSubledgerExternalDbId = ApplyToJournalBatchItem.XLedgerCustomerXLedgerDbId,
XglExternalDbId = Xgl.XLedgerDbId,
ApplyToJournalEntryBatchItemId = ApplyToJournalBatchItem.XLedgerJournalEntryBatchItemId,
[Description] = AcctTransactions.ItemDescription
from AcctTransactions ApplyToAccountTransaction
inner join dbo.XLedgerJournalEntryBatchItem ApplyToJournalBatchItem on
ApplyToAccountTransaction.ATPriKey = ApplyToJournalBatchItem.AcctTransactionFid
left outer join XLedgerTransactionHeader on
ApplyToJournalBatchItem.XLedgerTransactionHeaderFid = XLedgerTransactionHeader.XLedgerTransactionHeaderId and
XLedgerTransactionHeader.ArApMatchIdentifier is not null
inner join XLedgerAccount on ApplyToJournalBatchItem.OpposingAccountingAccountFid = XLedgerAccount.AccountingAccountFid
inner join Xgl on ApplyToJournalBatchItem.XglFid = Xgl.XglId
where
ApplyToAccountTransaction.DocumentNumber = AcctTransactionsApplyToInfo.ApplyToDocument and
( ApplyToJournalBatchItem.XLedgerJournalEntryBatchFid = XLedgerJournalEntryBatchItem.XLedgerJournalEntryBatchFid or
XLedgerTransactionHeader.ArApMatchIdentifier is not null )
order by ApplyToAccountTransaction.ATPriKey desc
) ApplyToAccountTransaction
where XLedgerJournalEntryBatchQueue.XLedgerJournalEntryBatchQueueId = @queueId
end
GO
GRANT EXECUTE ON [dbo].[XLedgerGetEnqueuedAccountTransactionApplyTos] TO [MssExec]
GO