Private Sub Export_Orders()
'// Export the Orders into Accpac order entry.
Dim i As Integer, j As Integer
Dim l_intLine As Integer, l_strID As String
Dim l_strCustomer As String, l_strCategory As String
Dim l_strPriceList As String, l_strLocation As String
Dim OEORDheader As ACCPACXAPILib.xapiView
Dim OEORDdetail1 As ACCPACXAPILib.xapiView
Dim OEORDdetail2 As ACCPACXAPILib.xapiView
Dim OEORDdetail3 As ACCPACXAPILib.xapiView
Dim OEORDdetail4 As ACCPACXAPILib.xapiView
Dim OEORDdetail5 As ACCPACXAPILib.xapiView
Dim OEORDdetail6 As ACCPACXAPILib.xapiView
Dim OEORDdetail7 As ACCPACXAPILib.xapiView
Dim OEORDdetail8 As ACCPACXAPILib.xapiView
Dim OEORDdetail9 As ACCPACXAPILib.xapiView
Dim OEORDdetail10 As ACCPACXAPILib.xapiView
On Error GoTo ERR_Handler
'// Set the views.
Set OEORDheader = ngjSess.OpenView("OE0520", "OE")
Set OEORDdetail1 = ngjSess.OpenView("OE0500", "OE")
Set OEORDdetail2 = ngjSess.OpenView("OE0740", "OE")
Set OEORDdetail3 = ngjSess.OpenView("OE0180", "OE")
Set OEORDdetail4 = ngjSess.OpenView("OE0680", "OE")
If AP_ModuleVersion("OE") = "53A" Then
Set OEORDdetail5 = ngjSess.OpenView("OE0526", "OE")
Set OEORDdetail6 = ngjSess.OpenView("OE0522", "OE")
Set OEORDdetail7 = ngjSess.OpenView("OE0501", "OE")
Set OEORDdetail8 = ngjSess.OpenView("OE0502", "OE")
Set OEORDdetail9 = ngjSess.OpenView("OE0504", "OE")
Set OEORDdetail10 = ngjSess.OpenView("OE0503", "OE")
End If
'// Compose the views.
If AP_ModuleVersion("OE") = "53A" Then
OEORDheader.Compose Array(OEORDdetail1, OEORDdetail4, OEORDdetail3, OEORDdetail2, OEORDdetail5, OEORDdetail6)
OEORDdetail1.Compose Array(OEORDheader, OEORDdetail7, OEORDdetail10, OEORDdetail8)
OEORDdetail2.Compose Array(OEORDheader)
OEORDdetail3.Compose Array(OEORDheader, OEORDdetail1)
OEORDdetail4.Compose Array(OEORDheader, OEORDdetail1)
OEORDdetail5.Compose Array(OEORDheader)
OEORDdetail6.Compose Array(OEORDheader)
OEORDdetail7.Compose Array(OEORDdetail1)
OEORDdetail8.Compose Array(OEORDdetail1, OEORDdetail9)
OEORDdetail9.Compose Array(OEORDdetail8)
OEORDdetail10.Compose Array(OEORDdetail1)
Else
OEORDheader.Compose Array(OEORDdetail1, OEORDdetail4, OEORDdetail3, OEORDdetail2, Nothing, Nothing, Nothing, Nothing, Nothing)
OEORDdetail1.Compose Array(OEORDheader, Nothing)
OEORDdetail2.Compose Array(OEORDheader, Nothing)
OEORDdetail3.Compose Array(OEORDheader, Nothing, OEORDdetail1)
OEORDdetail4.Compose Array(OEORDheader, Nothing, OEORDdetail1)
End If
'// Send info to the user interface.
Send_Message "Beginning Import of Orders to ACCPAC."
LogEvent eLogStatus, "Beginning Import of Orders to ACCPAC."
stbMain.Panels(1).Text = "Importing Orders..."
Send_Progress 0, UBound(m_udtOrder) + 1
DoEvents
'// Get user defined default values
l_strCustomer = Trim$(GetSetting("NGJ", "Export", "Customer", ""))
l_strCategory = Trim$(GetSetting("NGJ", "Export", "Category", ""))
l_strPriceList = Trim$(GetSetting("NGJ", "Export", "PriceList", ""))
l_strLocation = Trim$(GetSetting("NGJ", "Export", "Location", ""))
'// Start the looping of orders.
For i = 0 To UBound(m_udtOrder)
'// Set up the header information.
stbMain.Panels(1).Text = "Exporting Orders... Order # " & m_udtOrder(i).OrderID
With m_udtOrder(i)
If AP_ModuleVersion("OE") = "53A" Then '// Sub to check module version.
OEORDheader.RecordClear
OEORDheader.RecordGenerate False
Else
OEORDheader.Init
End If
OEORDheader.Fields("CUSTOMER").value = l_strCustomer
OEORDheader.Fields("BILNAME").value = Trim$(.bFirst & " " & .bLast)
OEORDheader.Fields("BILADDR1").value = Trim$(.bAddr1)
OEORDheader.Fields("BILADDR2").value = Trim$(.bAddr2)
OEORDheader.Fields("BILCITY").value = Trim$(.bCity)
OEORDheader.Fields("BILSTATE").value = Trim$(.bState)
OEORDheader.Fields("BILZIP").value = Trim$(.bPostal)
OEORDheader.Fields("BILCOUNTRY").value = Trim$(.bCountry)
OEORDheader.Fields("BILPHONE").value = Trim$(.bPhone)
OEORDheader.Fields("BILEMAIL").value = Trim$(.bEmail)
OEORDheader.Fields("SHPNAME").value = Trim$(.sFirst & " " & .sLast)
OEORDheader.Fields("SHPADDR1").value = Trim$(.sAddr1)
OEORDheader.Fields("SHPADDR2").value = Trim$(.sAddr2)
OEORDheader.Fields("SHPCITY").value = Trim$(.sCity)
OEORDheader.Fields("SHPSTATE").value = Trim$(.sState)
OEORDheader.Fields("SHPZIP").value = Trim$(.sPostal)
OEORDheader.Fields("SHPCOUNTRY").value = Trim$(.sCountry)
OEORDheader.Fields("TYPE").value = "1"
OEORDheader.Fields("ORDDATE").value = .OrDate
OEORDheader.Fields("LOCATION").value = l_strLocation
OEORDheader.Fields("COMMENT").value = Trim$(.Notes)
OEORDheader.Fields("RECALCTAX").value = "1"
OEORDheader.Fields("GOCALCTAX").value = "1"
OEORDheader.Fields("POSTINV").value = "0"
OEORDheader.Update
OEORDheader.Process
OEORDheader.Read
l_strID = OEORDheader.Fields("ORDUNIQ").value
End With
'// Detail Item information.
If AP_ModuleVersion("OE") = "53A" Then
l_intLine = -1 '// Set the first line number for 5.3.
Else
l_intLine = 0 '// All other versions.
End If
For j = 0 To UBound(m_udtDetail, 2)
With m_udtDetail(i, j)
If Trim$(.Name) <> "" Then
If AP_ModuleVersion("OE") = "53A" Then
OEORDdetail1.RecordClear
OEORDdetail1.RecordGenerate False
Else
OEORDdetail1.Init
End If
OEORDdetail1.Fields("ORDUNIQ").value = l_strID
OEORDdetail1.Fields("LINENUM").PutWithoutVerification (Str(l_intLine))
OEORDdetail1.Fields("LINETYPE").value = 1
OEORDdetail1.Fields("ITEM").value = "A11000" '.Model
OEORDdetail1.Fields("DESC").value = .Name
OEORDdetail1.Fields("PRICELIST").value = l_strPriceList
OEORDdetail1.Fields("CATEGORY").value = l_strCategory
OEORDdetail1.Fields("LOCATION").value = l_strLocation
OEORDdetail1.Fields("QTYORDERED").value = .Quantity
OEORDdetail1.Fields("PRICEOVER").value = 1
OEORDdetail1.Fields("UNITPRICE").value = .Price
OEORDdetail1.Fields("PRIUNTPRC").value = .Price
OEORDdetail1.Insert
OEORDdetail1.Fields("DESC").value = .Name
OEORDdetail1.Update
l_intLine = l_intLine - 1
End If
End With
Next j
'// Insert the header.
OEORDheader.Insert
Send_Progress i + 1, UBound(m_udtOrder) + 1
NextOrder:
'// Cancel the views.
OEORDdetail1.Cancel
OEORDheader.Cancel
Next i '// Number of Orders.
'// Destroy the views.
Set OEORDheader = Nothing
Set OEORDdetail1 = Nothing
Set OEORDdetail2 = Nothing
Set OEORDdetail3 = Nothing
Set OEORDdetail4 = Nothing
Set OEORDdetail5 = Nothing
Set OEORDdetail6 = Nothing
Set OEORDdetail7 = Nothing
Set OEORDdetail8 = Nothing
Set OEORDdetail9 = Nothing
Set OEORDdetail10 = Nothing
If m_intFailure = 0 Then
Send_Image False, 1
Else
Send_Image True, 1
End If
Exit Sub
ERR_Handler:
Dim Errors As xapiErrors
Dim Error As Variant
Set Errors = ngjSess.Errors
If Errors.count = 0 Then
'// Errormessenger is an error handling sub.
ErrorMessenger Err.Number, Err.Description, "frmMain.Export_Orders"
Else
For Each Error In Errors
If Error.Priority = 1 Or Error.Priority = 2 Then
Send_Message "Warning on Export Order # " & m_udtOrder(i).OrderID & "."
LogEvent eLogStatus, "WARNING: On Export Order# " & m_udtOrder(i).OrderID & ". " & Error.Priority & ": " & Error.Description & "."
Send_Warning
Send_Progress i + 1, UBound(m_udtOrder) + 1
Else
Send_Message "Failure on Export Order # " & m_udtOrder(i).OrderID & "."
LogEvent eLogStatus, "FAILURE: On Export Order # " & m_udtOrder(i).OrderID & ". " & Error.Priority & ": " & Error.Description & _
". Date: " & m_udtOrder(i).OrDate & " Customer: " & m_udtOrder(i).bFirst & " " & m_udtOrder(i).bLast & "."
Send_Failure
Send_Progress i + 1, UBound(m_udtOrder) + 1
End If
MsgBox Error.Priority & ": " & Error.Description '// for testing only.
Resume Next '// for testing only.
Next
Errors.Clear
End If
Set Errors = Nothing
Resume NextOrder
End Sub
Public Function AP_ModuleVersion(pMod As String) As String
'// Returns the version of ACCPAC module being used.
Dim myApps As ACCPACXAPILib.xapiActiveApplications
Dim oneApp As ACCPACXAPILib.xapiApplication
On Error GoTo ERR_Handler
Set myApps = ngjSess.ActiveApplications
For Each oneApp In myApps
If oneApp.PgmID = Trim$(pMod) Then
AP_ModuleVersion = oneApp.PgmVer
Exit For
End If
Next
Set myApps = Nothing
Set oneApp = Nothing
Exit Function
ERR_Handler:
'// ErrorACCPAC is an Accpac error handling sub.
ErrorACCPAC Err.Number, Err.Description, "modGeneral.AP_ModuleVersion"
End Function