Hi,
I want to subtract sales from stock in script.
scenario: I have ST of product A and Product B and SL takes place on different dates. When the SL sold out from product A then product B needs to be substract.
Such as on 22.01.2021, ST Product A was 18 and items sold out until 29.01.2021 but on this dates total remaining ST Product A was 3 and Sold items were 4 so 3 - 4 = -1. So 3 items should be subtract from Product A and 1 items should be subtract from Product B. and also mark it in last 2 columns that the sold items take place from Product A or Product B.
Main Product | Sub Product | Date | ST Product A | ST Product B | SL | SL from Product A | SL from Product B |
A | AA | 10.02.2021 | | | 20 | 15 | 5 |
A | AA | 09.02.2021 | 15 | 5 | 1 | | 1 |
A | AA | 06.02.2021 | | | 1 | | 1 |
A | AA | 05.02.2021 | | | 1 | | 1 |
A | AA | 04.02.2021 | | | 1 | | 1 |
A | AA | 03.02.2021 | | | 1 | | 1 |
A | AA | 02.02.2021 | | | 1 | | 1 |
A | AA | 01.02.2021 | | | 1 | | 1 |
A | AA | 31.01.2021 | | | 1 | | 1 |
A | AA | 30.01.2021 | | | 1 | | 1 |
A | AA | 29.01.2021 | | 5 | 4 | 3 | 1 |
A | AA | 28.01.2021 | | | 4 | 4 | |
A | AA | 27.01.2021 | | 2 | 2 | 2 | |
A | AA | 26.01.2021 | | | 2 | 2 | |
A | AA | 25.01.2021 | | 3 | 1 | 1 | |
A | AA | 24.01.2021 | | | 3 | 3 | |
A | AA | 23.01.2021 | | | 2 | 2 | |
A | AA | 22.01.2021 | 18 | | 1 | 1 | |