<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/printshop/includes/db.php");

$order_id = $_GET['order_id'] ?? null;

if (!$order_id) {
    echo "Order ID is required.";
    exit;
}

$invoice_path = $_SERVER['DOCUMENT_ROOT'] . "/printshop/invoices/invoice_{$order_id}.pdf";

if (file_exists($invoice_path)) {
    header('Content-Type: application/pdf');
    header("Content-Disposition: attachment; filename=invoice_{$order_id}.pdf");
    readfile($invoice_path);
} else {
    echo "Invoice not found.";
}
?>
