I getting dates of product reservation to the temporary array with the quantity reserved for a given day.
Below you can see that I have several reservations set for the product with ID: 3139.
I am interested closest date from the present day, ex. in this case, 2021-12-29 until that day, I have 3 items reserved, and on 2040-06-13 the reservation is gone, so these 3 items are returned to stock.
I currently did a script that looks for the nearest reserved date:
function find_closest($array, $date) {
foreach($array as $day) {
$interval[] = abs(strtotime($date) > strtotime($day));
}
asort($interval);
$closest = key($interval);
echo $array[$closest];
}
I do not know exactly how to do it, so that he checks exactly that a given number of pieces is reserved until 2040-06-13, and then it goes to 0.