Here is the complete sequence of tasks in the workflow:
1. Get list of current Sales Order from db
2. Get list of current System Stock from db
3. Get list of current System Works Orders from db
4. Get list of current Sensor Stock from db
5. Get list of current Sensor Works Orders from db
6. For each Order, see if there is a System in stock
7. If there is, assign it to the order and remove it from stock
8. If there isn't, check if there is a works order to make a system
9. If there is, assign it to the Sales Order and remove it from the list of available system works orders
10. If a stock system was assigned, move to the next order.
11. If a system works order was assigned, check if there is a sensor in stock.
12. If there is assign it to the Sales Order and remove it from stock
13. If there isn't, check if there is a works order to make a sensor
14. If there is, assign it to the Sales Order and remove it from the list of available sensor works orders
15. If there are still any remaining Systems, Sensors or Works Orders, move to the next Sales Order
16. If not, write updated list of Sales Orders with Systems and Sensors back to db
Attached is an example in MS Excel 2003 spreadsheet format of how the output needs to look post-processing
Thanks for your help.