Allocate Data from one unrelated source to another
I have 2 sources of data. 1. Is Sales Order data, and 2. is Stock data.
I have a requirement to create 2 additional fields by allocating values from 1 row in 1 Stack data to multiple rows in Sales Order data. I have attached sample data and a sample app.
In the Before table of the above screen shot, the total On Hand value for Stock Item 3, in warehouse 3 = 25. I want to allocate this value to the 3 Sales Orders that have Stock Item 3 from warehouse 3. The on Hand value should match the open value and the remainder goes to the next oldest Sales Order until the On Hand value = zero (or there are no more Sales Orders). The same concept needs to apply to the Qty On Order value, except Qty On Order only applies once the On Hand allocated value reaches zero. I need to produce the After table, using data from the Before table. On Hand Stock from other warehouses is NOT to be allocated to different warehouses.