<?php
include('db/cn.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Fetch customer_type for the given order_id
$orderId = $_GET['order_id'] ?? '';

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

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

?>