
[dbo].[UpdateCommissionOnHoldStatus_Legacy]
create procedure [dbo].[UpdateCommissionOnHoldStatus_Legacy]
(
@inOrderID int,
@inCommissionedDetailIds varchar(max),
@inSplitCommissionsIds varchar(max),
@inRemoveHold bit,
@inHoldUpdateDescription varchar(30),
@inSysUserId int,
@outErrorCode int output
)
as
set nocount on
declare @theNewHoldStatus nchar(1)
declare @theOldHoldStatus nchar(1)
declare @theGpBranchPriKey int
declare @theCommissionedDetailCount int
declare @theSplitCommissionsCount int
declare @theGPUpdateCount int
declare @theTempGPUpdateCount int
declare @theCurrentUtcDateTime datetime
declare @theGPDB_PM10000 sysname
declare @theGPDB_PM20000 sysname
declare @theParamList nvarchar(128)
declare @theRowCountSql nvarchar(128)
declare @theSQL nvarchar(4000)
declare @theCommissionsTable AcctTransactionsSourceType
declare @NO_GP_ACCOUNTING_SYSTEM int
declare @GP_BRANCH_SETUP_INCOMPLETE int
declare @REMOVE_HOLD_PARAMETER_IS_NULL int
declare @SOME_GP_ITEMS_ALREADY_ON_HOLD int
declare @SOME_GP_ITEMS_ALREADY_OFF_HOLD int
select
@outErrorCode = 0,
@NO_GP_ACCOUNTING_SYSTEM = 2300,
@GP_BRANCH_SETUP_INCOMPLETE = 2301,
@REMOVE_HOLD_PARAMETER_IS_NULL = 2302,
@SOME_GP_ITEMS_ALREADY_ON_HOLD = 2303,
@SOME_GP_ITEMS_ALREADY_OFF_HOLD = 2304,
@theCommissionedDetailCount = 0,
@theSplitCommissionsCount = 0,
@theGPUpdateCount = 0,
@theTempGPUpdateCount = 0,
@theCurrentUtcDateTime = getutcdate(),
@theGpBranchPriKey = ( select top 1 BranchPriKey from Branch where GLCPriKey is not null ),
@theOldHoldStatus = case
when @inRemoveHold = 1 then N'1'
else N'0'
end,
@theNewHoldStatus = case
when @inRemoveHold = 1 then N'0'
else N'1'
end
declare @theAccountingSystemType varchar(2) = dbo.GetAccountingSystemType()
if( @theAccountingSystemType = 'GP' )
begin
if( @theGpBranchPriKey is null )
begin
set @outErrorCode = @GP_BRANCH_SETUP_INCOMPLETE
end
else if( @inRemoveHold is null )
begin
set @outErrorCode = @REMOVE_HOLD_PARAMETER_IS_NULL
end
else
begin
if( len( isnull( @inCommissionedDetailIds, '' ) ) > 0 )
begin
insert into @theCommissionsTable ( OkToUpdate, Source, SourceRecord )
select
OkToUpdate = 0,
Source = 'CommissionedDetail',
SourceRecord = Item
from dbo.ParseMultiValuedParameter( @inCommissionedDetailIds, ',' )
set @theCommissionedDetailCount = @@rowcount
end
if( len( isnull( @inSplitCommissionsIds, '' ) ) > 0 )
begin
insert into @theCommissionsTable ( OkToUpdate, Source, SourceRecord )
select
OkToUpdate = 0,
Source = 'SplitCommissions',
SourceRecord = Item
from dbo.ParseMultiValuedParameter( @inSplitCommissionsIds, ',' )
set @theSplitCommissionsCount = @@rowcount
end
if( @theCommissionedDetailCount + @theSplitCommissionsCount > 0 )
begin
update @theCommissionsTable set
OkToUpdate = 1,
VendorNumber = AcctTransactions.VendorNumber,
VoucherNumber = AcctTransactions.VoucherNumber
from @theCommissionsTable as theCommissionsTable
inner join AcctTransactions on AcctTransactions.Source = theCommissionsTable.Source and
AcctTransactions.SourceRecord = theCommissionsTable.SourceRecord
where AcctTransactions.OrdPriKey = @inOrderID
set @theGPDB_PM20000 = 'PM20000'
set @theGPDB_PM20000 = dbo.udfGetGPDB( @theGpBranchPriKey, @theGPDB_PM20000 )
set @theGPDB_PM10000 = 'PM10000'
set @theGPDB_PM10000 = dbo.udfGetGPDB( @theGpBranchPriKey, @theGPDB_PM10000 )
set @theParamList = N'@theCommissionsTable [dbo].[AcctTransactionsSourceType] readonly, @theTempGPUpdateCount int output'
set @theRowCountSql = N' set @theTempGPUpdateCount = @@rowcount'
set @theSQL = N'update ' + @theGPDB_PM20000 + ' set ' +
'HOLD = ' + @theNewHoldStatus + ' ' +
'from @theCommissionsTable as theCommissionsTable ' +
'inner join ' + @theGPDB_PM20000 + ' as PM20000 on PM20000.VendorID = theCommissionsTable.VendorNumber and ' +
'PM20000.VCHRNMBR = theCommissionsTable.VoucherNumber ' +
'where theCommissionsTable.OkToUpdate = 1 and ' +
'PM20000.HOLD = ' + @theOldHoldStatus +
@theRowCountSql
exec sp_executesql
@stmt = @theSQL,
@params = @theParamList,
@theCommissionsTable = @theCommissionsTable,
@theTempGPUpdateCount = @theTempGPUpdateCount output
set @theGPUpdateCount = @theTempGPUpdateCount
set @theSQL = N'update ' + @theGPDB_PM10000 + ' set ' +
'SIMPLIFD = ' + @theNewHoldStatus + ' ' +
'from @theCommissionsTable as theCommissionsTable ' +
'inner join ' + @theGPDB_PM10000 + ' as PM10000 on PM10000.VendorID = theCommissionsTable.VendorNumber and ' +
'PM10000.VCHRNMBR = theCommissionsTable.VoucherNumber ' +
'where theCommissionsTable.OkToUpdate = 1 and ' +
'PM10000.SIMPLIFD = ' + @theOldHoldStatus +
@theRowCountSql
exec sp_executesql
@stmt = @theSQL,
@params = @theParamList,
@theCommissionsTable = @theCommissionsTable,
@theTempGPUpdateCount = @theTempGPUpdateCount output
set @theGPUpdateCount = @theGPUpdateCount + @theTempGPUpdateCount
if( @theCommissionedDetailCount > 0 )
begin
insert into CommissionedDetailHold
(
CommissionedDetailFID,
SysUserFID,
ChangedOn,
HoldUpdateStatus,
HoldUpdateDescription
)
select
CommissionedDetailFID = CommissionedDetail.CDPriKey,
SysUserFID = @inSysUserId,
ChangedOn = @theCurrentUtcDateTime,
HoldUpdateStatus = case
when @inRemoveHold = 1 then 0
else 1
end,
HoldUpdateDescription = @inHoldUpdateDescription
from @theCommissionsTable as theCommissionsTable
inner join CommissionedDetail on theCommissionsTable.SourceRecord = CommissionedDetail.CDPriKey
inner join SysUser on SysUser.SysUserID = @inSysUserId
where theCommissionsTable.Source = 'CommissionedDetail' and
theCommissionsTable.OkToUpdate = 1
end
if( @theSplitCommissionsCount > 0 )
begin
insert into SplitCommissionsHold
(
SplitCommissionsFID,
SysUserFID,
ChangedOn,
HoldUpdateStatus,
HoldUpdateDescription
)
select
SplitCommissionsFID = SplitCommissions.SCPriKey,
SysUserFID = @inSysUserId,
ChangedOn = @theCurrentUtcDateTime,
HoldUpdateStatus = case
when @inRemoveHold = 1 then 0
else 1
end,
HoldUpdateDescription = @inHoldUpdateDescription
from @theCommissionsTable as theCommissionsTable
inner join SplitCommissions on theCommissionsTable.SourceRecord = SplitCommissions.SCPriKey
inner join SysUser on SysUser.SysUserID = @inSysUserId
where theCommissionsTable.Source = 'SplitCommissions' and
theCommissionsTable.OkToUpdate = 1
end
if( @theCommissionedDetailCount + @theSplitCommissionsCount != @theGPUpdateCount )
begin
set @outErrorCode = case @inRemoveHold
when 1 then @SOME_GP_ITEMS_ALREADY_OFF_HOLD
else @SOME_GP_ITEMS_ALREADY_ON_HOLD
end
end
end
end
end
GO
GRANT EXECUTE ON [dbo].[UpdateCommissionOnHoldStatus_Legacy] TO [MssExec]
GO