<?php
    try {
        include("../main.php");
        $request = json_decode(file_get_contents('php://input'));
        extract((array) $request);
        $query = "INSERT INTO `bookings`(`name`, `email`, `phone`, `address`, `booking_date`, `remarks`, `price`, `price_without_tax`, `tax`) VALUES ('$name','$email','$phone','$address','$booking_date','$remarks','$price','$price_without_tax','$tax_price')";
        $dbobjx->query($query);
        if ($dbobjx->execute()) {
            $booking_id = $dbobjx->lastInsertId();
            $query = "INSERT INTO `booking_details` (`booking_id`, `product_name`, `product_quantity`, `created_at`) VALUES ";
            $valuebridge = [];
            foreach ($product_details as $key => $value) {
                $name = $value->name;
                $quantity = $value->quantity;
                $valuebridge[] = "($booking_id, '$name', '$quantity', NOW())";
            }
            $query .= implode(',', $valuebridge);
            $dbobjx->query($query);
            $dbobjx->execute($query);
            echo response(1, "SUCCESSFULLY OPERATED", []);
        } else {
            echo response(0, "BAD REQUEST!", []);
        }
        $dbobjx->close();
    } catch (Exception $error) {
        echo response(0, "API ERROR!, UNPROCESSABLE ENTITY", $error->getMessage());
    }
#code ends
#mtech