Skip to Content
0
Former Member
May 22, 2014 at 07:01 AM

Delivery Notes Generation Via Pick List

22 Views

Am trying to generate delivery notes off pick tickets and i can't find any code example. I now came up with the following code but am having issues when items are in multiple Bin Locations.

Public Sub Sales2Delivery() '(ByVal OrderID As String)

Dim OrderID As String = ""

Try

Using connection As New SqlConnection(StaginConn)

'Dim command As New SqlCommand("SELECT DocEntry from ORDR with (nolock) WHERE NumAtCard = '" & OrderID & "'", connection)

Dim command As New SqlCommand("SET DATEFORMAT DMY; select distinct top 5 o.DocEntry, o.NumAtCard from ordr O with (nolock) join RDR1 R with (nolock) on R.DocEntry = O.DocEntry join OPKL P with (nolock) on P.AbsEntry = R.PickIdNo where u_shipstate = 'Delivered' and CAST(O.docdate as date) >= '30/04/2014' and P.Status = 'Y';", connection)

connection.Open()

Dim reader As SqlDataReader = command.ExecuteReader()

' Call Read before accessing data.

While reader.Read()

Dim BusinessOrders As Documents = DirectCast(vCompany.GetBusinessObject(BoObjectTypes.oOrders), Documents)

Dim BusinessDelivery As Documents = DirectCast(vCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes), Documents)

Dim orders As Documents = BusinessOrders

orders.GetByKey(Convert.ToInt32(reader(0)))

OrderID = Convert.ToString(reader(1))

Dim Delivery As Documents = BusinessDelivery

Delivery.CardCode = orders.CardCode

Delivery.CardName = orders.CardName

Delivery.NumAtCard = orders.NumAtCard

'Delivery.DocNum = orders.DocNum

Delivery.HandWritten = BoYesNoEnum.tNO

Delivery.Series = 8

Delivery.DocDate = DateTime.Today

Delivery.DocDueDate = DateTime.Today

Delivery.TaxDate = DateTime.Today

Delivery.Address = orders.Address

Delivery.Address2 = orders.Address2

Delivery.Comments = "Based on Sales Order #" + orders.NumAtCard & "."

Delivery.DocCurrency = orders.DocCurrency

Delivery.DocDueDate = orders.DocDueDate

Delivery.DocObjectCode = SAPbobsCOM.BoObjectTypes.oDeliveryNotes

Delivery.ShipToCode = orders.ShipToCode

Dim lines As Document_Lines = orders.Lines

'If (count > 0) Then

' lines.Add()

' lines.SetCurrentLine((lines.Count - 1))

'End If

Dim oPickList As PickLists = DirectCast(vCompany.GetBusinessObject(BoObjectTypes.oPickLists), PickLists)

oPickList.GetByKey(orders.Lines.PickListIdNumber)

For i As Int32 = 0 To (lines.Count - 1)

If i > 0 Then

Delivery.Lines.Add()

Delivery.Lines.SetCurrentLine(i)

End If

' Set the Current Lines on the order

orders.Lines.SetCurrentLine(i)

Try

oPickList.Lines.SetCurrentLine(i)

Delivery.Lines.BaseEntry = oPickList.Lines.OrderEntry

Delivery.Lines.BaseLine = oPickList.Lines.OrderRowID

Delivery.Lines.Quantity = oPickList.Lines.PickedQuantity

Delivery.Lines.BaseType = DirectCast(SAPbobsCOM.BoObjectTypes.oOrders, Integer)

Delivery.Lines.BinAllocations.BinAbsEntry = oPickList.Lines.BinAllocations.BinAbsEntry

Dim rs As SAPbobsCOM.Recordset = vCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

rs.DoQuery("select itemcode, price, dscription from RDR1 R where R.LineNum = " & oPickList.Lines.OrderRowID & " and R.PickIdNo = " & oPickList.Lines.AbsoluteEntry)

While (rs.EoF <> True)

Delivery.Lines.ItemCode = rs.Fields.Item(0).Value.ToString 'orders.Lines.ItemCode

Delivery.Lines.UnitPrice = CType(rs.Fields.Item(1).Value.ToString, Double) 'orders.Lines.UnitPrice

Delivery.Lines.ItemDescription = rs.Fields.Item(2).Value.ToString 'orders.Lines.ItemDescription

rs.MoveNext()

End While

rs = Nothing

Catch ex As Exception

Continue For

My.Computer.FileSystem.WriteAllText(_LogPath, ErrDetails.ToString, True)

End Try

Next

If Delivery.Add() <> 0 Then

ErrDetails.AppendLine(" Unable to create Delivery note for Order: " & OrderID & " <br /> " & vCompany.GetLastErrorCode() & ":" & vCompany.GetLastErrorDescription())

Else

ErrDetails.AppendLine("Successfully created Delivery note for Order:" & OrderID) ' & " as requested by " & UserEmail & ".")

End If

orders = Nothing

Delivery = Nothing

BusinessOrders = Nothing

BusinessDelivery = Nothing

My.Computer.FileSystem.WriteAllText(_LogPath, ErrDetails.ToString, True)

End While

'orders = Nothing

'BusinessOrders = Nothing

End Using

Catch ex As Exception

ErrDetails.AppendLine(" Error generating Delivery note for Order: " & OrderID & " <br /> " & ex.ToString())

My.Computer.FileSystem.WriteAllText(_LogPath, ErrDetails.ToString, True)

Finally

If Not String.IsNullOrWhiteSpace(ErrDetails.ToString) Then

My.Computer.FileSystem.WriteAllText(_LogPath, (ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10) & "Errors encountered while registering data on " & System.DateTime.Now.ToString("F") & ".Errors:" & ChrW(13) & ChrW(10) & Me.ErrDetails.ToString), True)

Else

My.Computer.FileSystem.WriteAllText(_LogPath, (ChrW(13) & ChrW(10) & ChrW(13) & ChrW(10) & "Application Ran successfully on " & System.DateTime.Now.ToString("F") & "."), True)

End If

End Try

End Sub

The Error message am getting is 1470000368 - The quantity allocated to bin locations must be positive.