Hi,
I did try few more ways and one way works but it does not put matching shipment receipt number which I need. If I put that MultiLineShip proc, it gves me the same error. Below is the code which works with out having matching shipment receipt number which I need though. Thought this may help you.
Code: I have commented MultiLineShip proc lines in below code.
ALTER proc [dbo].[uspPerceptive_CreatePOInvoice_Test2]
@ErrorMsg VARCHAR(500) = NULL output
As
-- Select * from dynamics..taErrorCode where ErrorCode in (233)
-- Exec uspPerceptive_CreatePOInvoice_Test2
Set nocount on
Declare @SBACompany varchar(10),
@SBACompanyProc varchar(10),
@VendorId varchar(15),
@PONumber varchar(25),
@ProcName varchar(500),
@VendorName varchar(64),
@ErrOut varchar(1000),
@ErrState int,
@DocDate datetime,
@Amount decimal(19,2),
@ErrDesc varchar(500),
@GLAccount varchar(25),
@GLAccountNumber varchar(25),
@BatchName varchar(25),
@DocNum varchar(25),
@CURNCYID varchar(15),
@Description varchar(30),
@SQL NVARCHAR(777),
@server_name VARCHAR(100),
@PopEnterMatchInvHdrProcName varchar(50),
@PopEnterMatchInvLineProcName varchar(50),
@PopDistributionProcName varchar(50),
@PopEnterMatchInvToShipMultiLineProcName varchar(50),
@FreightAmount money,
@MiscChargeAmount money,
@GSTAmount money,
@PSTAmount money,
@HSTAmount money,
@TaxAmount money,
@POLineNumber int,
@POItemNumber varchar(50),
@POItemDesc varchar(101),
@LineQty int,
@LineUOM varchar(10),
@LineUnitPrice money,
@LineExtendedAmount money,
@POPRCTNM varchar(50),
@POPRCTSHPRCTNM varchar(50),
@RowNum Int
SELECT
@SBACompany = SBACompany,
@server_name = Case When SBACompany = 'SBANS' then 'GPDEV6'
When SBACompany NOT IN ('SBANS','CATOW') then ''
When SBACompany = 'CATOW' then 'FL1GPTEST2' END
FROM [FL1VPERCDB1QA].[PerceptiveImport].[dbo].[AP_PO] with (nolock)
Where PerceptiveNum = 'p05'
--Run the following scripts against the company database to determine the next receipt number.
Set @SQL = ('SELECT @POPRCTNM = POPRCTNM FROM ' + @server_name +'.'+ rtrim(@SBACompany) + '.dbo.POP40100')
exec sp_executesql @SQL, N'@POPRCTNM nchar(100) output', @POPRCTNM output
Select @PopEnterMatchInvHdrProcName = @server_name+'.'+rtrim(@SBACompany)+'.dbo.taPopEnterMatchInvHdr'
Select @PopEnterMatchInvLineProcName = @server_name+'.'+rtrim(@SBACompany)+'.dbo.taPopEnterMatchInvLine'
Select @PopDistributionProcName = @server_name+'.'+rtrim(@SBACompany)+'.dbo.taPopDistribution'
Select @PopEnterMatchInvToShipMultiLineProcName = @server_name+'.'+rtrim(@SBACompany)+'.dbo.taPopEnterMatchInvToShpMultiLine'
BEGIN TRANSACTION
Declare item cursor READ_ONLY for
SELECT PO.[SBACompany]
,[VendorId]
,PO.[PONumber]
,[CurrencyId]
,[POLineNumber]
,[POItemNumber]
,[POItemDesc]
,[LineQty]
,[LineUOM]
,[LineUnitPrice]
,[LineExtendedAmount]
FROM [FL1VPERCDB1QA].[PerceptiveImport].[dbo].[AP_PO] PO with (nolock)
Left JOIN [FL1VPERCDB1QA].[PerceptiveImport].[dbo].[AP_PO_Line] PL with (nolock) ON PO.SBACompany = PL.SBACompany and PO.PONumber = PL.PONumber
Where PO.PerceptiveNum = 'p05'
Order By PO.[SBACompany],PO.PONumber
Open item
Fetch item into
@SBACompany
,@VendorId
,@PONumber
,@CURNCYID
,@POLineNumber
,@POItemNumber
,@POItemDesc
,@LineQty
,@LineUOM
,@LineUnitPrice
,@LineExtendedAmount
WHILE @@fetch_status = 0
BEGIN
Print 'Begin Process'
--Run the following scripts against the company database to get Shipment Receipt Number
Set @SQL = ('Select @POPRCTSHPRCTNM = POPRCTNM From ' + rtrim(@SBACompany) + '.dbo.POP10500 Where PONUMBER =' + '''' + rtrim(@PONumber) + ''' and ITEMNMBR =' + '''' + rtrim(@POItemNumber) + '''')
exec sp_executesql @SQL, N'@POPRCTSHPRCTNM nchar(100) output', @POPRCTSHPRCTNM output
Select @POPRCTNM as ReceiptNumber,@POPRCTSHPRCTNM as ReceiptShipmentNumber,@POItemNumber as POItemNumber
--Print @SQL
exec @PopEnterMatchInvLineProcName
@I_vPOPRCTNM = @POPRCTNM
--,@I_vPOPMtchShpRcpt = @POPRCTSHPRCTNM
--,@I_vShipRCPTLNNM = 16384
,@I_vPONUMBER = @PONumber
,@I_vITEMNMBR = @POItemNumber
,@I_vVENDORID = @VendorId
,@I_vVNDITNUM = @POItemNumber
,@I_vVNDITDSC = @POItemDesc
--,@I_vUOFM = @LineUOM
,@I_vUNITCOST = @LineUnitPrice
,@I_vEXTDCOST = @LineExtendedAmount
--,@I_vAUTOCOST = 1
--,@I_vEXTDCOST = 0
,@I_vQTYINVCD = @LineQty
--,@I_vPOLNENUM = @POLineNumber
--,@I_vCURNCYID = @CURNCYID
,@I_vNONINVEN = 1
,@O_iErrorState=@ErrState output
,@oErrString=@ErrOut output
If @ErrOut <> ''
Begin
print 'Error with Match Invoice Line....'
PRINT('Proc Params:')
--PRINT('PerceptiveNum:' +@RowNum)
PRINT('SBACorp:' +@SBACompany)
PRINT('I_vPOPRCTNM=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTNM),'NULL'))
PRINT('I_vPONUMBER=' +COALESCE(CONVERT(VARCHAR(200),@PONumber),'NULL'))
PRINT('I_vITEMNMBR=' +COALESCE(CONVERT(VARCHAR(200),@POItemNumber),'NULL'))
PRINT('I_vVENDORID=' +COALESCE(CONVERT(VARCHAR(200),@VendorId),'NULL'))
PRINT('I_vVNDITNUM=' +COALESCE(CONVERT(VARCHAR(200),@POItemNumber),'NULL'))
PRINT('I_vVNDITDSC=' +COALESCE(CONVERT(VARCHAR(200),@POItemDesc),'NULL'))
PRINT('I_vUOFM=' +COALESCE(CONVERT(VARCHAR(200),@LineUOM),'NULL'))
PRINT('I_vUNITCOST=' +COALESCE(CONVERT(VARCHAR(200),@LineUnitPrice),'NULL'))
PRINT('I_vEXTDCOST=' +COALESCE(CONVERT(VARCHAR(200),@LineExtendedAmount),'NULL'))
PRINT('I_vPOLNENUM=' +COALESCE(CONVERT(VARCHAR(200),@POLineNumber),'NULL'))
PRINT('I_vCURNCYID=' +COALESCE(CONVERT(VARCHAR(200),@CURNCYID),'NULL'))
print @ErrOut
rollback transaction
goto err
End
Else
Begin
print 'Match Invoice Line Sucessful....'
End
--exec @PopEnterMatchInvToShipMultiLineProcName
-- @I_vPOPRCTNM = @POPRCTNM
-- ,@I_vPOPMtchShpRcpt = @POPRCTSHPRCTNM
-- ,@I_vPONUMBER = @PONumber
-- ,@I_vQTYINVCD = @LineQty
-- ,@I_vITEMNMBR = @POItemNumber
-- ,@I_vShipRCPTLNNM = 16384
-- ,@I_vVENDORID = @VendorId
-- ,@I_vVNDITNUM = @POItemNumber
-- ,@I_vNONINVEN = 1
-- ,@O_iErrorState=@ErrState output
-- ,@oErrString=@ErrOut output
--If @ErrOut <> ''
--Begin
-- print 'Error with Match Invoice Multi Line....'
-- PRINT('Proc Params:')
-- --PRINT('PerceptiveNum:' +@RowNum)
-- PRINT('SBACorp:' +@SBACompany)
-- PRINT('I_vPOPRCTNM=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTNM),'NULL'))
-- PRINT('I_vPOPMtchShpRcpt=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTSHPRCTNM),'NULL'))
-- PRINT('I_vPONUMBER=' +COALESCE(CONVERT(VARCHAR(200),@PONumber),'NULL'))
-- PRINT('I_vQTYINVCD=' +COALESCE(CONVERT(VARCHAR(200),@LineQty),'NULL'))
-- PRINT('I_vITEMNMBR=' +COALESCE(CONVERT(VARCHAR(200),@POItemNumber),'NULL'))
-- PRINT('I_vVENDORID=' +COALESCE(CONVERT(VARCHAR(200),@VendorId),'NULL'))
-- PRINT('I_vVNDITNUM=' +COALESCE(CONVERT(VARCHAR(200),@POItemNumber),'NULL'))
-- print @ErrOut
-- rollback transaction
-- goto err
--End
--Else
--Begin
-- print 'Match Invoice Multi Line Sucessful....'
--End
Fetch item into
@SBACompany
,@VendorId
,@PONumber
,@CURNCYID
,@POLineNumber
,@POItemNumber
,@POItemDesc
,@LineQty
,@LineUOM
,@LineUnitPrice
,@LineExtendedAmount
--COMMIT TRANSACTION
--if @@trancount > 0 Or (@ErrState > 0)
-- ROLLBACK TRANSACTION
End
Close item
Deallocate item
Declare itemheader cursor READ_ONLY for
SELECT PO.[SBACompany]
,[DocNumber]
,[DocDate]
,[VendorId]
,PO.[DocAmount]
,PO.[PONumber]
,[FreightAmount]
,[MiscChargeAmount]
,[TaxAmount]
,[CurrencyId]
,[BatchId]
FROM [FL1VPERCDB1QA].[PerceptiveImport].[dbo].[AP_PO] PO with (nolock)
Where PO.PerceptiveNum = 'p05'
Order By PO.[SBACompany],PO.PONumber
Open itemheader
Fetch itemheader into
@SBACompany
,@DocNum
,@DocDate
,@VendorId
,@Amount
,@PONumber
,@FreightAmount
,@MiscChargeAmount
,@TaxAmount
,@CURNCYID
,@BatchName
WHILE @@fetch_status = 0
BEGIN
exec @PopEnterMatchInvHdrProcName
@I_vPOPRCTNM = @POPRCTNM
,@I_vVNDDOCNM = @DocNum
,@I_vReceiptdate = @DocDate
,@I_vBACHNUMB = @BatchName
,@I_vVENDORID = @VendorId
--,@I_vSUBTOTAL = @Amount
,@I_vSUBTOTAL = 0
,@I_vAUTOCOST = 1
,@I_vFRTAMNT = @FreightAmount
,@I_vMISCAMNT = @MiscChargeAmount
,@I_vTAXAMNT = @TaxAmount
,@I_vCURNCYID = @CURNCYID
,@I_vCreateDist = 0
,@O_iErrorState=@ErrState output
,@oErrString=@ErrOut output
If @ErrOut <> ''
Begin
print 'Error with Match Invoice Header....'
PRINT('Proc Params:')
PRINT('SBACorp:' +@SBACompany)
PRINT('I_vPOPRCTNM=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTNM),'NULL'))
PRINT('I_vVNDDOCNM=' +COALESCE(CONVERT(VARCHAR(200),@DocNum),'NULL'))
PRINT('I_vReceiptdate=' +COALESCE(CONVERT(VARCHAR(200),@DocDate),'NULL'))
PRINT('I_vBACHNUMB=' +COALESCE(CONVERT(VARCHAR(200),@BatchName),'NULL'))
PRINT('I_vVENDORID=' +COALESCE(CONVERT(VARCHAR(200),@VendorId),'NULL'))
PRINT('I_vSUBTOTAL=' +COALESCE(CONVERT(VARCHAR(200),@Amount),'NULL'))
PRINT('I_vFRTAMNT=' +COALESCE(CONVERT(VARCHAR(200),@FreightAmount),'NULL'))
PRINT('I_MISCAMNT=' +COALESCE(CONVERT(VARCHAR(200),@MiscChargeAmount),'NULL'))
PRINT('I_TAXAMNT=' +COALESCE(CONVERT(VARCHAR(200),@TaxAmount),'NULL'))
PRINT('I_vCURNCYID=' +COALESCE(CONVERT(VARCHAR(200),@CURNCYID),'NULL'))
print @ErrOut
rollback transaction
goto err
End
Else
Begin
print 'Match Invoice Header Sucessful....'
End
Exec @PopDistributionProcName
@I_vPOPTYPE = 1
,@I_vPOPRCTNM = @POPRCTNM
,@I_vVENDORID=@VendorId
,@I_vDISTTYPE=9
,@I_vACTNUMST='2020-00000-00'
,@I_vCRDTAMNT=0
,@I_vDEBITAMT=@Amount
,@O_iErrorState=@ErrState output
,@oErrString=@ErrOut output
If @ErrOut <> '' or @@Error<>0
Begin
print 'Error with DEBIT Distribution....'
PRINT('BATCH:' +@BatchName)
PRINT('SBACorp:' +@SBACompany)
PRINT('POPRCTNM=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTNM),'NULL'))
PRINT('VENDORID=' +COALESCE(CONVERT(VARCHAR(200),@VendorId),'NULL'))
PRINT('DEBITAMT=' +COALESCE(CONVERT(VARCHAR(200),@Amount),'NULL'))
print @ErrOut
rollback transaction
goto err
End
Else
Begin
print 'Debit Distribution Sucessful.'
End
Exec @PopDistributionProcName
@I_vPOPTYPE = 1
,@I_vPOPRCTNM = @POPRCTNM
,@I_vVENDORID=@VendorId
,@I_vDISTTYPE=7
,@I_vACTNUMST='2110-00000-00'
,@I_vCRDTAMNT=@Amount
,@I_vDEBITAMT=0
,@O_iErrorState=@ErrState output
,@oErrString=@ErrOut output
If @ErrOut <> '' or @@Error<>0
Begin
print 'Error with Credit Distribution....'
PRINT('BATCH:' +@BatchName)
PRINT('SBACorp:' +@SBACompany)
PRINT('POPRCTNM=' +COALESCE(CONVERT(VARCHAR(200),@POPRCTNM),'NULL'))
PRINT('VENDORID=' +COALESCE(CONVERT(VARCHAR(200),@VendorId),'NULL'))
PRINT('CREDITAMT=' +COALESCE(CONVERT(VARCHAR(200),@Amount),'NULL'))
print @ErrOut
rollback transaction
goto err
End
Else
Begin
print 'Credit Distribution Sucessful.'
End
Fetch itemheader into
@SBACompany
,@DocNum
,@DocDate
,@VendorId
,@Amount
,@PONumber
,@FreightAmount
,@MiscChargeAmount
,@TaxAmount
,@CURNCYID
,@BatchName
End
Close itemheader
Deallocate itemheader
COMMIT TRANSACTION
err:
IF (@ErrState > 0)
Begin
print 'Error: ' + rtrim(@ErrOut)
Set @ErrorMsg = (Select top 1 'Error#: '+isnull(rtrim(@ErrOut),'')+': '+errordesc
From dynamics..taerrorcode where errorcode=isnull(@ErrState,1))
Select @ErrorMsg
Close item
Deallocate item