false, 'error' => 'Order ID is required']); exit; } try { // Fetch order details with outlet info $stmt = $pdo->prepare(" SELECT o.*, out.cashier_printer_ip, out.kitchen_printer_ip FROM orders o JOIN outlets out ON o.outlet_id = out.id WHERE o.id = ? "); $stmt->execute([$order_id]); $order = $stmt->fetch(PDO::FETCH_ASSOC); if (!$order) { echo json_encode(['success' => false, 'error' => 'Order not found']); exit; } // Fetch items $stmt = $pdo->prepare("SELECT * FROM order_items WHERE order_id = ?"); $stmt->execute([$order_id]); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch company settings $company = get_company_settings(); // Determine target IP $printer_ip = ($type === 'kitchen') ? $order['kitchen_printer_ip'] : $order['cashier_printer_ip']; if (empty($printer_ip)) { echo json_encode(['success' => false, 'error' => "No $type printer IP configured for this outlet"]); exit; } // Generate ESC/POS data $data = PrinterService::formatReceipt($order, $items, $company); // Send to printer $result = PrinterService::sendToNetworkPrinter($printer_ip, $data); echo json_encode($result); } catch (Exception $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); }