Stored Procedures [dbo].[UpdateCustomerCreditInfo]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inCustomerNumbervarchar(15)15
@inCreditLimitmoney8
@inAccountingCustomerCreditLimitTypeIdint4
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
*    Updates the customer credit limit info for a specific customer number.  This is used by the
*    AR Credit and Collections module.  This won't get called by XLedger systems as we don't push
*    accounting customer updates INTO XLedger.  Thus, we only update non-XLedger systems.
*/

CREATE procedure [dbo].[UpdateCustomerCreditInfo]
    @inCustomerNumber varchar(15),
    @inCreditLimit money,
    @inAccountingCustomerCreditLimitTypeId int
as
begin
    set nocount on

    declare @theErrorMessage varchar(max)
    set xact_abort on
    begin try
        declare @theAccountingSystemType varchar(2) = dbo.GetAccountingSystemType()

        -- XLedger needs to be updated via XLedger system, which then passes the changes down to
        -- MoversSuite via web-hooks.  We don't push customer updates INTO XLedger.  This SP will
        -- not be invoked if XLedger is the accounting system.
        if( @theAccountingSystemType != 'XL' )
        begin
            update RM00101 set
                CRLMTAMT = isnull( @inCreditLimit, 0.0 ),
                -- GP doesn't support nulls, so let's never insert a null.
                CRLMTTYP = coalesce( AccountingCustomerCreditLimitType.GPCreditLimitTypeCode,
                    NoCreditCreditLimitType.GPCreditLimitTypeCode, 0 )
            from RM00101_Synonym as RM00101
            left outer join AccountingCustomerCreditLimitType on AccountingCustomerCreditLimitType.AccountingCustomerCreditLimitTypeId = @inAccountingCustomerCreditLimitTypeId
            left outer join AccountingCustomerCreditLimitType as NoCreditCreditLimitType on NoCreditCreditLimitType.TypeName = 'No Credit'
            where RM00101.CUSTNMBR = @inCustomerNumber

            -- Update GPWarehouse customer info as well.
            update GPCustomer set
                CreditLimit = isnull( @inCreditLimit, 0.0 ),
                CreditLimitType = coalesce( AccountingCustomerCreditLimitType.GPCreditLimitTypeCode,
                    NoCreditCreditLimitType.GPCreditLimitTypeCode, 0 ),
                AccountingCustomerCreditLimitTypeFid = isnull( AccountingCustomerCreditLimitType.AccountingCustomerCreditLimitTypeId,
                    NoCreditCreditLimitType.AccountingCustomerCreditLimitTypeId )
            from GPCustomer
            left outer join AccountingCustomerCreditLimitType on AccountingCustomerCreditLimitType.AccountingCustomerCreditLimitTypeId = @inAccountingCustomerCreditLimitTypeId
            left outer join AccountingCustomerCreditLimitType as NoCreditCreditLimitType on NoCreditCreditLimitType.TypeName = 'No Credit'
            where GPCustomer.CustomerNumber = @inCustomerNumber
        end
    end try
    begin catch
        set @theErrorMessage = concat( 'There was a problem running UpdateCustomerCreditInfo. ',
            'Error: ', ltrim( str( error_number() ) ), ' ', error_message(), ' ',
            'Line(', ltrim( str( error_line() ) ), ')' )

        raiserror ( @theErrorMessage, 16, 1 )
    end catch
end
GO
GRANT EXECUTE ON  [dbo].[UpdateCustomerCreditInfo] TO [MssExec]
GO
Uses