Imports Microsoft.Dynamics.GP.eConnect.Serialization
Imports FPCommon.Common
Public Class POPReceivingsType
Function POPReceipt(POPRCTNM As String, POPTYPE As Int16, strSQLServer As String, strDatabase As String) As String
'we expect there to be three tables populated:
'DDtaPopRcptLineInsert
'DDtaPopRcptHdrInsert
'The fields in these tables are all NULLABLE. The script to create these tables is located here:
'if you don't populate a field in the table it won't be used. Only populated values are imported.
'this code also makes use of the CDBNull and CNothing Methods, documented here:
'the POPRCTNM and POPTYPE parameters can be used to query the data out of those tables
'set the return value for the function
POPReceipt = ""
'initialize
Dim intLineCount As Int16
Dim strResult As String = ""
Try
'Create eConnect Objects
Dim oeConnectFunctions As New eConnectFunctions(strSQLServer, strDatabase)
Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
Dim oPOPReceivingsType As New Microsoft.Dynamics.GP.eConnect.Serialization.POPReceivingsType
'=======================================================================
'lines
'=======================================================================
'data access code that queries the DDtaPopRcptLineInsert table and returns a DataTable
For Each oRow As DataRow In DAL.SPs.dd_DDtaPopRcptLineInsert_SEL_byID2(POPTYPE, POPRCTNM).getTable.Rows
'create an object to hold the line info
Dim otaPopRcptLineInsert As New Microsoft.Dynamics.GP.eConnect.Serialization.taPopRcptLineInsert_ItemsTaPopRcptLineInsert
'populate the object. If the field in the table is null, then assign the field to itself. Otherwise, assign the value
With otaPopRcptLineInsert
.ACTLSHIP = CDBNull(.ACTLSHIP, oRow("ACTLSHIP"))
.AutoAssignBin = CDBNull(.AutoAssignBin, oRow("AutoAssignBin"))
.AUTOCOST = CDBNull(.AUTOCOST, oRow("AUTOCOST"))
.BOLPRONUMBER = CDBNull(.BOLPRONUMBER, oRow("BOLPRONUMBER"))
.CMMTTEXT = CDBNull(.CMMTTEXT, oRow("CMMTTEXT"))
.CostCatID = CDBNull(.CostCatID, oRow("CostCatID"))
.CURNCYID = CDBNull(.CURNCYID, oRow("CURNCYID"))
.EXTDCOST = CDBNull(.EXTDCOST, oRow("EXTDCOST"))
If Not oRow("EXTDCOST") Is System.DBNull.Value Then
.EXTDCOSTSpecified = True
End If
.InventoryAccount = CDBNull(.InventoryAccount, oRow("InventoryAccount"))
.INVINDX = CDBNull(.INVINDX, oRow("INVINDX"))
.ITEMDESC = CDBNull(.ITEMDESC, oRow("ITEMDESC"))
.ITEMNMBR = CDBNull(.ITEMNMBR, oRow("ITEMNMBR"))
.JOBNUMBR = CDBNull(.JOBNUMBR, oRow("JOBNUMBR"))
.Landed_Cost_Group_ID = CDBNull(.Landed_Cost_Group_ID, oRow("Landed_Cost_Group_ID"))
.LOCNCODE = CDBNull(.LOCNCODE, oRow("LOCNCODE"))
.NONINVEN = CDBNull(.NONINVEN, oRow("NONINVEN"))
.POLNENUM = CDBNull(.POLNENUM, oRow("POLNENUM"))
.PONUMBER = CDBNull(.PONUMBER, oRow("PONUMBER"))
.POPRCTNM = CDBNull(.POPRCTNM, oRow("POPRCTNM"))
.POPTYPE = CDBNull(.POPTYPE, oRow("POPTYPE"))
.ProjNum = CDBNull(.ProjNum, oRow("ProjNum"))
.Purchase_Item_Tax_Schedu = CDBNull(.Purchase_Item_Tax_Schedu, oRow("Purchase_Item_Tax_Schedu"))
.Purchase_IV_Item_Taxable = CDBNull(.Purchase_IV_Item_Taxable, oRow("Purchase_IV_Item_Taxable"))
.Purchase_Site_Tax_Schedu = CDBNull(.Purchase_Site_Tax_Schedu, oRow("Purchase_Site_Tax_Schedu"))
.QTYINVCD = CDBNull(.QTYINVCD, oRow("QTYINVCD"))
.QTYSHPPD = CDBNull(.QTYSHPPD, oRow("QTYSHPPD"))
.RCPTLNNM = CDBNull(.RCPTLNNM, oRow("RCPTLNNM"))
.receiptdate = CDBNull(.receiptdate, oRow("receiptdate"))
.RequesterTrx = CDBNull(.RequesterTrx, oRow("RequesterTrx"))
.TAXAMNT = CDBNull(.TAXAMNT, oRow("TAXAMNT"))
.VENDORID = CDBNull(.VENDORID, oRow("VENDORID"))
.VNDITDSC = CDBNull(.VNDITDSC, oRow("VNDITDSC"))
.VNDITNUM = CDBNull(.VNDITNUM, oRow("VNDITNUM"))
.UNITCOST = CDBNull(.UNITCOST, oRow("UNITCOST"))
If Not oRow("UNITCOST") Is System.DBNull.Value Then
.UNITCOSTSpecified = True
End If
.UOFM = CDBNull(.UOFM, oRow("UOFM"))
.USRDEFND1 = CDBNull(.USRDEFND1, oRow("USRDEFND1"))
.USRDEFND2 = CDBNull(.USRDEFND2, oRow("USRDEFND2"))
.USRDEFND3 = CDBNull(.USRDEFND3, oRow("USRDEFND3"))
.USRDEFND4 = CDBNull(.USRDEFND4, oRow("USRDEFND4"))
.USRDEFND5 = CDBNull(.USRDEFND5, oRow("USRDEFND5"))
'Data access code to delete the line that we just used from DDtaPopRcptLineInsert
SPs.dd_DDtaPopRcptLineInsert_DEL_byID(oRow("RowID")).execute()
'add the line to the POPReceivingsType object
ReDim Preserve oPOPReceivingsType.taPopRcptLineInsert_Items(intLineCount)
oPOPReceivingsType.taPopRcptLineInsert_Items(intLineCount) = otaPopRcptLineInsert
intLineCount += 1
End With
Next
'=======================================================================
'header
'=======================================================================
'create the eConnect header class
Dim otaPopRcptHdrInsert As New Microsoft.Dynamics.GP.eConnect.Serialization.taPopRcptHdrInsert
'Populate a datatable with the information for the header table
Dim oDTHeader As DataTable = SPs.dd_DDtaPopRcptLineInsert_SEL_byID2(POPTYPE, POPRCTNM).getTable
'assign the header data to the eConnect document
With otaPopRcptHdrInsert
'populate the object. If the field in the table is null, then assign the field to itself. Otherwise, assign the value
.POPRCTNM = CNothing(.POPRCTNM, oDTHeader.Rows(0)("POPRCTNM"))
.POPTYPE = CNothing(.POPTYPE, oDTHeader.Rows(0)("POPTYPE"))
.VNDDOCNM = CNothing(.VNDDOCNM, oDTHeader.Rows(0)("VNDDOCNM"))
.receiptdate = CNothing(.receiptdate, oDTHeader.Rows(0)("receiptdate"))
.ACTLSHIP = CNothing(.ACTLSHIP, oDTHeader.Rows(0)("ACTLSHIP"))
.BACHNUMB = CNothing(.BACHNUMB, oDTHeader.Rows(0)("BACHNUMB"))
.VENDORID = CNothing(.VENDORID, oDTHeader.Rows(0)("VENDORID"))
.VENDNAME = CNothing(.VENDNAME, oDTHeader.Rows(0)("VENDNAME"))
.SUBTOTAL = CNothing(.SUBTOTAL, oDTHeader.Rows(0)("SUBTOTAL"))
If Not oDTHeader.Rows(0)("SUBTOTAL") Is System.DBNull.Value Then
.SUBTOTALSpecified = 1
End If
.TRDISAMT = CNothing(.TRDISAMT, oDTHeader.Rows(0)("TRDISAMT"))
If Not oDTHeader.Rows(0)("TRDISAMT") Is System.DBNull.Value Then
.TRDISAMTSpecified = 1
End If
.FRTAMNT = CNothing(.FRTAMNT, oDTHeader.Rows(0)("FRTAMNT"))
.MISCAMNT = CNothing(.MISCAMNT, oDTHeader.Rows(0)("MISCAMNT"))
.TAXAMNT = CNothing(.TAXAMNT, oDTHeader.Rows(0)("TAXAMNT"))
.TEN99AMNT = CNothing(.TEN99AMNT, oDTHeader.Rows(0)("TEN99AMNT"))
.PYMTRMID = CNothing(.PYMTRMID, oDTHeader.Rows(0)("PYMTRMID"))
.DSCPCTAM = CNothing(.DSCPCTAM, oDTHeader.Rows(0)("DSCPCTAM"))
If Not oDTHeader.Rows(0)("DSCPCTAM") Is System.DBNull.Value Then
.DSCPCTAMSpecified = 1
End If
.DSCDLRAM = CNothing(.DSCDLRAM, oDTHeader.Rows(0)("DSCDLRAM"))
If Not oDTHeader.Rows(0)("DSCDLRAM") Is System.DBNull.Value Then
.DSCDLRAMSpecified = 1
End If
.DISAVAMT = CNothing(.DISAVAMT, oDTHeader.Rows(0)("DISAVAMT"))
If Not oDTHeader.Rows(0)("DISAVAMT") Is Nothing Then
.DISAVAMTSpecified = True
End If
.REFRENCE = CNothing(.REFRENCE, oDTHeader.Rows(0)("REFRENCE"))
.USER2ENT = CNothing(.USER2ENT, oDTHeader.Rows(0)("USER2ENT"))
.VCHRNMBR = CNothing(.VCHRNMBR, oDTHeader.Rows(0)("VCHRNMBR"))
.Tax_Date = CNothing(.Tax_Date, oDTHeader.Rows(0)("Tax_Date"))
.TIME1 = CNothing(.TIME1, oDTHeader.Rows(0)("TIME1"))
.WITHHAMT = CNothing(.WITHHAMT, oDTHeader.Rows(0)("WITHHAMT"))
.TXRGNNUM = CNothing(.TXRGNNUM, oDTHeader.Rows(0)("TXRGNNUM"))
.AUTOCOST = CNothing(.AUTOCOST, oDTHeader.Rows(0)("AUTOCOST"))
.TAXSCHID = CNothing(.TAXSCHID, oDTHeader.Rows(0)("TAXSCHID"))
.Purchase_Freight_Taxable = CNothing(.Purchase_Freight_Taxable, oDTHeader.Rows(0)("Purchase_Freight_Taxable"))
.Purchase_Misc_Taxable = CNothing(.Purchase_Misc_Taxable, oDTHeader.Rows(0)("Purchase_Misc_Taxable"))
.FRTSCHID = CNothing(.FRTSCHID, oDTHeader.Rows(0)("FRTSCHID"))
.MSCSCHID = CNothing(.MSCSCHID, oDTHeader.Rows(0)("MSCSCHID"))
.FRTTXAMT = CNothing(.FRTTXAMT, oDTHeader.Rows(0)("FRTTXAMT"))
.MSCTXAMT = CNothing(.MSCTXAMT, oDTHeader.Rows(0)("MSCTXAMT"))
.BCKTXAMT = CNothing(.BCKTXAMT, oDTHeader.Rows(0)("BCKTXAMT"))
.BackoutTradeDiscTax = CNothing(.BackoutTradeDiscTax, oDTHeader.Rows(0)("BackoutTradeDiscTax"))
.SHIPMTHD = CNothing(.SHIPMTHD, oDTHeader.Rows(0)("SHIPMTHD"))
.USINGHEADERLEVELTAXES = CNothing(.USINGHEADERLEVELTAXES, oDTHeader.Rows(0)("USINGHEADERLEVELTAXES"))
.CREATEDIST = CNothing(.CREATEDIST, oDTHeader.Rows(0)("CREATEDIST"))
.CURNCYID = CNothing(.CURNCYID, oDTHeader.Rows(0)("CURNCYID"))
.XCHGRATE = CNothing(.XCHGRATE, oDTHeader.Rows(0)("XCHGRATE"))
.RATETPID = CNothing(.RATETPID, oDTHeader.Rows(0)("RATETPID"))
.EXPNDATE = CNothing(.EXPNDATE, oDTHeader.Rows(0)("EXPNDATE"))
.EXCHDATE = CNothing(.EXCHDATE, oDTHeader.Rows(0)("EXCHDATE"))
.EXGTBDSC = CNothing(.EXGTBDSC, oDTHeader.Rows(0)("EXGTBDSC"))
.EXTBLSRC = CNothing(.EXTBLSRC, oDTHeader.Rows(0)("EXTBLSRC"))
.RATEEXPR = CNothing(.RATEEXPR, oDTHeader.Rows(0)("RATEEXPR"))
.DYSTINCR = CNothing(.DYSTINCR, oDTHeader.Rows(0)("DYSTINCR"))
.RATEVARC = CNothing(.RATEVARC, oDTHeader.Rows(0)("RATEVARC"))
.TRXDTDEF = CNothing(.TRXDTDEF, oDTHeader.Rows(0)("TRXDTDEF"))
.RTCLCMTD = CNothing(.RTCLCMTD, oDTHeader.Rows(0)("RTCLCMTD"))
.PRVDSLMT = CNothing(.PRVDSLMT, oDTHeader.Rows(0)("PRVDSLMT"))
.DATELMTS = CNothing(.DATELMTS, oDTHeader.Rows(0)("DATELMTS"))
.DUEDATE = CNothing(.DUEDATE, oDTHeader.Rows(0)("DUEDATE"))
.DISCDATE = CNothing(.DISCDATE, oDTHeader.Rows(0)("DISCDATE"))
.NOTETEXT = CNothing(.NOTETEXT, oDTHeader.Rows(0)("NOTETEXT"))
.VADCDTRO = CNothing(.VADCDTRO, oDTHeader.Rows(0)("VADCDTRO"))
.CASHAMNT = CNothing(.CASHAMNT, oDTHeader.Rows(0)("CASHAMNT"))
.CAMCBKID = CNothing(.CAMCBKID, oDTHeader.Rows(0)("CAMCBKID"))
.CDOCNMBR = CNothing(.CDOCNMBR, oDTHeader.Rows(0)("CDOCNMBR"))
.CAMTDATE = CNothing(.CAMTDATE, oDTHeader.Rows(0)("CAMTDATE"))
.CAMPMTNM = CNothing(.CAMPMTNM, oDTHeader.Rows(0)("CAMPMTNM"))
.CHEKAMNT = CNothing(.CHEKAMNT, oDTHeader.Rows(0)("CHEKAMNT"))
.CHAMCBID = CNothing(.CHAMCBID, oDTHeader.Rows(0)("CHAMCBID"))
.CHEKNMBR = CNothing(.CHEKNMBR, oDTHeader.Rows(0)("CHEKNMBR"))
.CHEKDATE = CNothing(.CHEKDATE, oDTHeader.Rows(0)("CHEKDATE"))
.CAMPYNBR = CNothing(.CAMPYNBR, oDTHeader.Rows(0)("CAMPYNBR"))
.CRCRDAMT = CNothing(.CRCRDAMT, oDTHeader.Rows(0)("CRCRDAMT"))
.CARDNAME = CNothing(.CARDNAME, oDTHeader.Rows(0)("CARDNAME"))
.CCRCTNUM = CNothing(.CCRCTNUM, oDTHeader.Rows(0)("CCRCTNUM"))
.CRCARDDT = CNothing(.CRCARDDT, oDTHeader.Rows(0)("CRCARDDT"))
.CCAMPYNM = CNothing(.CCAMPYNM, oDTHeader.Rows(0)("CCAMPYNM"))
.DISTKNAM = CNothing(.DISTKNAM, oDTHeader.Rows(0)("DISTKNAM"))
.RequesterTrx = CNothing(.RequesterTrx, oDTHeader.Rows(0)("RequesterTrx"))
.USRDEFND1 = CNothing(.USRDEFND1, oDTHeader.Rows(0)("USRDEFND1"))
.USRDEFND2 = CNothing(.USRDEFND2, oDTHeader.Rows(0)("USRDEFND2"))
.USRDEFND3 = CNothing(.USRDEFND3, oDTHeader.Rows(0)("USRDEFND3"))
.USRDEFND4 = CNothing(.USRDEFND4, oDTHeader.Rows(0)("USRDEFND4"))
.USRDEFND5 = CNothing(.USRDEFND5, oDTHeader.Rows(0)("USRDEFND5"))
'Data access code to delete the line from the header table
SPs.dd_DDtaPopRcptHdrInsert_DEL_byID2(POPRCTNM, POPTYPE).execute()
End With
'assign the document to the eConnectType
oPOPReceivingsType.taPopRcptHdrInsert = otaPopRcptHdrInsert
ReDim oeConnectType.POPReceivingsType(0)
oeConnectType.POPReceivingsType(0) = oPOPReceivingsType
'send the transaction
strResult = oeConnectFunctions.CreateTransactionEntity(oeConnectType)
Catch ex As Exception
Dim strMessage = ex.Message
Throw New Exception(strMessage)
End Try
Return strResult
End Function
End Class