<?php
require_once "../../includes/db.php";
header('Content-Type: application/json');
session_start();

$coid   = $_SESSION['co_id'];
$limit  = $_GET['limit'] ?? 10;
$offset = $_GET['offset'] ?? 0;

$stmt = $pdo->prepare("
    SELECT id, p_name, p_sale_px, p_prch_px, status
    FROM products
    WHERE co_id = :coid
    ORDER BY reporting_order ASC
    LIMIT :limit OFFSET :offset
");

$stmt->bindValue(':coid', $coid, PDO::PARAM_INT);
$stmt->bindValue(':limit', (int)$limit, PDO::PARAM_INT);
$stmt->bindValue(':offset', (int)$offset, PDO::PARAM_INT);

$stmt->execute();

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
exit;