<?php
include 'config.php';

// Get all products with category information
$query = "SELECT p.idproduk, p.kode_produk, p.nama_produk, p.harga_jual, p.stock, k.nama_kategori 
          FROM produk p 
          JOIN kategori k ON p.idkategori = k.idkategori 
          ORDER BY p.nama_produk ASC";
$result = mysqli_query($conn, $query);

$products = array();
while($row = mysqli_fetch_assoc($result)) {
    $row['harga_jual'] = number_format($row['harga_jual'], 0, ',', '.');
    $products[] = $row;
}

echo json_encode(array('products' => $products));
?>