0

時間指定をしています。特定の時間帯 (10:00 - 11:00、11:30 - 12:30、13:00 - 14:000) では、特定の数のアイテムのみを注文する必要があります。最大数に達した場合は、注文オプションを無効にする必要があります。時間が変わったときに在庫状況に応じて読み込まれるように、ajax を介してアイテムをリストします。私は多くの方法を試しましたが、できません。

http://rezervace.pcserviskv.cz/step1/

出力:

2020-05-18

10:00 - 11:00 - 項目 1 (2/0)

10:00 - 11:00 - 項目 2 (4/0)

2020-05-18

11:30 - 12:30 - 項目 1 (2/1)

11:30 - 12:30 - 項目 2 (2/0)

2020-05-18

13:00 - 14:00 - 項目 1 (2/0)

13:00 - 14:00 - 項目 2 (4/1)

2020-05-19

10:00 - 11:00 - 項目 1 (2/0)

10:00 - 11:00 - 項目 2 (4/0)

2020-05-19

11:30 - 12:30 - アイテム 1 (2/2) - 在庫切れ

11:30 - 12:30 - 項目 2 (2/0)

2020-05-19

13:00 - 14:00 - 項目 1 (2/0)

13:00 - 14:00 - アイテム 2 (4/4) - 在庫切れ

    -- Product

create table product
(
    id    int auto_increment
        primary key,
    name  varchar(255) not null,
    count int(3)       not null,
    input varchar(255) not null,
    price int(5)       not null
);

INSERT INTO product (id, name, quantity, input, price) VALUES 
(3, 'Item 1', 2, 'item1', 500), 
(4, 'Item 2', 4, 'item2', 1000);


    -- orders

create table orders
(
    id         int auto_increment
        primary key,
    number     int          not null,
    product    varchar(255) not null,
    date       date         not null,
    time_start time         not null,
    time_end   time         not null
);

INSERT INTO orders (id, number, date, time_start, time_end, first_name, last_name, email, phone) VALUES 
(1, 0, '2020-05-18', '11:30:00', '12:30:00', '', '', '', ''),
(2, 0, '2020-05-18', '13:00:00', '14:00:00', '', '', '', ''),
(3, 0, '2020-05-19', '11:30:00', '12:30:00', '', '', '', ''),
(4, 0, '2020-05-19', '13:00:00', '14:00:00', '', '', '', '');


    -- order_items

create table order_items
(
    id           int(4) auto_increment
        primary key,
    order_id     int(4)       not null,
    product_name varchar(255) not null,
    quantity     int(2)       not null
);

INSERT INTO order_items (id, order_id, product_id, product_name, quantity) VALUES 
(1, 1, 3, 'Item 1', 1),
(2, 2, 4, 'Item 2', 1),
(3, 3, 3, 'Item 1', 2),
(4, 4, 4, 'Item 2', 4);

SELECT i.id as id, i.product_id as product_id, SUM(ifnull(i.quantity, 0)) as quantity_order, p.name
as name, p.price as price, p.quantity as quantity,
p.input as input, o.time_start as time_start, o.time_end as time_end
FROM product p
LEFT JOIN order_items i ON p.id = i.product_id
LEFT JOIN orders o on o.id = i.order_id
WHERE (o.date = '2020-05-18') AND (o.time_start = '11:30:00') AND (o.time_end = '12:30:00') or
i.product_id IS NULL or i.id 
GROUP BY p.id, o.time_start, o.time_end


foreach ($products as $product) {
  if($product->quantity <= $product->quantity_order && $product->time_start == $time->time_start) {
  echo $product->name . "out of stock";
 } else {
      echo $product->name . "<input type="number">";
        }
}

4

0 に答える 0