In your script, create a stock movements table based on the rows you specified in the first list. The movements table has a single date column, a single movement quantity column and a single product column.
First store the stock additions in this table (only rows with Item, Quantity and Purchased Date), like:
Then add the stock subtractions (only rows with Item, Quantity and Sales Date). Negate the Quantity.
The order is unimportant. Showing stock levels on a certain date now becomes very simple.