<?php
include 'config.php';

if(isset($_GET['nota'])) {
    $nota = $_GET['nota'];
    
    // Get products from the transaction
    $query = mysqli_query($conn, "SELECT t.idproduk, t.quantity, p.nama_produk, p.harga_jual, (t.quantity * p.harga_jual) as subtotal 
                                  FROM tb_nota t 
                                  JOIN produk p ON t.idproduk = p.idproduk 
                                  WHERE t.no_nota = '$nota'");
    
    $products = [];
    while($row = mysqli_fetch_assoc($query)) {
        $products[] = $row;
    }
    
    if(count($products) > 0) {
        echo json_encode([
            'success' => true,
            'products' => $products
        ]);
    } else {
        echo json_encode([
            'success' => false,
            'message' => 'No products found for this nota'
        ]);
    }
} else {
    echo json_encode([
        'success' => false,
        'message' => 'No nota provided'
    ]);
}
?>