From dc337b650531b95f94b63b420f93b2d3ace72f57 Mon Sep 17 00:00:00 2001 From: Scheianu Ionut Date: Thu, 2 Oct 2025 18:01:55 +0300 Subject: [PATCH] Add enhanced print controller with pause/resume and error recovery Features: - Real-time progress modal with visual progress bar and counter - Detailed event log with timestamps and color-coded status - Pause/Resume functionality for checking printer/paper - Reprint Last button for damaged labels - Cancel button for emergency stops - Automatic error detection and recovery - Auto-pause on print failures (paper out/jam) - Automatic retry of failed labels after resume - Smart state management tracking current/last/failed labels - Sequential label numbering maintained through errors - Database update only on successful completion - Proper modal display with .show class toggle --- py_app/ENHANCED_PRINT_CONTROLLER.md | 263 ++++++++++++++++ py_app/app/templates/print_module.html | 413 +++++++++++++++++++++---- 2 files changed, 612 insertions(+), 64 deletions(-) create mode 100644 py_app/ENHANCED_PRINT_CONTROLLER.md diff --git a/py_app/ENHANCED_PRINT_CONTROLLER.md b/py_app/ENHANCED_PRINT_CONTROLLER.md new file mode 100644 index 0000000..8ab36b9 --- /dev/null +++ b/py_app/ENHANCED_PRINT_CONTROLLER.md @@ -0,0 +1,263 @@ +# Enhanced Print Controller - Features & Usage + +## Overview +The print module now includes an advanced Print Controller with real-time monitoring, error detection, pause/resume functionality, and automatic reprint capabilities for handling printer issues like paper jams or running out of paper. + +## Key Features + +### 1. **Real-Time Progress Modal** +- Visual progress bar showing percentage completion +- Live counter showing "X / Y" labels printed +- Status messages updating in real-time +- Detailed event log with timestamps + +### 2. **Print Status Log** +- Timestamped entries for all print events +- Color-coded status messages: + - **Green**: Successful operations + - **Yellow**: Warnings and paused states + - **Red**: Errors and failures +- Auto-scrolling to show latest events +- Scrollable history of all print activities + +### 3. **Control Buttons** + +#### **⏸️ Pause Button** +- Pauses printing between labels +- Useful for: + - Checking printer paper level + - Inspecting print quality + - Loading more paper +- Progress bar turns yellow when paused + +#### **▢️ Resume Button** +- Resumes printing from where it was paused +- Appears when print job is paused +- Progress bar returns to normal green + +#### **πŸ”„ Reprint Last Button** +- Available after each successful print +- Reprints the last completed label +- Useful when: + - Label came out damaged + - Print quality was poor + - Label fell on the floor + +#### **❌ Cancel Button** +- Stops the entire print job +- Shows how many labels were completed +- Progress bar turns red +- Database not updated on cancellation + +### 4. **Automatic Error Detection** +- Detects when a label fails to print +- Automatically pauses the job +- Shows error message in log +- Progress bar turns red +- Prompts user to check printer + +### 5. **Automatic Recovery** +When a print error occurs: +1. Job pauses automatically +2. Error is logged with timestamp +3. User checks and fixes printer issue (refill paper, clear jam) +4. User clicks "Resume" +5. Failed label is automatically retried +6. If retry succeeds, continues with next label +7. If retry fails, user can cancel or try again + +### 6. **Smart Print Management** +- Tracks current label being printed +- Remembers last successfully printed label +- Maintains list of failed labels +- Prevents duplicate printing +- Sequential label numbering (CP00000777/001, 002, 003...) + +## Usage Instructions + +### Normal Printing Workflow + +1. **Start Print Job** + - Select an order from the table + - Click "Print Label (QZ Tray)" button + - Print Controller modal appears + +2. **Monitor Progress** + - Watch progress bar fill (green) + - Check "X / Y" counter + - Read status messages + - View timestamped log entries + +3. **Completion** + - All labels print successfully + - Database updates automatically + - Table refreshes to show new status + - Modal closes automatically + - Success notification appears + +### Handling Paper Running Out Mid-Print + +**Scenario**: Printing 20 labels, paper runs out after label 12 + +1. **Detection** + - Label 13 fails to print + - Controller detects error + - Job pauses automatically + - Progress bar turns red + - Log shows: "βœ— Label 13 failed: Print error" + - Status: "⚠️ ERROR - Check printer (paper jam/out of paper)" + +2. **User Action** + - Check printer + - See paper is empty + - Load new paper roll + - Ensure paper is feeding correctly + +3. **Resume Printing** + - Click "▢️ Resume" button + - Controller automatically retries label 13 + - Log shows: "Retrying label 13..." + - If successful: "βœ“ Label 13 printed successfully (retry)" + - Continues with labels 14-20 + - Job completes normally + +### Handling Print Quality Issues + +**Scenario**: Label 5 of 10 prints too light + +1. **During Print** + - Wait for label 5 to complete + - "πŸ”„ Reprint Last" button appears + - Click button + - Label 5 reprints with current settings + +2. **Adjust & Continue** + - Adjust printer darkness setting + - Click "▢️ Resume" if paused + - Continue printing labels 6-10 + +### Manual Pause for Inspection + +**Scenario**: Want to check label quality mid-batch + +1. Click "⏸️ Pause" button +2. Progress bar turns yellow +3. Remove and inspect last printed label +4. If good: Click "▢️ Resume" +5. If bad: + - Click "πŸ”„ Reprint Last" + - Adjust printer settings + - Click "▢️ Resume" + +### Emergency Cancellation + +**Scenario**: Wrong order selected or major printer malfunction + +1. Click "❌ Cancel" button +2. Printing stops immediately +3. Log shows labels completed (e.g., "7 of 25") +4. Progress bar turns red +5. Modal stays open for 2 seconds +6. Warning notification appears +7. Database NOT updated +8. Can reprint the order later + +## Technical Implementation + +### Print Controller State +```javascript +{ + isPaused: false, // Whether job is paused + isCancelled: false, // Whether job is cancelled + currentLabel: 0, // Current label number being printed + totalLabels: 0, // Total labels in job + lastPrintedLabel: 0, // Last successfully printed label + failedLabels: [], // Array of failed label numbers + orderData: null, // Order information + printerName: null // Selected printer name +} +``` + +### Event Log Format +``` +[17:47:15] Starting print job: 10 labels +[17:47:15] Printer: Thermal Printer A +[17:47:15] Order: CP00000777 +[17:47:16] Sending label 1 to printer... +[17:47:16] βœ“ Label 1 printed successfully +``` + +### Error Detection +- Try/catch around each print operation +- Errors trigger automatic pause +- Failed label number recorded +- Automatic retry on resume + +### Progress Calculation +```javascript +percentage = (currentLabel / totalLabels) * 100 +``` + +### Color States +- **Green**: Normal printing +- **Yellow**: Paused (manual or automatic) +- **Red**: Error or cancelled + +## Benefits + +1. βœ… **Prevents Wasted Labels**: Automatic recovery from errors +2. βœ… **Reduces Operator Stress**: Clear status and easy controls +3. βœ… **Handles Paper Depletion**: Auto-pause and retry on paper out +4. βœ… **Quality Control**: Easy reprint of damaged labels +5. βœ… **Transparency**: Full log of all print activities +6. βœ… **Flexibility**: Pause anytime for inspection +7. βœ… **Safety**: Cancel button for emergencies +8. βœ… **Accuracy**: Sequential numbering maintained even with errors + +## Common Scenarios Handled + +| Issue | Detection | Solution | +|-------|-----------|----------| +| Paper runs out | Print error on next label | Auto-pause, user refills, resume | +| Paper jam | Print error detected | Auto-pause, user clears jam, resume | +| Poor print quality | Visual inspection | Reprint last label | +| Wrong order selected | User realizes mid-print | Cancel job | +| Need to inspect labels | User decision | Pause, inspect, resume | +| Label falls on floor | Visual observation | Reprint last label | +| Printer offline | Print error | Auto-pause, user fixes, resume | + +## Future Enhancements (Possible) + +- Printer status monitoring (paper level, online/offline) +- Print queue for multiple orders +- Estimated time remaining +- Sound notifications on completion +- Email/SMS alerts for long jobs +- Print history logging to database +- Batch printing multiple orders +- Automatic printer reconnection + +## Testing Recommendations + +1. **Normal Job**: Print 5-10 labels, verify all complete +2. **Paper Depletion**: Remove paper mid-job, verify auto-pause and recovery +3. **Pause/Resume**: Manually pause mid-job, wait, resume +4. **Reprint**: Print job, reprint last label multiple times +5. **Cancel**: Start job, cancel after 2-3 labels +6. **Error Recovery**: Simulate error, verify automatic retry + +## Browser Compatibility + +- Chrome/Edge: βœ… Fully supported +- Firefox: βœ… Fully supported +- Safari: βœ… Fully supported +- Mobile browsers: ⚠️ Desktop recommended for QZ Tray + +## Support + +For issues or questions: +- Check browser console for detailed error messages +- Verify QZ Tray is running and connected +- Check printer is online and has paper +- Review print status log in modal +- Restart QZ Tray if connection issues persist diff --git a/py_app/app/templates/print_module.html b/py_app/app/templates/print_module.html index 5e73eeb..576e359 100644 --- a/py_app/app/templates/print_module.html +++ b/py_app/app/templates/print_module.html @@ -45,18 +45,22 @@ top: 0; width: 100%; height: 100%; - background-color: rgba(0, 0, 0, 0.6); + background-color: rgba(0, 0, 0, 0.7); justify-content: center; align-items: center; } +.print-progress-modal.show { + display: flex !important; +} + .print-progress-content { background-color: white; padding: 30px; - border-radius: 10px; - box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); - min-width: 400px; - max-width: 500px; + border-radius: 15px; + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4); + min-width: 500px; + max-width: 600px; text-align: center; } @@ -70,36 +74,131 @@ margin-bottom: 15px; color: #666; font-size: 16px; + min-height: 24px; } .progress-bar-container { width: 100%; - height: 30px; - background-color: #f0f0f0; - border-radius: 15px; + height: 35px; + background-color: #e9ecef; + border-radius: 18px; overflow: hidden; margin-bottom: 15px; - box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1); + box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15); + position: relative; } .progress-bar { height: 100%; - background: linear-gradient(90deg, #007bff 0%, #0056b3 100%); + background: linear-gradient(90deg, #28a745 0%, #20c997 100%); width: 0%; - transition: width 0.3s ease; - border-radius: 15px; + transition: width 0.4s ease; + border-radius: 18px; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; + font-size: 14px; +} + +.progress-bar.error { + background: linear-gradient(90deg, #dc3545 0%, #c82333 100%); +} + +.progress-bar.paused { + background: linear-gradient(90deg, #ffc107 0%, #ff9800 100%); } .progress-details { - font-size: 18px; + font-size: 20px; font-weight: bold; - color: #007bff; + color: #28a745; + margin-bottom: 15px; } + +.progress-details.error { + color: #dc3545; +} + +.print-status-log { + max-height: 150px; + overflow-y: auto; + background: #f8f9fa; + border: 1px solid #dee2e6; + border-radius: 8px; + padding: 10px; + margin: 15px 0; + text-align: left; + font-family: monospace; + font-size: 12px; +} + +.print-status-log div { + padding: 3px 0; + color: #495057; +} + +.print-status-log div.success { + color: #28a745; +} + +.print-status-log div.error { + color: #dc3545; + font-weight: bold; +} + +.print-status-log div.warning { + color: #ffc107; +} + +.print-control-buttons { + display: flex; + gap: 10px; + justify-content: center; + margin-top: 20px; +} + +.print-control-btn { + padding: 10px 20px; + border: none; + border-radius: 8px; + font-size: 14px; + font-weight: 600; + cursor: pointer; + transition: all 0.3s; +} + +.print-control-btn:hover { + transform: translateY(-2px); + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.print-control-btn.pause { + background: #ffc107; + color: #000; +} + +.print-control-btn.resume { + background: #28a745; + color: white; +} + +.print-control-btn.reprint { + background: #17a2b8; + color: white; +} + +.print-control-btn.cancel { + background: #dc3545; + color: white; +} + +.print-control-btn:disabled { + opacity: 0.5; + cursor: not-allowed; +} + {% endblock %} @@ -341,18 +440,39 @@ -