Hello All! I have a really hard question! I have a list of sales orders, a list of purchase orders, and a list of stock. I am trying to line up what will be consumed for each sales order by contract date of the sales order. Stock must be consumed first. I have been able to sort them by date and deplete the stock, but I cannot figure out how to then fill in the missing gaps with the Purchase Orders. Help! I have just attached the data because the work flow is just a data input and sort so far. I don't know where to start. I hope this makes sense.
| Sales Order | S.O. Part # | Contract Date | Sales Order Qty | Stock | Purchase Order | P.O. QTY | PO Part # | Purchase Order Date |
| 1 | 141516 | 1/5/2023 | 2 | 1 | 450501 | 2 | 141516 | 1/6/2023 |
| 2 | 151617 | 1/6/2023 | 3 | 4 | 450502 | 2 | 141516 | 1/8/2023 |
| 3 | 161718 | 1/7/2023 | 4 | 3 | 450503 | 2 | 141516 | 1/10/2023 |
| 4 | 181920 | 1/7/2023 | 2 | 0 | 450504 | 2 | 151617 | 1/11/2023 |
| 5 | 212223 | 1/9/2023 | 5 | 0 | 450505 | 2 | 161718 | 1/10/2023 |
| 6 | 161718 | 1/10/2023 | 4 | 3 | 450506 | 2 | 161718 | 1/12/2023 |
| 7 | 161718 | 1/15/2023 | 4 | 3 | 450507 | 4 | 161718 | 1/14/2023 |
| 450508 | 1 | 161718 | 1/16/2023 | |||||
| 450509 | 2 | 181920 | 1/17/2023 | |||||
| 450510 | 1 | 151617 | 1/13/2023 | |||||
| 450511 | 2 | 212223 | 1/11/2023 | |||||
| 450512 | 3 | 212223 | 1/12/2023 | |||||
| Result | ||||||||
| Sales Order | S.O. Part # | Contract Date | Sales Order Qty | Stock used | Purchase Order Used | Purchase Order | Purchase Order 2 | Purchase Order 3 |
| 1 | 141516 | 1/5/2023 | 2 | 1 | 1 | 450501 | ||
| 2 | 151617 | 1/6/2023 | 3 | 3 | 0 | |||
| 3 | 161718 | 1/7/2023 | 4 | 3 | 1 | 450505 | ||
| 4 | 181920 | 1/7/2023 | 2 | 0 | 0 | 450509 | ||
| 5 | 212223 | 1/9/2023 | 5 | 0 | 0 | 450511 | 450512 | |
| 6 | 161718 | 1/10/2023 | 4 | 0 | 4 | 450505 | 450506 | 450507 |
| 7 | 161718 | 1/15/2023 | 4 | 0 | 4 | 450507 | 450508 |
Sales Orders 4 and 5 should of had Purchase Orders used as 2 and 5.
