From c5d1449ede7ef8e904e10d91344259ce2767eb55 Mon Sep 17 00:00:00 2001 From: Scheianu Ionut Date: Fri, 26 Sep 2025 23:32:20 +0300 Subject: [PATCH] commit node js --- electron_pos_analysis.py | 104 ++++++++ py_app/app/__pycache__/routes.cpython-312.pyc | Bin 98046 -> 99274 bytes py_app/app/routes.py | 26 +- py_app/app/templates/print_module.html | 249 +++++++++++++++--- 4 files changed, 344 insertions(+), 35 deletions(-) create mode 100644 electron_pos_analysis.py diff --git a/electron_pos_analysis.py b/electron_pos_analysis.py new file mode 100644 index 0000000..8acb279 --- /dev/null +++ b/electron_pos_analysis.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +""" +Analysis: electron-pos-printer vs Other Solutions +Comprehensive comparison for thermal printer integration +""" + +print("๐Ÿ” ELECTRON-POS-PRINTER ANALYSIS") +print("=" * 60) +print() + +print("๐Ÿ“Š SOLUTION COMPARISON:") +print() + +solutions = { + "Windows Service": { + "pros": ["Universal browser support", "Background operation", "No user interaction"], + "cons": ["Complex installation", "Windows only", "Service management issues", "Firewall/security concerns"], + "complexity": "High", + "reliability": "Medium", + "user_experience": "Poor (complex setup)" + }, + "Chrome Extension": { + "pros": ["Better integration", "No installation complexity", "Chrome Web Store distribution"], + "cons": ["Chrome/Edge only", "Limited printer access", "Manifest V3 restrictions", "Native messaging needed"], + "complexity": "High", + "reliability": "Medium", + "user_experience": "Medium (browser dependent)" + }, + "Electron POS Printer": { + "pros": [ + "Direct printer communication", + "Rich formatting (text, barcodes, QR, images, tables)", + "Multiple paper sizes (80mm, 58mm, etc.)", + "Active development (364 stars)", + "TypeScript support", + "Easy integration", + "Cross-platform potential", + "No service installation needed" + ], + "cons": ["Requires Electron app wrapper", "Slightly larger footprint"], + "complexity": "Low", + "reliability": "High", + "user_experience": "Excellent (simple setup)" + } +} + +for solution, details in solutions.items(): + print(f"๐Ÿ—๏ธ {solution.upper()}:") + print(f" โœ… Pros: {', '.join(details['pros'])}") + print(f" โŒ Cons: {', '.join(details['cons'])}") + print(f" ๐Ÿ”ง Complexity: {details['complexity']}") + print(f" ๐ŸŽฏ Reliability: {details['reliability']}") + print(f" ๐Ÿ‘ค UX: {details['user_experience']}") + print() + +print("๐ŸŽฏ RECOMMENDATION: ELECTRON-POS-PRINTER") +print("=" * 60) +print() + +print("โœ… WHY ELECTRON-POS-PRINTER IS THE BEST CHOICE:") +print(" 1. ๐ŸŽจ Rich formatting capabilities (perfect for our labels)") +print(" 2. ๐Ÿ–จ๏ธ Direct thermal printer support") +print(" 3. ๐Ÿ“ Multiple paper sizes (58mm, 80mm thermal printers)") +print(" 4. ๐Ÿ”ง Simple installation - just package the Electron app") +print(" 5. ๐Ÿš€ Active project with 364 stars and regular updates") +print(" 6. ๐Ÿ“ฑ Can create standalone desktop app for printing") +print(" 7. ๐Ÿ”— Easy web integration via IPC or HTTP API") +print(" 8. ๐ŸŽฏ Designed specifically for POS/receipt printing") +print() + +print("๐Ÿ—๏ธ IMPLEMENTATION STRATEGY:") +print(" 1. Create Electron wrapper app around our Flask web interface") +print(" 2. Use electron-pos-printer for all thermal printing") +print(" 3. Keep PDF generation as fallback for non-thermal printers") +print(" 4. Package as single executable for easy deployment") +print() + +print("๐Ÿ“‹ IMPLEMENTATION STEPS:") +print(" โœจ Step 1: Create Electron main process") +print(" ๐Ÿ–จ๏ธ Step 2: Integrate electron-pos-printer") +print(" ๐Ÿ”— Step 3: Add IPC communication with web interface") +print(" ๐Ÿ“ฆ Step 4: Package for distribution") +print(" ๐Ÿงช Step 5: Test with thermal printers") +print() + +print("๐Ÿ”ฅ KEY FEATURES WE CAN IMPLEMENT:") +print(" โ€ข Direct thermal printing without PDF") +print(" โ€ข Barcode generation (Code128, Code39, EAN, etc.)") +print(" โ€ข QR code generation") +print(" โ€ข Rich text formatting") +print(" โ€ข Image printing (logos, etc.)") +print(" โ€ข Table layouts") +print(" โ€ข Multiple copies") +print(" โ€ข Print preview") +print(" โ€ข Paper size optimization") +print() + +print("โœ… VERDICT: This is the BEST solution!") +print(" The electron-pos-printer package is specifically designed") +print(" for our exact use case and eliminates all the complexity") +print(" of Windows services or browser extensions.") + +if __name__ == "__main__": + pass \ No newline at end of file diff --git a/py_app/app/__pycache__/routes.cpython-312.pyc b/py_app/app/__pycache__/routes.cpython-312.pyc index e2ff6de435944091ae44e5d6523ac05884995d92..ad5b5656abf26bd75c9fb26c9562aadf44e70704 100644 GIT binary patch delta 1245 zcmZ8fZERXq7(VA-F5JR^GAPi=n%gnERWmx5c1~J1hh1pRg57Wl=u&pe0d^?@J6y`j zfG*R-E-r2z(Yr>I_3zUCsPP9TCZ;wqG5Uw4b&}esKh)pUCX1OL@f<#u#gp9Uy!XD( z`<(ZE&i(fv?%Vg&hVS%xEg6F09}3;EH^{& z=3C`7v~jb@8iQrG&c{R!mM^ef&LXlRTa3AHUuK$2RC=mtau)VqedmU*azh8LlRfuX z{5xUc-w14KGuc=yl98oU5tGShM@eMn5F z!>xWAo0=d?o}D~Y;!)Vc6qxdtUp!yF?J`@C3USLcNmh|X>Y}QV>^HFmRlC)Yyn-~{sScIAG64;0mM zSNk0q3hLW`cfVvrof3Q^W{NUlCI}E)RF~BL)}DhoaG4E)9PHnn9~x~#*yvK%7WOVXZGNcL zLWnen&y#|edBXpiaIS*7+RBZ?pLzF>ys54RdmMLdi?+LtMaSII^bdW*5Bi2b53F8U z@Al6dYUZJNo^ZNsig&@QoL)G+)U#q=x47p!elePE=C0>%madoXNE^n3Tjo8r?qjuQ zUaR%IvaL}$3_Cz&G1hrtveY|N7E2wd^p@>ipwqc@eC60TgB!+)DnIe(uR6;gfFb>C z@p^x?^XST@m2lPI-r$F~jMh7vYVXOa&9iQNb=6-rj(yLM{Z;2E`*CJJndREa5swyp zbwW#UP21sdvukFDXNX-JfHWTBJnqWg1U$-dlf;5RC2$G;#HdB;-vwnvhP_;v#J7|w z8J2ZZ^mCL#gMK&Dh~M++hLZtT)2?pmMDQ3;zL2EKb+} delta 238 zcmX@r&i3ywE8l5eUM>b8SpDW&MnUpKJ_*Kzjp`m;jJ1;sxF*P?h@~^GkyyByzjGEIgW-`h!YHoj* z$tcdq7`~k?o6((d`>_H>6IRwppozBI|Cch}V`7T|vWudpKdxX@WQ_x|OQ&;IGEU}> z1qmmDh=l3OD;ZT;lYs21=@%;*l^Nr', methods=['GET']) def get_order_data(order_id): """Get specific order data for preview""" diff --git a/py_app/app/templates/print_module.html b/py_app/app/templates/print_module.html index 9ba770f..3d9e755 100644 --- a/py_app/app/templates/print_module.html +++ b/py_app/app/templates/print_module.html @@ -207,20 +207,36 @@
-
-
- ๐Ÿ“ฆ Quality Print Service + +
+
+ ๐Ÿ–ฅ๏ธ Quality Print Desktop v1.0.0 (RECOMMENDED) +
+
+ Professional desktop app with built-in thermal printing โ€ข Direct hardware access โ€ข Rich formatting +
+ + โœ… READY! +
+ + +
+
+ ๐Ÿ“ฆ Windows Print Service (DEPRECATED)
- Professional Windows service for instant direct printing to thermal label printers without PDF dialogs + Legacy background service โ€ข Limited features โ€ข Use desktop app instead
- - ๐Ÿ“ฅ Download Complete Package + + ๐Ÿ“ฅ Download Legacy Service
+
- Easy Install: Extract โ†’ Run install.bat as Admin โ†’ Done!
- Supports all thermal printers โ€ข Auto-starts with Windows โ€ข One-click installation + ๐Ÿ† Desktop App Benefits: Direct thermal printing โ€ข Rich barcodes/QR codes โ€ข Better reliability
+ โœจ Now includes: electron-pos-printer โ€ข One-click install โ€ข Cross-platform support
@@ -580,18 +596,187 @@ function handleDirectPrint(selectedRow) { console.log(`Direct printing to: ${printerName || 'default printer'}`); - // Check if print service is available + // Extract order data from selected row + const cells = selectedRow.querySelectorAll('td'); + const orderData = { + id: parseInt(orderId), + comanda_productie: cells[1].textContent.trim(), + cod_articol: cells[2].textContent.trim(), + descr_com_prod: cells[3].textContent.trim(), + cantitate: parseInt(cells[4].textContent.trim()), + data_livrare: cells[5].textContent.trim(), + dimensiune: cells[6].textContent.trim(), + com_achiz_client: cells[7].textContent.trim(), + nr_linie_com_client: cells[8].textContent.trim(), + customer_name: cells[9].textContent.trim(), + customer_article_number: cells[10].textContent.trim() + }; + + // Check for Electron thermal printing first (best option) + if (window.ThermalPrinter) { + console.log('๐Ÿ”ฅ Using Electron thermal printer'); + handleElectronThermalPrint(orderData, printerName, quantity, prodOrder); + return; + } + + // Fallback to Windows service (if available) checkPrintServiceStatus() .then(serviceStatus => { - if (!serviceStatus) { - throw new Error('Print service is not available'); + if (serviceStatus) { + console.log('๐Ÿ–จ๏ธ Using Windows print service'); + return handleServicePrint(orderId, printerName, quantity, prodOrder); + } else { + throw new Error('No print service available. Please install the Quality Print Desktop app or Windows service.'); + } + }) + .catch(error => { + console.error('Direct print error:', error); + + let errorMessage = 'โŒ Direct printing failed: ' + error.message; + + if (error.message.includes('service') || error.message.includes('available')) { + errorMessage += '\n\n๐Ÿ’ก Solutions:\n' + + '1. Download and install Quality Print Desktop app (recommended)\n' + + '2. Install the Windows print service\n' + + '3. Use PDF generation as alternative'; } - // Generate PDF first for printing - return generatePrintablePDF(orderId, true); // true for paper-saving mode + alert(errorMessage); + }); +} + +// Handle Electron thermal printing (best option) +function handleElectronThermalPrint(orderData, printerName, quantity, prodOrder) { + const button = document.getElementById('print-label-btn'); + const originalText = button.textContent; + button.textContent = 'Printing...'; + button.disabled = true; + + // Print each label sequentially + printSequentialLabels(orderData, printerName, quantity, 0) + .then(() => { + alert(`โœ… Successfully printed ${quantity} labels!\n๐Ÿ“Š Order: ${prodOrder}\n๐Ÿ–จ๏ธ Printer: ${printerName || 'Default Printer'}\n๐Ÿ”ฅ Using Electron Thermal Printing`); + + // Update database status + updatePrintedStatus(orderData.id); }) + .catch(error => { + console.error('Electron thermal print error:', error); + alert(`โŒ Thermal printing failed: ${error.message}\n\n๐Ÿ’ก Try using PDF generation instead.`); + }) + .finally(() => { + button.textContent = originalText; + button.disabled = false; + }); +} + +// Print labels sequentially for better reliability +async function printSequentialLabels(orderData, printerName, totalQuantity, currentIndex) { + if (currentIndex >= totalQuantity) { + return; // All labels printed + } + + const labelNumber = currentIndex + 1; + const sequentialId = `${orderData.comanda_productie}-${labelNumber.toString().padStart(3, '0')}`; + + // Generate label data for this specific label + const labelData = [ + { + type: 'text', + value: 'INNOFA ROMANIA SRL', + style: { fontWeight: 'bold', fontSize: '12px', textAlign: 'center', marginBottom: '5px' } + }, + { + type: 'text', + value: orderData.customer_name || 'N/A', + style: { fontSize: '11px', textAlign: 'center', marginBottom: '3px' } + }, + { + type: 'text', + value: 'โ”€'.repeat(32), + style: { textAlign: 'center', fontSize: '8px', marginBottom: '2px' } + }, + { + type: 'text', + value: `Quantity: ${orderData.cantitate || '0'}`, + style: { fontSize: '10px', marginBottom: '2px' } + }, + { + type: 'text', + value: `Customer Order: ${orderData.com_achiz_client || 'N/A'}-${orderData.nr_linie_com_client || '00'}`, + style: { fontSize: '10px', marginBottom: '2px' } + }, + { + type: 'text', + value: `Delivery: ${orderData.data_livrare || 'N/A'}`, + style: { fontSize: '10px', marginBottom: '2px' } + }, + { + type: 'text', + value: `Size: ${orderData.dimensiune || 'N/A'}`, + style: { fontSize: '10px', marginBottom: '2px' } + }, + { + type: 'text', + value: `Article: ${orderData.customer_article_number || 'N/A'}`, + style: { fontSize: '10px', marginBottom: '3px' } + }, + { + type: 'text', + value: 'โ”€'.repeat(32), + style: { textAlign: 'center', fontSize: '8px', marginBottom: '3px' } + }, + { + type: 'barCode', + value: sequentialId, + height: 40, + width: 2, + displayValue: true, + fontsize: 8, + style: { textAlign: 'center', marginBottom: '5px' } + }, + { + type: 'text', + value: `Label ${labelNumber}/${totalQuantity}`, + style: { fontSize: '8px', textAlign: 'center', marginBottom: '5px' } + }, + { + type: 'text', + value: ' ', // Add spacing + style: { fontSize: '6px' } + } + ]; + + const printOptions = { + printerName: printerName || 'default', + pageSize: '80mm', + margin: '2mm 2mm 2mm 2mm', + copies: 1, + silent: true, + preview: false, + timeOutPerLine: 200 + }; + + console.log(`๐Ÿท๏ธ Printing label ${labelNumber}/${totalQuantity}: ${sequentialId}`); + + try { + // Print this label + await window.ThermalPrinter.print(labelData, printOptions); + + // Small delay between labels + await new Promise(resolve => setTimeout(resolve, 300)); + + // Print next label + return printSequentialLabels(orderData, printerName, totalQuantity, currentIndex + 1); + } catch (error) { + throw new Error(`Failed to print label ${labelNumber}: ${error.message}`); + } +} + +// Handle Windows service printing (fallback) +function handleServicePrint(orderId, printerName, quantity, prodOrder) { + return generatePrintablePDF(orderId, true) // true for paper-saving mode .then(pdfUrl => { - // Send PDF to print service const printData = { pdf_url: pdfUrl, printer: printerName, @@ -616,31 +801,13 @@ function handleDirectPrint(selectedRow) { }) .then(result => { if (result.success) { - alert(`โœ… Successfully sent ${quantity} labels to printer!\n๐Ÿ“Š Order: ${prodOrder}\n๐Ÿ–จ๏ธ Printer: ${printerName || 'Default'}\n๐Ÿ“„ Job ID: ${result.job_id || 'N/A'}`); + alert(`โœ… Successfully sent ${quantity} labels to printer!\n๐Ÿ“Š Order: ${prodOrder}\n๏ฟฝ๏ธ Printer: ${printerName || 'Default'}\n๐Ÿ“„ Job ID: ${result.job_id || 'N/A'}`); // Update database status and refresh table - updatePrintedStatus(orderId); + updatePrintedStatus(parseInt(orderId)); } else { throw new Error(result.error || 'Unknown print error'); } - }) - .catch(error => { - console.error('Direct print error:', error); - - let errorMessage = 'โŒ Direct printing failed: ' + error.message; - - if (error.message.includes('service is not available')) { - errorMessage += '\n\n๐Ÿ’ก Solutions:\n' + - '1. Install the print service using the download link below\n' + - '2. Ensure the service is running (check Windows Services)\n' + - '3. Try restarting the print service\n' + - '4. Use PDF generation as alternative'; - } else if (error.message.includes('fetch')) { - errorMessage += '\n\n๐Ÿ’ก The print service may not be running.\n' + - 'Please start the Quality Print Service from Windows Services.'; - } - - alert(errorMessage); }); } @@ -929,6 +1096,20 @@ function clearLabelPreview() { document.getElementById('vertical-barcode-text').textContent = '000000-00'; } +// Download Electron app function +function downloadElectronApp() { + // Download the Quality Print Desktop v1.0.0 + const link = document.createElement('a'); + link.href = '/download/desktop-app'; + link.download = 'Quality_Print_Desktop_v1.0.0.zip'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // Show success message + showNotification('๏ฟฝ Quality Print Desktop v1.0.0 download started!', 'success'); +} + document.getElementById('print-label-btn').addEventListener('click', function() { console.log('Generate PDF logic here'); });