Stored Procedures [dbo].[ValidateAccountingSystemRequirements_XLedger]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inBatSessionIDvarchar(50)50
@inErrorLoggingSessionIdvarchar(50)50
@inIsStorageProcessingbit1
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
* Don't use this stored proc directly but instead use ValidateAccountingSystemRequirements_Synonym.
* ValidateAccountingSystemRequirements_Synonym will either point to this view or to
* ValidateAccountingSystemRequirements_Legacy otherwise.
*/

CREATE PROCEDURE [dbo].[ValidateAccountingSystemRequirements_XLedger]
    @inBatSessionID varchar(50),
    @inErrorLoggingSessionId varchar(50),
    @inIsStorageProcessing bit = null,
    @outErrorCode int output
as
begin
    set nocount on

    -- Initialize output parameters.
    set @outErrorCode = 0

    -- Local variables
    declare @theStorageRows int
    declare @theCounter int
    declare @theBATProcessPriKeyStr varchar(10)
    declare @theItemCodeStr varchar(10)
    declare @theNominalBranchID varchar(5)
    declare @theNominalBranchFid int
    declare @theNominalBranchObjectValueXLedgerDbId bigint
    declare @theOpposingBranchID varchar(5)
    declare @theOpposingBranchFid int
    declare @theOpposingBranchObjectValueXLedgerDbId bigint
    declare @theNominalXLedgerCompanyXLedgerDbId bigint
    declare @theOpposingXLedgerCompanyXLedgerDbId bigint
    declare @theNominalDivisionFid int
    declare @theNominalDivisionObjectValueXLedgerDbId bigint
    declare @theOpposingDivisionFid int
    declare @theOpposingDivisionObjectValueXLedgerDbId bigint
    declare @theNominalAccountingAccountFid int
    declare @theOpposingAccountingAccountFid int
    declare @theMustHaveAccountingCustomer bit
    declare @theAccountingCustomerFid int
    declare @theXLedgerCustomerXLedgerDbId bigint
    declare @theAccountingCustomerNumber varchar(15)
    declare @theBATProcessCustomerNumber varchar(15)
    declare @theAccountingCustomerHidden bit
    declare @theMustHaveAccountingVendor bit
    declare @theAccountingVendorFid int
    declare @theXLedgerSupplierXLedgerDbId bigint
    declare @theAccountingVendorNumber varchar(15)
    declare @theBATProcessVendorNumber varchar(15)
    declare @theAccountingVendorHidden bit
    declare @theTransactionType varchar(30)
    declare @theBatErrorCode int

    declare @theNominalBranchCanPost bit
    declare @theNominalBranchHidden bit
    declare @theOpposingBranchCanPost bit
    declare @theOpposingBranchHidden bit
    declare @theNominalAccountingAccountCanPost bit
    declare @theNominalAccountingAccountHidden bit
    declare @theNominalAccountingAccountCode nvarchar(32)
    declare @theOpposingAccountingAccountCanPost bit
    declare @theOpposingAccountingAccountHidden bit
    declare @theOpposingAccountingAccountCode nvarchar(32)

    declare @theSourceTable varchar(50)
    declare @theSourceRecordId int
    declare @theObjectTable varchar(20) = 'Order'
    declare @theOrderId int
    declare @theUnknownItem varchar(5) = '???'

    -- Reportable errors
    declare @MSS_BRANCH_NOT_SET_ON_BATPROCESS_RECORD int = 1530
    declare @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_BRANCH_OBJECT_VALUE int = 1531
    declare @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_COMPANY_OBJECT_VALUE int = 1532
    declare @MSS_ITEM_CODE_NOT_MAPPED_TO_AN_XLEDGER_GL_ACCOUNT int = 1533
    declare @MSS_CUSTOMER_NOT_MAPPED_TO_AN_XLEDGER_CUSTOMER int = 1534
    declare @MSS_VENDOR_NOT_MAPPED_TO_AN_XLEDGER_SUPPLIER int = 1535
    declare @MSS_BRANCH_MARKED_AS_CANNOT_POST_IN_XLEDGER int = 1536
    declare @MSS_BRANCH_MARKED_AS_HIDDEN_IN_XLEDGER int = 1537
    declare @MSS_GL_ACCOUNT_MARKED_AS_CANNOT_POST_IN_XLEDGER int = 1538
    declare @MSS_GL_ACCOUNT_MARKED_AS_HIDDEN_IN_XLEDGER int = 1539
    declare @MSS_CUSTOMER_MARKED_AS_HIDDEN_IN_XLEDGER int = 1540
    declare @MSS_VENDOR_MARKED_AS_HIDDEN_IN_XLEDGER int = 1541
    declare @MSS_CUSTOMER_NOT_PROVIDED_WHEN_ITS_REQUIRED int = 1542
    declare @MSS_VENDOR_NOT_PROVIDED_WHEN_ITS_REQUIRED int = 1543

    -- Temp table to hold the transactions about to be processed into AcctTransactions table.
    declare @thePrePostingTable table
    (
        PrePostingTableId int not null identity(1,1),
        -- Links to BATProcess.BATProcessPriKey from which we get all the data we need.
        BATProcessPriKey int not null,
        -- Links to AcctTransactions.BranchID
        -- Nominal (revenue or expense) points to the GLNumber's Branch's identifier in xledger.
        NominalBranchID varchar(5),
        NominalBranchObjectValueXLedgerDbId bigint,
        NominalBranchCanPost bit,
        NominalBranchHidden bit,
        -- Opposing points to the OpposingGLNumber's Branch foreign key.  If this is AR, this is the ARBranch.
        OpposingBranchID varchar(5),
        OpposingBranchObjectValueXLedgerDbId bigint,
        OpposingBranchCanPost bit,
        OpposingBranchHidden bit,

        -- Nominal points to the Branch's Company's external dbid.
        NominalXLedgerCompanyXLedgerDbId bigint,
        -- Opposing points to the OpposingBranch's Company's external dbid.
        OpposingXLedgerCompanyXLedgerDbId bigint,

        --XLTD:  We're thinking that we should use the XLedger DbIds here instead of foreign keys to our "internal table"
        -- Only systems with divisions have non-null values for these two fields.
        -- Nominal points to the Division's external dbid.
        --NominalDivisionObjectValueXLedgerDbId bigint,
        -- Opposing points to the OpposingDivision's external dbid.  If this is AR, this is the ARDivision.
        --OpposingDivisionObjectValueXLedgerDbId bigint,

        -- Nominal points to the GLNumber's AccountingAccount foreign key.
        NominalAccountingAccountCanPost bit,
        NominalAccountingAccountHidden bit,
        NominalAccountingAccountCode nvarchar(32),
        -- Opposing points to the OpposingGLNumber's AccountingAccount foreign key.
        OpposingAccountingAccountCanPost bit,
        OpposingAccountingAccountHidden bit,
        OpposingAccountingAccountCode nvarchar(32),

        -- Not all transactions have a customer (like journal entry or a payable to a vendor)
        AccountingCustomerFid int,
        XLedgerCustomerXLedgerDbId bigint,
        AccountingCustomerNumber varchar(15),
        AccountingCustomerHidden bit,
        -- Not all transactions have a vendor (like journal entry or a receivable from a customer)
        AccountingVendorFid int,
        XLedgerSupplierXLedgerDbId bigint,
        AccountingVendorNumber varchar(15),
        AccountingVendorHidden bit
    )

    insert into @thePrePostingTable
    (
        BATProcessPriKey,
        NominalBranchID,
        NominalBranchObjectValueXLedgerDbId,
        NominalBranchCanPost,
        NominalBranchHidden,
        OpposingBranchID,
        OpposingBranchObjectValueXLedgerDbId,
        OpposingBranchCanPost,
        OpposingBranchHidden,
        NominalXLedgerCompanyXLedgerDbId,
        OpposingXLedgerCompanyXLedgerDbId,
        --NominalDivisionObjectValueXLedgerDbId,
        --OpposingDivisionObjectValueXLedgerDbId,
        NominalAccountingAccountCanPost,
        NominalAccountingAccountHidden,
        NominalAccountingAccountCode,
        OpposingAccountingAccountCanPost,
        OpposingAccountingAccountHidden,
        OpposingAccountingAccountCode,
        XLedgerCustomerXLedgerDbId,
        AccountingCustomerNumber,
        AccountingCustomerHidden,
        XLedgerSupplierXLedgerDbId,
        AccountingVendorNumber,
        AccountingVendorHidden
    )
    select
        BATProcessPriKey = BATProcess.BATProcessPriKey,
        NominalBranchID = isnull( NominalBranch.BranchID, @theUnknownItem ),
        NominalBranchObjectValueXLedgerDbId = NominalXLedgerBranchObjectValue.XLedgerDbId,
        NominalBranchCanPost = NominalXLedgerBranchObjectValue.CanPost,
        NominalBranchHidden = NominalXLedgerBranchObjectValue.[Hidden],
        OpposingBranchID = isnull( OpposingBranch.BranchID, @theUnknownItem ),
        OpposingBranchObjectValueXLedgerDbId = OpposingXLedgerBranchObjectValue.XLedgerDbId,
        OpposingBranchCanPost = OpposingXLedgerBranchObjectValue.CanPost,
        OpposingBranchHidden = OpposingXLedgerBranchObjectValue.[Hidden],
        NominalXLedgerCompanyXLedgerDbId = NominalXLedgerCompany.XLedgerDbId,
        OpposingXLedgerCompanyXLedgerDbId = OpposingXLedgerCompany.XLedgerDbId,
        --NominalDivisionObjectValueXLedgerDbId,
        --OpposingDivisionObjectValueXLedgerDbId,
        NominalAccountingAccountCanPost = NominalAccountingAccount.CanPost,
        NominalAccountingAccountHidden = NominalAccountingAccount.[Hidden],
        NominalAccountingAccountCode = NominalAccountingAccount.Code,
        OpposingAccountingAccountCanPost = OpposingAccountingAccount.CanPost,
        OpposingAccountingAccountHidden = OpposingAccountingAccount.[Hidden],
        OpposingAccountingAccountCode = OpposingAccountingAccount.Code,
        XLedgerCustomerXLedgerDbId = XLedgerCustomer.ExternalDbId,
        AccountingCustomerNumber = AccountingCustomer.CustomerNumber,
        AccountingCustomerHidden = AccountingCustomer.[Hidden],
        XLedgerSupplierXLedgerDbId = XLedgerSupplier.ExternalDbId,
        AccountingVendorNumber = AccountingVendor.VendorNumber,
        AccountingVendorHidden = AccountingVendor.[Hidden]
    from BATProcess
    left outer join Branch as NominalBranch on NominalBranch.BranchPriKey = BATProcess.NominalBranchFid
    left outer join XLedgerBranchObjectValue as NominalXLedgerBranchObjectValue on
        NominalXLedgerBranchObjectValue.BranchFid = BATProcess.NominalBranchFid
    left outer join XLedgerCompany as NominalXLedgerCompany on
        NominalXLedgerCompany.XLedgerCompanyId = NominalXLedgerBranchObjectValue.XLedgerCompanyFid
    left outer join Branch as OpposingBranch on OpposingBranch.BranchPriKey = BATProcess.OpposingBranchFid
    left outer join XLedgerBranchObjectValue as OpposingXLedgerBranchObjectValue on
        OpposingXLedgerBranchObjectValue.BranchFid = BATProcess.OpposingBranchFid
    left outer join XLedgerCompany as OpposingXLedgerCompany on
        OpposingXLedgerCompany.XLedgerCompanyId = OpposingXLedgerBranchObjectValue.XLedgerCompanyFid
    left outer join AccountingAccount as NominalAccountingAccount on NominalAccountingAccount.AccountingAccountId = BATProcess.NominalAccountingAccountFid
    left outer join AccountingAccount as OpposingAccountingAccount on OpposingAccountingAccount.AccountingAccountId = BATProcess.OpposingAccountingAccountFid
    left outer join XLedgerCustomer on XLedgerCustomer.AccountingCustomerFid = BATProcess.AccountingCustomerFid
    left outer join AccountingCustomer on AccountingCustomer.AccountingCustomerId = BATProcess.AccountingCustomerFid
    left outer join XLedgerSupplier on XLedgerSupplier.AccountingVendorFid = BATProcess.AccountingVendorFid
    left outer join AccountingVendor on AccountingVendor.AccountingVendorId = BATProcess.AccountingVendorFid
    where BATProcess.BATSessionID = @inBatSessionID
    order by BATProcess.BATProcessPriKey

    set @theStorageRows = @@rowcount
    set @theCounter = 1

    while( @theCounter <= @theStorageRows )
    begin
        select
            @theBATProcessPriKeyStr = convert( varchar(10), PrePostingTable.BATProcessPriKey ),
            @theOrderId = BATProcess.OrdPriKey,
            @theItemCodeStr = convert( varchar(10), BATProcess.ItemCode ),
            @theSourceTable = BATProcess.[Source],
            @theSourceRecordId = BATProcess.SourceRecord,
            @theNominalBranchID = PrePostingTable.NominalBranchID,
            @theNominalBranchFid = BATProcess.NominalBranchFid,
            @theNominalBranchObjectValueXLedgerDbId = PrePostingTable.NominalBranchObjectValueXLedgerDbId,
            @theNominalBranchCanPost = PrePostingTable.NominalBranchCanPost,
            @theNominalBranchHidden = PrePostingTable.NominalBranchHidden,
            @theOpposingBranchID = PrePostingTable.OpposingBranchID,
            @theOpposingBranchFid = BATProcess.OpposingBranchFid,
            @theOpposingBranchObjectValueXLedgerDbId = PrePostingTable.OpposingBranchObjectValueXLedgerDbId,
            @theOpposingBranchCanPost = PrePostingTable.OpposingBranchCanPost,
            @theOpposingBranchHidden = PrePostingTable.OpposingBranchHidden,
            @theNominalXLedgerCompanyXLedgerDbId = PrePostingTable.NominalXLedgerCompanyXLedgerDbId,
            @theOpposingXLedgerCompanyXLedgerDbId = PrePostingTable.OpposingXLedgerCompanyXLedgerDbId,
            --@theNominalDivisionFid = BATProcess.NominalDivisionFid,
            --@theNominalDivisionObjectValueXLedgerDbId = PrePostingTable.NominalDivisionObjectValueXLedgerDbId,
            --@theOpposingDivisionFid = BATProcess.OpposingDivisionFid,
            --@theOpposingDivisionObjectValueXLedgerDbId = PrePostingTable.OpposingDivisionObjectValueXLedgerDbId,
            @theNominalAccountingAccountFid = BATProcess.NominalAccountingAccountFid,
            @theNominalAccountingAccountCanPost = PrePostingTable.NominalAccountingAccountCanPost,
            @theNominalAccountingAccountHidden = PrePostingTable.NominalAccountingAccountHidden,
            @theNominalAccountingAccountCode = PrePostingTable.NominalAccountingAccountCode,
            @theOpposingAccountingAccountFid = BATProcess.OpposingAccountingAccountFid,
            @theOpposingAccountingAccountCanPost = PrePostingTable.OpposingAccountingAccountCanPost,
            @theOpposingAccountingAccountHidden = PrePostingTable.OpposingAccountingAccountHidden,
            @theOpposingAccountingAccountCode = PrePostingTable.OpposingAccountingAccountCode,
            @theMustHaveAccountingCustomer = case
                when BATProcess.TransactionType like 'A/R%' then 1
                else 0
            end,
            @theAccountingCustomerFid = BATProcess.AccountingCustomerFid,
            @theBATProcessCustomerNumber = isnull( BATProcess.CustomerNumber, @theUnknownItem ),
            @theXLedgerCustomerXLedgerDbId = PrePostingTable.XLedgerCustomerXLedgerDbId,
            @theAccountingCustomerNumber = PrePostingTable.AccountingCustomerNumber,
            @theAccountingCustomerHidden = PrePostingTable.AccountingCustomerHidden,
            @theMustHaveAccountingVendor = case
                when BATProcess.TransactionType like 'A/P%' then 1
                else 0
            end,
            @theAccountingVendorFid = BATProcess.AccountingVendorFid,
            @theBATProcessVendorNumber = isnull( BATProcess.VendorNumber, @theUnknownItem ),
            @theXLedgerSupplierXLedgerDbId = PrePostingTable.XLedgerSupplierXLedgerDbId,
            @theAccountingVendorNumber = PrePostingTable.AccountingVendorNumber,
            @theAccountingVendorHidden = PrePostingTable.AccountingVendorHidden,
            @theTransactionType = BATProcess.TransactionType
        from @thePrePostingTable as PrePostingTable
        inner join BATProcess on BATProcess.BATProcessPriKey = PrePostingTable.BATProcessPriKey
        where PrePostingTableId = @theCounter

        if( isnull( @theNominalBranchID, @theUnknownItem ) = @theUnknownItem )
        begin
            -- This error indicates that the appropriate Branch prikey is not being copied to the
            -- BATProcess record from say the BillingMinorItem record.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_BRANCH_NOT_SET_ON_BATPROCESS_RECORD,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = 'Nominal',
                @inParam2 = @theBATProcessPriKeyStr

            set @outErrorCode = 1
        end
        else if( @theNominalBranchObjectValueXLedgerDbId is null )
        begin
            -- This error indicates a user branch mapping error or XLedger setup error.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_BRANCH_OBJECT_VALUE,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = @theNominalBranchID,
                @inParam2 = @theBATProcessPriKeyStr

            set @outErrorCode = 1
        end

        if( isnull( @theOpposingBranchID, @theUnknownItem ) = @theUnknownItem )
        begin
            -- This error indicates that the appropriate AR Branch prikey is not being copied to the
            -- BATProcess record from say the BillingMinorItem record.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_BRANCH_NOT_SET_ON_BATPROCESS_RECORD,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = 'Opposing',
                @inParam2 = @theBATProcessPriKeyStr

            set @outErrorCode = 1
        end
        else if( @theOpposingBranchObjectValueXLedgerDbId is null )
        begin
            -- This error indicates a user branch mapping error or XLedger setup error.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_BRANCH_OBJECT_VALUE,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = @theOpposingBranchID,
                @inParam2 = @theBATProcessPriKeyStr

            set @outErrorCode = 1
        end

        if( @theNominalBranchObjectValueXLedgerDbId is not null )
        begin
            if( @theNominalXLedgerCompanyXLedgerDbId is null )
            begin
                -- This error indicates a user company mapping error or XLedger setup error.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_COMPANY_OBJECT_VALUE,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theNominalBranchID

                set @outErrorCode = 1
            end

            if( isnull( @theNominalBranchCanPost, 0 ) = 0 )
            begin
                -- This error indicates XLedger considers this branch unavailable for posting and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_MARKED_AS_CANNOT_POST_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theNominalBranchID

                set @outErrorCode = 1
            end

            if( isnull( @theNominalBranchHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this branch as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theNominalBranchID

                set @outErrorCode = 1
            end
        end

        if( @theOpposingBranchObjectValueXLedgerDbId is not null )
        begin
            if( @theOpposingXLedgerCompanyXLedgerDbId is null )
            begin
                -- This error indicates a user company mapping error or XLedger setup error.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_NOT_MAPPED_TO_AN_XLEDGER_COMPANY_OBJECT_VALUE,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theOpposingBranchID

                set @outErrorCode = 1
            end

            if( isnull( @theOpposingBranchCanPost, 0 ) = 0 )
            begin
                -- This error indicates XLedger considers this branch unavailable for posting and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_MARKED_AS_CANNOT_POST_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theOpposingBranchID

                set @outErrorCode = 1
            end

            if( isnull( @theOpposingBranchHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this branch as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_BRANCH_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theOpposingBranchID

                set @outErrorCode = 1
            end
        end

        if( @theNominalAccountingAccountFid is null )
        begin
            -- This error indicates a user item code mapping error or XLedger setup error.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_ITEM_CODE_NOT_MAPPED_TO_AN_XLEDGER_GL_ACCOUNT,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = @theItemCodeStr

            set @outErrorCode = 1
        end
        else
        begin
            if( isnull( @theNominalAccountingAccountCanPost, 0 ) = 0 )
            begin
                -- This error indicates XLedger considers this GL account unavailable for posting and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_GL_ACCOUNT_MARKED_AS_CANNOT_POST_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theNominalAccountingAccountCode

                set @outErrorCode = 1
            end

            if( isnull( @theNominalAccountingAccountHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this GL account as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_GL_ACCOUNT_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theNominalAccountingAccountCode

                set @outErrorCode = 1
            end
        end

        if( @theOpposingAccountingAccountFid is null )
        begin
            -- This error indicates a user item code mapping error or XLedger setup error.
            exec @theBatErrorCode = spRecordBatOrStorageError
                @inIsStorageProcessing = @inIsStorageProcessing,
                @inErrorCodeID = @MSS_ITEM_CODE_NOT_MAPPED_TO_AN_XLEDGER_GL_ACCOUNT,
                @inOrderID = @theOrderId,
                @inSessionID = @inErrorLoggingSessionId,
                @inSourceTable = @theSourceTable,
                @inSourceID = @theSourceRecordId,
                @inObjectTable = @theObjectTable,
                @inObjectID = @theOrderId,
                @inParam1 = @theItemCodeStr

            set @outErrorCode = 1
        end
        else
        begin
            if( isnull( @theOpposingAccountingAccountCanPost, 0 ) = 0 )
            begin
                -- This error indicates XLedger considers this GL account unavailable for posting and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_GL_ACCOUNT_MARKED_AS_CANNOT_POST_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theOpposingAccountingAccountCode

                set @outErrorCode = 1
            end

            if( isnull( @theOpposingAccountingAccountHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this GL account as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_GL_ACCOUNT_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theOpposingAccountingAccountCode

                set @outErrorCode = 1
            end
        end

        if( @theMustHaveAccountingCustomer = 1 )
        begin
            if( @theAccountingCustomerFid is null )
            begin
                -- This error is some MoversSuite error where the customer didn't make it to BATProcess.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_CUSTOMER_NOT_PROVIDED_WHEN_ITS_REQUIRED,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theTransactionType,
                    @inParam2 = @theBATProcessCustomerNumber

                set @outErrorCode = 1
            end
            else if( @theXLedgerCustomerXLedgerDbId is null )
            begin
                -- This error indicates a user customer mapping error or XLedger setup error.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_CUSTOMER_NOT_MAPPED_TO_AN_XLEDGER_CUSTOMER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theAccountingCustomerNumber

                set @outErrorCode = 1
            end

            if( isnull( @theAccountingCustomerHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this customer as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_CUSTOMER_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theAccountingCustomerNumber

                set @outErrorCode = 1
            end
        end

        if( @theMustHaveAccountingVendor = 1 )
        begin
            if( @theAccountingVendorFid is null )
            begin
                -- This error is some MoversSuite error where the vendor didn't make it to BATProcess.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_VENDOR_NOT_PROVIDED_WHEN_ITS_REQUIRED,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theTransactionType,
                    @inParam2 = @theBATProcessVendorNumber

                set @outErrorCode = 1
            end
            else if( @theXLedgerSupplierXLedgerDbId is null )
            begin
                -- This error indicates a user vendor mapping error or XLedger setup error.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_VENDOR_NOT_MAPPED_TO_AN_XLEDGER_SUPPLIER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theAccountingVendorNumber

                set @outErrorCode = 1
            end

            if( isnull( @theAccountingVendorHidden, 1 ) = 1 )
            begin
                -- This error indicates XLedger considers this vendor/supplier as hidden and is therefore unusable.
                exec @theBatErrorCode = spRecordBatOrStorageError
                    @inIsStorageProcessing = @inIsStorageProcessing,
                    @inErrorCodeID = @MSS_VENDOR_MARKED_AS_HIDDEN_IN_XLEDGER,
                    @inOrderID = @theOrderId,
                    @inSessionID = @inErrorLoggingSessionId,
                    @inSourceTable = @theSourceTable,
                    @inSourceID = @theSourceRecordId,
                    @inObjectTable = @theObjectTable,
                    @inObjectID = @theOrderId,
                    @inParam1 = @theAccountingVendorNumber

                set @outErrorCode = 1
            end
        end

        set @theCounter = @theCounter + 1
    end
end
GO
GRANT EXECUTE ON  [dbo].[ValidateAccountingSystemRequirements_XLedger] TO [MssExec]
GO
Uses