
[dbo].[GenerateAccountingBatches_XLedger]
CREATE PROCEDURE [dbo].[GenerateAccountingBatches_XLedger]
@inBatchDescription nvarchar(64),
@inBatProcessAccttransctionsMap BATProcessAcctTransactions readonly,
@outErrorCode int output
as
begin
set nocount on
declare @theXLedgerJournalEntryBatchItemId int
set @outErrorCode = 0
insert into XLedgerJournalEntryBatch
(
[Description]
)
select
[Description] = @inBatchDescription
set @theXLedgerJournalEntryBatchItemId = scope_identity()
insert into XLedgerJournalEntryBatchItem
(
XLedgerJournalEntryBatchFid,
AcctTransactionFid,
XglFid,
NominalXLedgerCompanyXLedgerDbId,
OpposingXLedgerCompanyXLedgerDbId,
NominalBranchObjectValueXLedgerDbId,
OpposingBranchObjectValueXLedgerDbId,
NominalAccountingAccountFid,
OpposingAccountingAccountFid,
XLedgerCustomerXLedgerDbId,
XLedgerSupplierXLedgerDbId
)
select
XLedgerJournalEntryBatchFid = @theXLedgerJournalEntryBatchItemId,
AcctTransactionFid = BATProcessAcctTransactionMap.AcctTransactionsID,
XglFid = BATProcess.XglFid,
NominalXLedgerCompanyXLedgerDbId = NominalXLedgerCompany.XLedgerDbId,
OpposingXLedgerCompanyXLedgerDbId = OpposingXLedgerCompany.XLedgerDbId,
NominalBranchObjectValueXLedgerDbId = NominalXLedgerBranchObjectValue.XLedgerDbId,
OpposingBranchObjectValueXLedgerDbId = OpposingXLedgerBranchObjectValue.XLedgerDbId,
NominalAccountingAccountFid = BATProcess.NominalAccountingAccountFid,
OpposingAccountingAccountFid = BATProcess.OpposingAccountingAccountFid,
XLedgerCustomerXLedgerDbId = XLedgerCustomer.ExternalDbId,
XLedgerSupplierXLedgerDbId = XLedgerSupplier.ExternalDbId
from @inBatProcessAccttransctionsMap as BATProcessAcctTransactionMap
inner join BATProcess on BATProcess.BATProcessPriKey = BATProcessAcctTransactionMap.BATProcessID
inner join XLedgerBranchObjectValue as NominalXLedgerBranchObjectValue on
NominalXLedgerBranchObjectValue.BranchFid = BATProcess.NominalBranchFid
inner join XLedgerCompany as NominalXLedgerCompany on
NominalXLedgerCompany.XLedgerCompanyId = NominalXLedgerBranchObjectValue.XLedgerCompanyFid
inner join XLedgerBranchObjectValue as OpposingXLedgerBranchObjectValue on
OpposingXLedgerBranchObjectValue.BranchFid = BATProcess.OpposingBranchFid
inner join XLedgerCompany as OpposingXLedgerCompany on
OpposingXLedgerCompany.XLedgerCompanyId = OpposingXLedgerBranchObjectValue.XLedgerCompanyFid
left outer join XLedgerCustomer on XLedgerCustomer.AccountingCustomerFid = BATProcess.AccountingCustomerFid
left outer join XLedgerSupplier on XLedgerSupplier.AccountingVendorFid = BATProcess.AccountingVendorFid
insert into XLedgerJournalEntryBatchQueue
(
XLedgerJournalEntryBatchFid,
Processed,
EnqueuedAt
)
select
XLedgerJournalEntryBatchFid = @theXLedgerJournalEntryBatchItemId,
Processed = 0,
EnqueuedAt = sysdatetimeoffset()
insert into MssWebEvent( MssWebEventTypeFid )
select MssWebEventType.MssWebEventTypeId
from MssWebEventType
where MssWebEventType.EventTypeName = 'XLedgerTransactionUploadRequested'
end
GO
GRANT EXECUTE ON [dbo].[GenerateAccountingBatches_XLedger] TO [MssExec]
GO