updated print module
This commit is contained in:
@@ -720,34 +720,25 @@ function updatePrintButtonForService(serviceAvailable) {
|
||||
}
|
||||
}
|
||||
|
||||
// Enhanced print function with Windows service support
|
||||
// Enhanced print function with Windows service support - NEW SERVER-SIDE APPROACH
|
||||
async function printLabelsWithService(orderId, prodOrder, quantity) {
|
||||
console.log(`🖨️ printLabelsWithService called - Order: ${orderId}, Quantity: ${quantity}`);
|
||||
|
||||
try {
|
||||
// Generate PDF URL
|
||||
const pdfUrl = `${window.location.origin}/generate_labels_pdf/${orderId}`;
|
||||
console.log(`📄 PDF URL: ${pdfUrl}`);
|
||||
|
||||
// Get selected printer from dropdown
|
||||
const selectedPrinter = getSelectedPrinter();
|
||||
console.log(`🖨️ Selected printer: ${selectedPrinter}`);
|
||||
|
||||
// Prepare print data for service
|
||||
// Use new server-side endpoint that bypasses CORS
|
||||
const printData = {
|
||||
pdf_url: pdfUrl,
|
||||
printer_name: selectedPrinter,
|
||||
copies: 1,
|
||||
silent: true,
|
||||
order_id: orderId,
|
||||
quantity: quantity
|
||||
printer_name: selectedPrinter
|
||||
};
|
||||
|
||||
console.log('📋 Print request data:', printData);
|
||||
console.log(`📡 Sending to: ${PRINT_SERVICE_URL}/print/silent`);
|
||||
console.log(`📡 Sending to server endpoint: /print_labels_silent/${orderId}`);
|
||||
|
||||
// Send to Windows service
|
||||
const response = await fetch(`${PRINT_SERVICE_URL}/print/silent`, {
|
||||
// Send to Flask server which handles Windows service communication
|
||||
const response = await fetch(`/print_labels_silent/${orderId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -755,10 +746,10 @@ async function printLabelsWithService(orderId, prodOrder, quantity) {
|
||||
body: JSON.stringify(printData)
|
||||
});
|
||||
|
||||
console.log(`📨 Service response status: ${response.status}`);
|
||||
console.log(`📨 Server response status: ${response.status}`);
|
||||
|
||||
const result = await response.json();
|
||||
console.log('📋 Service response data:', result);
|
||||
console.log('📋 Server response data:', result);
|
||||
|
||||
if (response.ok && result.success) {
|
||||
// Success - labels printed silently
|
||||
@@ -771,13 +762,24 @@ async function printLabelsWithService(orderId, prodOrder, quantity) {
|
||||
await updatePrintedStatus(orderId);
|
||||
|
||||
return true;
|
||||
} else if (response.status === 503 && result.fallback === 'pdf_download') {
|
||||
// Windows service not available - inform user and suggest fallback
|
||||
console.warn('⚠️ Windows service not available, showing service setup info');
|
||||
|
||||
alert(`⚠️ Windows Print Service Not Available\n\n${result.error}\n\n📋 To enable silent printing:\n1. Install the Windows Print Service\n2. Start the service: sc start QualityLabelPrinting\n3. Restart your browser\n\n💡 For now, use the "Generate PDF" button for manual printing.`);
|
||||
|
||||
// Mark service as unavailable for this session
|
||||
printServiceAvailable = false;
|
||||
updatePrintButtonForService(false);
|
||||
|
||||
throw new Error('Windows Print Service not available');
|
||||
} else {
|
||||
console.error('❌ Service returned error:', result);
|
||||
throw new Error(result.error || `Print service failed with status ${response.status}`);
|
||||
console.error('❌ Server returned error:', result);
|
||||
throw new Error(result.error || `Print operation failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Windows service print error:', error);
|
||||
console.error('❌ Server-side print error:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user