0

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.

Screen of temporary array Screen of temporary array

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.

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
Blaaszka
  • 1
  • 1
  • Is data stored in DB? I think SQL solution can be be easy – Slava Rozhnev Jun 19 '21 at 13:28
  • @SlavaRozhnev Yes, data is stored in comarch MSSQL, i retrived reservation data from MSSQL to MySQL temporary array. – Blaaszka Jun 19 '21 at 13:34
  • @Blaaszka, Please share the expected output. – Samir Selia Jun 19 '21 at 15:04
  • @Samir currently, only the quantity in stock is transferred to the store, without taking into account the reserved products, and I need to provide the correct quantity – Blaaszka Jun 19 '21 at 15:43
  • I'm still unable to understand what are you looking to solve. A sample data set from the table with the expected rows from the MySQL query would help in providing a solution. – Samir Selia Jun 19 '21 at 17:56
  • Have a look here: https://stackoverflow.com/a/6187063/1456201 You can just do `LIMIT 1` to get the single closest date. – Jim Jan 15 '22 at 14:22

0 Answers0