When I create the book-in based on the ShipmentID it pulls in all the lines from the shipment. No issues there except in my file, I may only have a small selection of the possible lines, so maybe the shipment has 50 lines, my bookin might only need to show 10.
Fortunately I'm provided the original ShipmentLineID in the file, so to populate the quantity I'm matching the ShipmentLineID and the file-provided ID so I can correctly set the bookin line quantity.
My problem is that the quantity is only getting set on the last line in my file. All the preceding lines are showing the quantity as 0.
I just can't work out where the syntax is wrong so I think another pair of eyes might spot it.
Here's my code - it's in VB because the standard File Watcher plugin is in VB.
- Code: Select all
Private Sub CSVBookInImport(ByVal FileName As String)
'SAMPLE CSV INPUT FILE
'=======================================================================
'ShipmentNo,PONumber,PartNo,QtyReceived,SubQty,SerialNo,ExpiryDate,LINEID
'I01679S,PO0029064,DAYS-203B,20,20,,,A927C46898E347448837
'I01679S,PO0029064,DAYS-203B,100,100,,,AA086DB2D75340FC80EC
'I01679S,PO0029524,HLC-751-300005,16,16,,,7111DB3C0F76488E9605
'I01679S,PO0028477,HLC-751-300005,11,11,,,FC7688847B6A4558934A
'I01679S,PO0029064,HLC-751-300005,1,1,,,0B7BBAE15BE94E82A776
'I01679S,PO0028477,SHH-521APL002,22,22,,,BDAF0B2108DA4533B4C8
'I01679S,PO0029524,SHH-521APL002,24,24,,,0ACEB78D74C14421AEBD
'I01679S,PO0029524,SHH-845PL001,14,14,,,7B70EA33EADE48118E61
'=======================================================================
SyncLock JiwaFinancials.Jiwa.JiwaApplication.Manager.CriticalSectionFlag
Dim bookIn As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.BookIn = _plugin.Manager.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.BookIn)(Nothing)
Using csvParser As New FileIO.TextFieldParser(FileName)
csvParser.TextFieldType = FileIO.FieldType.Delimited
csvParser.Delimiters = New String() {","}
csvParser.HasFieldsEnclosedInQuotes = False
Dim csvFields As String()
Dim previousOrderNo As String = Nothing
csvFields = csvParser.ReadFields 'Move past the first row
Do While Not csvParser.EndOfData
csvFields = csvParser.ReadFields
If Not previousOrderNo Is Nothing AndAlso csvFields(0) <> previousOrderNo Then
' The shipment No. has changed - save the current bookin
bookIn.Save()
CSVBookinWatcher.LogToEventLog(String.Format("Imported book-in for shipment. '{0}' ", csvFields(0)), System.Diagnostics.EventLogEntryType.SuccessAudit)
End If
' Create a new book-in
'Find the shipment ID
bookIn.CreateNew(GetShipmentID(csvFields(0), bookIn.Manager))
For Each mybookInLine As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.Line In bookIn.Lines
CSVBookinWatcher.LogToEventLog(String.Format("ShipmentLineID '{0}'. FileID '{1}' ",mybookInLine.ShipmentLine.RecID, csvFields(7)), System.Diagnostics.EventLogEntryType.SuccessAudit)
If mybookInLine.ShipmentLine.RecID = csvFields(7) Then
mybookInLine.Quantity = csvFields(3)
End If
Next
Loop
If bookIn.Lines.Count > 0 Then
For Each mybookInLine As JiwaFinancials.Jiwa.JiwaLandedCost.BookIn.Line In bookIn.Lines
If mybookInLine.Quantity = 0 Then
' mybookInLine.Lines.Remove(mybookInLine)
' This works but just remming so I can see whats going on.
End If
Next
bookIn.Save()
CSVBookinWatcher.LogToEventLog(String.Format("Imported Book-in '{0}'. Book In no. '{1}' ", csvFields(0), bookIn.BookInNo), System.Diagnostics.EventLogEntryType.SuccessAudit)
End If
End Using
End SyncLock
End Sub
The specific code block which sets the quantity is the bit that reads
- Code: Select all
If mybookInLine.ShipmentLine.RecID = csvFields(7) Then
mybookInLine.Quantity = csvFields(3)
End If