<?php
require_once '../db.php';
require_once '../includes/company.php';

$id = (int)($_GET['id'] ?? 0);
if ($id <= 0) exit('Invalid ID');

$po = $conn->query("
    SELECT po.*, v.name AS vendor_name
    FROM purchase_orders po
    JOIN vendors v ON v.id = po.vendor_id
    WHERE po.id = $id
")->fetch_assoc();
if (!$po) exit('PO not found');

$company = getCompany($conn, $po['company_id']);

$items = $conn->query("
    SELECT pi.*, p.name AS product_name
    FROM purchase_items pi
    JOIN products p ON p.id = pi.product_id
    WHERE pi.purchase_order_id = $id
");

require 'layout_thermal.php';
