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

$id = (int)($_GET['id'] ?? 0);
if ($id <= 0) die("Invalid Return");

$pr = $conn->query("
    SELECT pr.*, po.po_no, v.name AS vendor_name
    FROM purchase_returns pr
    JOIN purchase_orders po ON po.id = pr.purchase_order_id
    JOIN vendors v ON v.id = pr.vendor_id
    WHERE pr.id = $id
")->fetch_assoc();
if (!$pr) die("Return not found");

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

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

require 'layout_thermal_return.php';
