<?php
include('../db/cn.php');

// Fetch customer_type for the given order_id
$orderId = $_GET['order_id'] ?? '';

if ($orderId) {
    $query = "SELECT customer_type FROM log_user_sales WHERE order_id = '$orderId' LIMIT 1";
    $result = mysqli_query($connection, $query);
    
    if ($result && $row = mysqli_fetch_assoc($result)) {
        $customerType = strtolower($row['customer_type']);

        if ($customerType === 'retail') {
            echo "<script>window.location.href = 'printpos.php?order_id=$orderId';</script>";
        } elseif ($customerType === 'wholesale') {
            echo "<script>window.location.href = 'printpos2.php?order_id=$orderId';</script>";
        } else {
            echo "<script>alert('Invalid customer type.');</script>";
        }
    } else {
        echo "<script>alert('Order not found.');</script>";
    }
}
?>
