uploaded new name

This commit is contained in:
2025-09-22 20:34:15 +03:00
parent dd1772222d
commit 921ea43834
14 changed files with 180 additions and 64 deletions

View File

@@ -617,25 +617,37 @@ async function checkPrintServiceAvailability() {
try {
printerStatus.textContent = 'Checking Windows Print Service...';
console.log(`🔍 Checking Windows Print Service at: ${PRINT_SERVICE_URL}/health`);
const response = await fetch(`${PRINT_SERVICE_URL}/health`, {
method: 'GET',
signal: AbortSignal.timeout(3000)
signal: AbortSignal.timeout(5000)
});
console.log(`📡 Service response status: ${response.status}`);
if (response.ok) {
const data = await response.json();
console.log('📋 Service response data:', data);
printServiceAvailable = true;
console.log('✅ Windows Print Service is available');
console.log('✅ Windows Print Service is available and responding!');
updatePrintButtonForService(true);
updatePrinterStatus(`Windows Print Service detected (${data.platform || 'Unknown platform'})`);
await loadAvailablePrinters();
} else {
throw new Error('Service not responding');
throw new Error(`Service responded with status ${response.status}`);
}
} catch (error) {
printServiceAvailable = false;
console.log('⚠️ Windows Print Service not available, using fallback PDF download');
console.error(' Windows Print Service check failed:', error);
console.log(`🔧 Troubleshooting:
1. Is the service running? Check: sc query QualityLabelPrinting
2. Is port 8765 accessible? Try: http://localhost:8765/health in new tab
3. Service logs: C:\\Program Files\\QualityLabelPrinting\\PrintService\\print_service.log`);
updatePrintButtonForService(false);
updatePrinterStatus('Windows Print Service not detected - PDF download mode');
updatePrinterStatus(`Windows Print Service not detected - ${error.message}`);
}
}
@@ -710,12 +722,16 @@ function updatePrintButtonForService(serviceAvailable) {
// Enhanced print function with Windows service support
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
const printData = {
@@ -727,6 +743,9 @@ async function printLabelsWithService(orderId, prodOrder, quantity) {
quantity: quantity
};
console.log('📋 Print request data:', printData);
console.log(`📡 Sending to: ${PRINT_SERVICE_URL}/print/silent`);
// Send to Windows service
const response = await fetch(`${PRINT_SERVICE_URL}/print/silent`, {
method: 'POST',
@@ -736,11 +755,16 @@ async function printLabelsWithService(orderId, prodOrder, quantity) {
body: JSON.stringify(printData)
});
console.log(`📨 Service response status: ${response.status}`);
const result = await response.json();
console.log('📋 Service response data:', result);
if (response.ok && result.success) {
// Success - labels printed silently
const printerName = selectedPrinter === 'default' ? 'default printer' : selectedPrinter;
console.log(`✅ Print successful to printer: ${printerName}`);
alert(`✅ Labels printed successfully!\n\n📊 Order: ${prodOrder}\n📦 Quantity: ${quantity} labels\n🖨️ Printer: ${printerName}\n📋 Sequential: ${prodOrder}-001 to ${prodOrder}-${String(quantity).padStart(3, '0')}\n\n🎯 Printed silently via Windows service!`);
// Update order status in database
@@ -748,11 +772,12 @@ async function printLabelsWithService(orderId, prodOrder, quantity) {
return true;
} else {
throw new Error(result.error || 'Print service failed');
console.error('❌ Service returned error:', result);
throw new Error(result.error || `Print service failed with status ${response.status}`);
}
} catch (error) {
console.error('Windows service print error:', error);
console.error('Windows service print error:', error);
throw error;
}
}
@@ -854,20 +879,29 @@ function addPDFGenerationHandler() {
try {
let success = false;
console.log(`🖨️ Print operation started - Service available: ${printServiceAvailable}`);
// Try Windows service first if available
if (printServiceAvailable) {
console.log('🚀 Attempting silent print via Windows service...');
try {
success = await printLabelsWithService(orderId, prodOrder, quantity);
console.log(`✅ Windows service print result: ${success}`);
} catch (serviceError) {
console.warn('Windows service failed, falling back to PDF download:', serviceError);
console.error('Windows service failed:', serviceError);
console.warn('🔄 Falling back to PDF download mode');
printServiceAvailable = false; // Mark as unavailable for this session
updatePrintButtonForService(false);
}
} else {
console.log('📄 Service not available, using PDF download mode');
}
// Fallback to PDF download if service failed or unavailable
if (!success) {
console.log('📥 Generating PDF for download...');
success = await downloadPDFLabels(orderId, prodOrder, quantity);
console.log(`📄 PDF download result: ${success}`);
}
} catch (error) {