<?php
include 'koneksi.php';

$data = json_decode(file_get_contents("php://input"), true);

$productId = $data['productId'];
$quantity = $data['quantity'];
$total = $data['total'];
$paymentMethod = $data['paymentMethod'];

$sql = "INSERT INTO orders (total_harga, Metode_bayar) VALUES (?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("is", $total, $paymentMethod);
$stmt->execute();
$orderId = $stmt->insert_id; 

$sql = "INSERT INTO order_items (order_id, product_id, jumlah, harga_satuan) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("iiid", $orderId, $productId, $quantity, $total);
$stmt->execute();

$stmt->close();
$conn->close();

echo json_encode(['status' => 'success']);
?>
