JiwaApplication.Manager.Instance.Logon(JiwaCon.DataSource, JiwaCon.Database, JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, My.Settings.JiwaUserName, My.Settings.JiwaUserPwd)
                Dim stockTransfer As JiwaStockTransfer.StockTransfer = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaStockTransfer.StockTransfer)(Nothing)
                stockTransfer.CreateNew()

                With stockTransfer
                    .LogicalWarehouseResidingIn.IN_LogicalID = Trim(_strLogicalID)
                    .TransferDate = JiwaApplication.Manager.Instance.SysDateTime
                    .Reference = "Stock Adjustment for Sales order " & Trim(_strInvoiceNo) & " & Delivery No 01."
                    Dim i As Integer = 0
                    Dim ToInventoryID As String

                    For Each Row As DataRow In _TransferTable.Rows
                        'i += 1
                        Dim line As New JiwaStockTransfer.Line
                        If CType(Row("Variance"), Double) > 0 Then
                            'Increase Stock
                            ToInventoryID = Row("InventoryID").ToString
                            '.Lines(i).FromInventory.PartNo = "External"
                            '.Lines(i).ToInventory.InventoryID = Trim(ToInventoryID)
                            '.Lines(i).ToPartSerialNo = Trim(Row("SerialNo").ToString)
                            '.Lines(i).TransferQuantity = CType(Row("Variance"), Double)
                            '.Lines(i).ToPartBinLocation = Row("BinNo").ToString

                            line.FromInventory.PartNo = "External"
                            line.ToInventory.InventoryID = Trim(ToInventoryID)
                            line.ToPartSerialNo = Trim(Row("SerialNo").ToString)
                            line.TransferQuantity = CType(Row("Variance"), Double)
                            line.ToPartBinLocation = Row("BinNo").ToString

                            'If IsDBNull(Row("ExpiryDate")) = False Then
                            '    '.Lines(i).ToPartExpiryDate = CType(Row("ExpiryDate"), DateTime)
                            '    line.ToPartExpiryDate = CType(Row("ExpiryDate"), DateTime)
                            'End If
                            line.ToPartExpiryDate = JiwaApplication.Manager.Instance.SysDateTime

                            If CType(Row("CostIn"), Double) <> 0 Then
                                '.Lines(i).ToInventory.LCost = CType(Row("CostIn"), Double)
                                line.ToInventory.LCost = CType(Row("CostIn"), Double)
                            End If
                            '.Lines(i).Reference = "DBR Stock Adjustment for Sales order " & Trim(_strInvoiceNo) & " & Delivery No 01."
                            line.Reference = "Stock Adjustment for Sales order " & Trim(_strInvoiceNo) & " & Delivery No 01."
                            .Lines.Add(line)
                        End If
                        'i += 1
                        line.Clear()
                        line = Nothing
                    Next

                    .Save()

                    TransferNo = .TransferNo.ToString
                   
                    If _AutoActivate = True Then
                        .ActivateRecord()
                    End If

                    .Clear()
                    .CleanUp()
                End With