Stored Procedures [dbo].[ValidateAccountingSystemRequirementsForBc]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@inBatSessionIDvarchar(50)50
@inErrorLoggingSessionIdvarchar(50)50
@inIsStorageProcessingbit1
@inObjectTablevarchar(20)20
@inObjectTableIdint4
@outErrorCodeint4Out
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
create procedure [dbo].[ValidateAccountingSystemRequirementsForBc]
    @inBatSessionID varchar(50),
    @inErrorLoggingSessionId varchar(50),
    @inIsStorageProcessing bit = null,
    @inObjectTable varchar(20) = null,
    @inObjectTableId int = null,
    @outErrorCode int output
as
begin
set nocount on
    declare @BRANCH_NOT_MAPPED_TO_A_DIMENSION int = 9600
    declare @DIVISION_NOT_MAPPED_TO_A_DIMENSION int = 9601
    declare @MOVETYPEGROUP_NOT_MAPPED_TO_A_DIMENSION int = 9602


    declare @areDivisionsEnabled bit = dbo.IsDivisionEnabled();

    declare @errors table
    (
        Id int identity( 1, 1 ),
        BATProcessId int not null,
        ErrorCodeId int not null,
        Param1 varchar(128) null
    )

    insert into @errors(
        BATProcessId,
        ErrorCodeId,
        Param1
    )
    select
        BATProcess.BATProcessPriKey,
        Errors.ErrorCodeId,
        Errors.Param1
    from BATProcess
    left outer join Branch as NominalBranch on
        BATProcess.NominalBranchFid = NominalBranch.BranchPriKey
    left outer join BcBranchDimensionValueMap NominalBranchMapping
        on BATProcess.NominalBranchFid = NominalBranchMapping.BranchFid
    left outer join Branch as OpposingBranch on
        BATProcess.OpposingBranchFid = OpposingBranch.BranchPriKey
    left outer join BcBranchDimensionValueMap OpposingBranchMapping
        on BATProcess.OpposingBranchFid = OpposingBranchMapping.BranchFid
    left outer join Division NominalDivision
        on BATProcess.NominalDivisionFid = NominalDivision.DivisionId
    left outer join BcDivisionDimensionValueMap NominalDivisionMapping
        on NominalDivision.DivisionId = NominalDivisionMapping.DivisionFid
    left outer join Division OpposingDivision
        on BATProcess.OpposingDivisionFid = OpposingDivision.DivisionId
    left outer join BcDivisionDimensionValueMap OpposingDivisionMapping
        on OpposingDivision.DivisionId = OpposingDivisionMapping.DivisionFid
    left outer join Orders on BATProcess.OrdPriKey = Orders.PriKey
    left outer join MoveType on Orders.MoveType = MoveType.PriKey
    left outer join MoveTypeGroups on MoveType.MTGroupPriKey = MoveTypeGroups.MTGroupPriKey
    left outer join BcMoveTypeGroupDimensionValueMap on MoveTypeGroups.MTGroupPriKey = BcMoveTypeGroupDimensionValueMap.MoveTypeGroupFid
    cross apply (
        select
            ErrorCodeId = @BRANCH_NOT_MAPPED_TO_A_DIMENSION,
            Param1 = NominalBranch.BranchId
            where NominalBranchMapping.BcBranchDimensionValueMapId is null
        union all select
            ErrorCodeId = @BRANCH_NOT_MAPPED_TO_A_DIMENSION,
            Param1 = OpposingBranch.BranchId
            where OpposingBranchMapping.BcBranchDimensionValueMapId is null
        union all select
            ErrorCodeId = @DIVISION_NOT_MAPPED_TO_A_DIMENSION,
            Param1 = NominalDivision.Number
            where
                1 = @areDivisionsEnabled
                and NominalDivisionMapping.BcDivisionDimensionValueMapId is null
        union all select
            ErrorCodeId = @DIVISION_NOT_MAPPED_TO_A_DIMENSION,
            Param1 = OpposingDivision.Number
            where
                1 = @areDivisionsEnabled
                and OpposingDivisionMapping.BcDivisionDimensionValueMapId is null
        union all select
            ErrorCodeId = @MOVETYPEGROUP_NOT_MAPPED_TO_A_DIMENSION,
            Param1 = MoveTypeGroups.[Description]
        where MoveTypeGroups.MTGroupPriKey is not null and BcMoveTypeGroupDimensionValueMap.BcMoveTypeGroupDimensionValueMapId is null
        --skipping accounts, customer, vendor, and driver/sales mappings for now.  Justifications:
            --GL Account validation is handled earlier in the process when we look them up and add to BAT Process
                --All GL accounts are guaranteed to be mapped to BC since they are imported instead of being data-entered.
            --Customers/Vendors are always mapped when relevant (this proc right now is checking against user error, not bugs)
            --Customers/Vendors are always mapped to BC implicitly, since they are not manually data-entered, and are instead imported from the BC accounting system
            
        --All of the above is subject to change when we find ourselves in a situation where someone is "changing" accounting systems.
    ) as Errors
    where BATProcess.BATSessionID = @inBatSessionID
    order by BATProcess.BATProcessPriKey




    declare @errorTableId int = 1
    declare @errorCode int
    declare @orderId int
    declare @sourceTable varchar(50)
    declare @sourceRecord int
    declare @param1 varchar(128)
    declare @objectTable varchar(20) = case
        when isnull( @inObjectTable, '' ) = '' then 'Order'
        else @inObjectTable
    end

    declare @objectTableId int

    while( 1 = 1 )
    begin
        select top 1
            @errorCode = Errors.ErrorCodeId,
            @orderId = BATProcess.OrdPriKey,
            @sourceTable = BATProcess.[Source],
            @sourceRecord = BATProcess.SourceRecord,
            @objectTableId =
                case
                    when isnull( @inObjectTable, '' ) = '' then BATProcess.OrdPriKey
                    when @inObjectTable = 'Order' then BATProcess.OrdPriKey
                    else @inObjectTableId
                end,
            @param1 = Errors.Param1
        from @errors Errors
        inner join BATProcess on Errors.BATProcessId = BATProcess.BATProcessPriKey
        where Errors.Id = @errorTableId

        if @@rowcount = 0 break;
        set @outErrorCode = 1

        exec spRecordBatOrStorageError
            @inIsStorageProcessing = @inIsStorageProcessing,
            @inErrorCodeID = @errorCode,
            @inOrderID = @orderId,
            @inSessionID = @inErrorLoggingSessionId,
            @inSourceTable = @sourceTable,
            @inSourceID = @sourceRecord,
            @inObjectTable = @objectTable,
            @inObjectID = @objectTableId,
            @inParam1 = @param1


        set @errorTableId = @errorTableId + 1;
    end
end
GO
GRANT EXECUTE ON  [dbo].[ValidateAccountingSystemRequirementsForBc] TO [MssExec]
GO
Uses
Used By