Ok, as promised - below is a scheduled script which processes backorders for sales orders.
Which backorders to process is decided by calling the stored procedure configured in the system to list all backorders (by default it is "usp_JIWA_GetBackOrderProcessList"). If that doesn't suit, just replace the call to your own stored proc, or even a straight query.
Dim Ok
Dim BOProcessObject
Dim SystemProfile
Dim WriteHandle
Dim OrdersOnBackID()
Dim InvoiceID()
Dim InvLineID()
Dim InventoryID()
Dim PartNo()
Dim Quantity()
Dim WarehouseID()
Ok = True
If Ok = True Then
Set SystemProfile = CreateObject("JiwaSysProfile.clsSysProfile")
Set myFSO = CreateObject("Scripting.FileSystemObject")
If myFSO.FileExists(JiwaDatabaseObject.IniFile) = True Then
If SystemProfile.Load(JiwaDatabaseObject.IniFile) = False Then
rtnErrorModule = SystemProfile.ErrorModule
rtnErrorString = SystemProfile.ErrorMessage
Ok = False
Else
JiwaDatabaseObject.CurrentLogicalWarehouseID = SystemProfile.GetValue("JiwaDocument/Parameters/InventoryParams/LastLogicalWarehouseID")
End If
End If
Set MyFSO = nothing
End If
If Ok = True Then
StoredProcName = JiwaDatabaseObject.ReadSysData("System", "StoredProcForProcessBackOrders", "usp_JIWA_GetBackOrderProcessList")
SQLStr = "EXEC " & StoredProcName & " 1, 0, 0, 0, 0, 0, 0, 0, 'Main / New South Wales', '', ''"
With JiwaDatabaseObject
hRead1 = .StatementOpen(.ConnectionJiwaRead1)
If .ExecuteSelect(hRead1, SQLStr, True) = True Then
ReDim OrdersOnBackID(0)
ReDim InvoiceID(0)
ReDim InvLineID(0)
ReDim InventoryID(0)
ReDim PartNo(0)
ReDim Quantity(0)
ReDim WarehouseID(0)
Do While .FetchRow(hRead1) = True
ReDim Preserve OrdersOnBackID(UBound(OrdersOnBackID) + 1)
ReDim Preserve InvoiceID(UBound(InvoiceID) + 1)
ReDim Preserve InvLineID(UBound(InvLineID) + 1)
ReDim Preserve InventoryID(UBound(InventoryID) + 1)
ReDim Preserve PartNo(UBound(PartNo) + 1)
ReDim Preserve Quantity(UBound(Quantity) + 1)
ReDim Preserve WarehouseID(UBound(WarehouseID) + 1)
OrdersOnBackID(UBound(OrdersOnBackID)) = .GetData(hRead1, 2)
InvoiceID(UBound(InvoiceID)) = Trim(.GetData(hRead1, 4))
InvLineID(UBound(InvLineID)) = Trim(.GetData(hRead1, 5))
InventoryID(UBound(InventoryID)) = .GetData(hRead1, 6)
PartNo(UBound(PartNo)) = Trim(.GetData(hRead1, 7))
Quantity(UBound(Quantity)) = .GetData(hRead1, 10)
WarehouseID(UBound(WarehouseID)) = .GetData(hRead1, 13)
Loop
Else
rtnErrorModule = SQLStr
rtnErrorString = .ErrorMessage
Ok = False
End If
.StatementClose hRead1
End With
End If
If Ok = True Then
Set BOProcessObject = CreateObject("JiwaBOProcess.StdFunctions")
Set BOProcessObject.Database = JiwaDatabaseObject
Set BOProcessObject.SystemProfile = SystemProfile
Set BOProcessObject.MDIParent = Nothing
BOProcessObject.ReadsAreUnCommitted = True
If BOProcessObject.SetupProcessBackOrdersUnattended = False Then
rtnErrorModule = "BOProcessObject.SetupProcessBackOrdersUnattended"
rtnErrorString = "unkown error"
Ok = False
End If
End If
If Ok = True Then
WriteHandle = JiwaDatabaseObject.StatementOpen(JiwaDatabaseObject.ConnectionWrite, , , 0)
For ItemIndex = 1 To UBound(OrdersOnBackID)
If BOProcessObject.ProcessBackOrdersForSingleSalesOrderUnattended(WriteHandle, OrdersOnBackID(ItemIndex), InvoiceID(ItemIndex), InvLineID(ItemIndex), Quantity(ItemIndex), InventoryID(ItemIndex), PartNo(ItemIndex), WarehouseID(ItemIndex)) = False Then
Ok = False
m_ErrorModule = "BOProcessObject.ProcessBackOrdersForSingleSalesOrderUnattended"
m_ErrorString = "Error processing backorder : " & BOProcessObject.ErrorMessage
End If
If Ok = False Then
Exit For
End If
Next
If Ok = True Then
JiwaDatabaseObject.Commit
Else
JiwaDatabaseObject.RollBack
End If
JiwaDatabaseObject.StatementClose CInt(WriteHandle)
End If
End Sub