
[dbo].[UpdateCustomerCreditInfo]
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()
if( @theAccountingSystemType != 'XL' )
begin
update RM00101 set
CRLMTAMT = isnull( @inCreditLimit, 0.0 ),
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 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