Stored Procedures [dbo].[GenerateAccountingBatches_XLedger]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inBatchDescriptionnvarchar(64)128
@inBatProcessAccttransctionsMapBATProcessAcctTransactionsmax
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
* Don't use this stored proc directly but instead use GenerateAccountingBatches_Synonym.
* GenerateAccountingBatches_Synonym will either point to this view or to
* GenerateAccountingBatches_Legacy otherwise.
*/

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 our XLedger batch header.
    insert into XLedgerJournalEntryBatch
    (
        [Description]
    )
    select
        [Description] = @inBatchDescription

    set @theXLedgerJournalEntryBatchItemId = scope_identity()

    -- Insert our XLedger batch details.
    -- One detail per AcctTransaction.
    insert into XLedgerJournalEntryBatchItem
    (
        XLedgerJournalEntryBatchFid,
        AcctTransactionFid,
        XglFid,
        NominalXLedgerCompanyXLedgerDbId,
        OpposingXLedgerCompanyXLedgerDbId,
        NominalBranchObjectValueXLedgerDbId,
        OpposingBranchObjectValueXLedgerDbId,
        -- XLTD: These will likely be the appropriate XLedgerDivisionObjectValue.XLedgerDbId
        --NominalDivisionFid,
        --OpposingDivisionFid,
        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,
        --NominalDivisionFid = BATProcess.NominalDivisionFid,
        --OpposingDivisionFid = BATProcess.OpposingDivisionFid,
        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

    -- All done!  Queue this batch up for processing to XLedger.
    -- One queue per XLedgerJournalEntryBatch.
    insert into XLedgerJournalEntryBatchQueue
    (
        XLedgerJournalEntryBatchFid,
        Processed,
        EnqueuedAt
    )
    select
        XLedgerJournalEntryBatchFid = @theXLedgerJournalEntryBatchItemId,
        Processed = 0,
        EnqueuedAt = sysdatetimeoffset()

    -- And lastly tell MssWeb that there is work to be done.
    insert into MssWebEvent( MssWebEventTypeFid )
    select MssWebEventType.MssWebEventTypeId
    from MssWebEventType
    where MssWebEventType.EventTypeName = 'XLedgerTransactionUploadRequested'

end
GO
GRANT EXECUTE ON  [dbo].[GenerateAccountingBatches_XLedger] TO [MssExec]
GO
Uses