feat: Migrate label printing module from legacy app
- Created labels module with complete structure in app/modules/labels/ - Implemented print_module.py with database functions: * get_unprinted_orders_data() - Retrieve unprinted orders from database * get_printed_orders_data() - Retrieve printed orders from database * update_order_printed_status() - Mark orders as printed * search_orders_by_cp_code() - Search orders by production code - Created routes.py with Flask Blueprint and API endpoints: * GET /labels/ - Module home page with feature launchers * GET /labels/print-module - Main label printing interface * GET /labels/print-lost-labels - Lost label reprinting interface * GET /labels/api/unprinted-orders - API for unprinted orders * GET /labels/api/printed-orders - API for printed orders * POST /labels/api/search-orders - Search orders API * POST /labels/api/update-printed-status/<id> - Update status API - Migrated HTML templates from legacy app with theme support: * print_module.html - Thermal label printing with QZ Tray integration * print_lost_labels.html - Lost label search and reprint interface * Added comprehensive CSS variables for dark/light mode theming * Preserved all original JavaScript functionality for printing - Created index.html module home page with feature launchers - Registered labels blueprint in app/__init__.py with /labels prefix - Added 'Label Printing' module card to dashboard with print icon All functionality preserved from original implementation: - QZ Tray thermal printer integration - JsBarcode barcode generation (horizontal + vertical) - PDF export fallback - Session-based authentication for all routes - Database integration with proper error handling
This commit is contained in:
@@ -143,14 +143,16 @@ def register_blueprints(app):
|
||||
from app.modules.settings.routes import settings_bp
|
||||
from app.modules.warehouse.routes import warehouse_bp
|
||||
from app.modules.warehouse.boxes_routes import boxes_bp
|
||||
from app.modules.labels.routes import labels_bp
|
||||
|
||||
app.register_blueprint(main_bp)
|
||||
app.register_blueprint(quality_bp, url_prefix='/quality')
|
||||
app.register_blueprint(settings_bp, url_prefix='/settings')
|
||||
app.register_blueprint(warehouse_bp, url_prefix='/warehouse')
|
||||
app.register_blueprint(boxes_bp)
|
||||
app.register_blueprint(labels_bp, url_prefix='/labels')
|
||||
|
||||
app.logger.info("Blueprints registered: main, quality, settings, warehouse, boxes")
|
||||
app.logger.info("Blueprints registered: main, quality, settings, warehouse, boxes, labels")
|
||||
|
||||
|
||||
def register_error_handlers(app):
|
||||
|
||||
2
app/modules/labels/__init__.py
Normal file
2
app/modules/labels/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# Labels Module
|
||||
# Handles label printing and management for thermal printers
|
||||
200
app/modules/labels/print_module.py
Normal file
200
app/modules/labels/print_module.py
Normal file
@@ -0,0 +1,200 @@
|
||||
"""
|
||||
Labels Module - Print Module Functions
|
||||
Handles retrieval of orders for label printing
|
||||
"""
|
||||
import logging
|
||||
from app.database import get_db
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_unprinted_orders_data(limit=100):
|
||||
"""
|
||||
Retrieve unprinted orders from the database for label printing
|
||||
Returns list of order dictionaries where printed_labels != 1
|
||||
"""
|
||||
try:
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if order_for_labels table exists
|
||||
cursor.execute("SHOW TABLES LIKE 'order_for_labels'")
|
||||
if not cursor.fetchone():
|
||||
logger.warning("order_for_labels table does not exist")
|
||||
return []
|
||||
|
||||
# Check if printed_labels column exists
|
||||
cursor.execute("SHOW COLUMNS FROM order_for_labels LIKE 'printed_labels'")
|
||||
column_exists = cursor.fetchone()
|
||||
|
||||
if column_exists:
|
||||
# Use printed_labels column
|
||||
cursor.execute("""
|
||||
SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate,
|
||||
com_achiz_client, nr_linie_com_client, customer_name,
|
||||
customer_article_number, open_for_order, line_number,
|
||||
created_at, updated_at, printed_labels, data_livrare, dimensiune
|
||||
FROM order_for_labels
|
||||
WHERE printed_labels IS NULL OR printed_labels = 0
|
||||
ORDER BY created_at DESC
|
||||
LIMIT %s
|
||||
""", (limit,))
|
||||
else:
|
||||
# Fallback: get all orders if no printed_labels column
|
||||
cursor.execute("""
|
||||
SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate,
|
||||
com_achiz_client, nr_linie_com_client, customer_name,
|
||||
customer_article_number, open_for_order, line_number,
|
||||
created_at, updated_at, 0 as printed_labels, data_livrare, dimensiune
|
||||
FROM order_for_labels
|
||||
ORDER BY created_at DESC
|
||||
LIMIT %s
|
||||
""", (limit,))
|
||||
|
||||
columns = [col[0] for col in cursor.description]
|
||||
orders = []
|
||||
|
||||
for row in cursor.fetchall():
|
||||
order_dict = {columns[i]: row[i] for i in range(len(columns))}
|
||||
# Ensure date fields are strings
|
||||
if order_dict.get('created_at'):
|
||||
order_dict['created_at'] = str(order_dict['created_at'])
|
||||
if order_dict.get('updated_at'):
|
||||
order_dict['updated_at'] = str(order_dict['updated_at'])
|
||||
if order_dict.get('data_livrare'):
|
||||
order_dict['data_livrare'] = str(order_dict['data_livrare'])
|
||||
orders.append(order_dict)
|
||||
|
||||
cursor.close()
|
||||
logger.info(f"Retrieved {len(orders)} unprinted orders")
|
||||
return orders
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error retrieving unprinted orders: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_printed_orders_data(limit=100):
|
||||
"""
|
||||
Retrieve printed orders from the database
|
||||
Returns list of order dictionaries where printed_labels = 1
|
||||
"""
|
||||
try:
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if order_for_labels table exists
|
||||
cursor.execute("SHOW TABLES LIKE 'order_for_labels'")
|
||||
if not cursor.fetchone():
|
||||
logger.warning("order_for_labels table does not exist")
|
||||
return []
|
||||
|
||||
# Check if printed_labels column exists
|
||||
cursor.execute("SHOW COLUMNS FROM order_for_labels LIKE 'printed_labels'")
|
||||
column_exists = cursor.fetchone()
|
||||
|
||||
if column_exists:
|
||||
# Get orders where printed_labels = 1
|
||||
cursor.execute("""
|
||||
SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate,
|
||||
com_achiz_client, nr_linie_com_client, customer_name,
|
||||
customer_article_number, open_for_order, line_number,
|
||||
created_at, updated_at, printed_labels, data_livrare, dimensiune
|
||||
FROM order_for_labels
|
||||
WHERE printed_labels = 1
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT %s
|
||||
""", (limit,))
|
||||
else:
|
||||
# Fallback: no printed orders if column doesn't exist
|
||||
logger.info("printed_labels column does not exist - no printed orders available")
|
||||
cursor.close()
|
||||
return []
|
||||
|
||||
columns = [col[0] for col in cursor.description]
|
||||
orders = []
|
||||
|
||||
for row in cursor.fetchall():
|
||||
order_dict = {columns[i]: row[i] for i in range(len(columns))}
|
||||
# Ensure date fields are strings
|
||||
if order_dict.get('created_at'):
|
||||
order_dict['created_at'] = str(order_dict['created_at'])
|
||||
if order_dict.get('updated_at'):
|
||||
order_dict['updated_at'] = str(order_dict['updated_at'])
|
||||
if order_dict.get('data_livrare'):
|
||||
order_dict['data_livrare'] = str(order_dict['data_livrare'])
|
||||
orders.append(order_dict)
|
||||
|
||||
cursor.close()
|
||||
logger.info(f"Retrieved {len(orders)} printed orders")
|
||||
return orders
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error retrieving printed orders: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def update_order_printed_status(order_id, printed=True):
|
||||
"""
|
||||
Update the printed_labels status for an order
|
||||
"""
|
||||
try:
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
UPDATE order_for_labels
|
||||
SET printed_labels = %s
|
||||
WHERE id = %s
|
||||
""", (1 if printed else 0, order_id))
|
||||
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
logger.info(f"Updated order {order_id} printed status to {printed}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating order printed status: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def search_orders_by_cp_code(cp_code_search):
|
||||
"""
|
||||
Search for orders by CP code / Production Order
|
||||
"""
|
||||
try:
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
search_term = cp_code_search.strip().upper()
|
||||
|
||||
cursor.execute("""
|
||||
SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate,
|
||||
com_achiz_client, nr_linie_com_client, customer_name,
|
||||
customer_article_number, open_for_order, line_number,
|
||||
created_at, updated_at, printed_labels, data_livrare, dimensiune
|
||||
FROM order_for_labels
|
||||
WHERE UPPER(comanda_productie) LIKE %s
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 100
|
||||
""", (f"{search_term}%",))
|
||||
|
||||
columns = [col[0] for col in cursor.description]
|
||||
orders = []
|
||||
|
||||
for row in cursor.fetchall():
|
||||
order_dict = {columns[i]: row[i] for i in range(len(columns))}
|
||||
if order_dict.get('created_at'):
|
||||
order_dict['created_at'] = str(order_dict['created_at'])
|
||||
if order_dict.get('updated_at'):
|
||||
order_dict['updated_at'] = str(order_dict['updated_at'])
|
||||
if order_dict.get('data_livrare'):
|
||||
order_dict['data_livrare'] = str(order_dict['data_livrare'])
|
||||
orders.append(order_dict)
|
||||
|
||||
cursor.close()
|
||||
return orders
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error searching orders by CP code: {e}")
|
||||
return []
|
||||
128
app/modules/labels/routes.py
Normal file
128
app/modules/labels/routes.py
Normal file
@@ -0,0 +1,128 @@
|
||||
"""
|
||||
Labels Module Routes
|
||||
Handles label printing pages and API endpoints
|
||||
"""
|
||||
from flask import Blueprint, render_template, session, redirect, url_for, jsonify, request
|
||||
import logging
|
||||
|
||||
from .print_module import (
|
||||
get_unprinted_orders_data,
|
||||
get_printed_orders_data,
|
||||
update_order_printed_status,
|
||||
search_orders_by_cp_code
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
labels_bp = Blueprint('labels', __name__, url_prefix='/labels')
|
||||
|
||||
|
||||
@labels_bp.route('/', methods=['GET'])
|
||||
def labels_index():
|
||||
"""Labels module home page"""
|
||||
if 'user_id' not in session:
|
||||
return redirect(url_for('main.login'))
|
||||
|
||||
return render_template('modules/labels/index.html')
|
||||
|
||||
|
||||
@labels_bp.route('/print-module', methods=['GET'])
|
||||
def print_module():
|
||||
"""Label printing interface with thermal printer support"""
|
||||
if 'user_id' not in session:
|
||||
return redirect(url_for('main.login'))
|
||||
|
||||
return render_template('modules/labels/print_module.html')
|
||||
|
||||
|
||||
@labels_bp.route('/print-lost-labels', methods=['GET'])
|
||||
def print_lost_labels():
|
||||
"""Print lost/missing labels interface"""
|
||||
if 'user_id' not in session:
|
||||
return redirect(url_for('main.login'))
|
||||
|
||||
return render_template('modules/labels/print_lost_labels.html')
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# API Endpoints for Labels Module
|
||||
# ============================================================================
|
||||
|
||||
@labels_bp.route('/api/unprinted-orders', methods=['GET'], endpoint='api_unprinted_orders')
|
||||
def api_unprinted_orders():
|
||||
"""Get all unprinted orders for label printing"""
|
||||
if 'user_id' not in session:
|
||||
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
|
||||
|
||||
try:
|
||||
limit = request.args.get('limit', 100, type=int)
|
||||
if limit > 500:
|
||||
limit = 500
|
||||
if limit < 1:
|
||||
limit = 1
|
||||
|
||||
orders = get_unprinted_orders_data(limit)
|
||||
return jsonify({'success': True, 'orders': orders, 'count': len(orders)}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting unprinted orders: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@labels_bp.route('/api/printed-orders', methods=['GET'], endpoint='api_printed_orders')
|
||||
def api_printed_orders():
|
||||
"""Get all printed orders"""
|
||||
if 'user_id' not in session:
|
||||
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
|
||||
|
||||
try:
|
||||
limit = request.args.get('limit', 100, type=int)
|
||||
if limit > 500:
|
||||
limit = 500
|
||||
if limit < 1:
|
||||
limit = 1
|
||||
|
||||
orders = get_printed_orders_data(limit)
|
||||
return jsonify({'success': True, 'orders': orders, 'count': len(orders)}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting printed orders: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@labels_bp.route('/api/search-orders', methods=['POST'], endpoint='api_search_orders')
|
||||
def api_search_orders():
|
||||
"""Search for orders by CP code"""
|
||||
if 'user_id' not in session:
|
||||
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
|
||||
|
||||
try:
|
||||
data = request.get_json()
|
||||
cp_code = data.get('cp_code', '').strip()
|
||||
|
||||
if not cp_code or len(cp_code) < 1:
|
||||
return jsonify({'success': False, 'error': 'CP code is required'}), 400
|
||||
|
||||
results = search_orders_by_cp_code(cp_code)
|
||||
return jsonify({'success': True, 'orders': results, 'count': len(results)}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error searching orders: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@labels_bp.route('/api/update-printed-status/<int:order_id>', methods=['POST'], endpoint='api_update_printed_status')
|
||||
def api_update_printed_status(order_id):
|
||||
"""Mark an order as printed"""
|
||||
if 'user_id' not in session:
|
||||
return jsonify({'success': False, 'error': 'Unauthorized'}), 401
|
||||
|
||||
try:
|
||||
data = request.get_json() or {}
|
||||
printed = data.get('printed', True)
|
||||
|
||||
success = update_order_printed_status(order_id, printed)
|
||||
if success:
|
||||
return jsonify({'success': True, 'message': 'Order status updated'}), 200
|
||||
else:
|
||||
return jsonify({'success': False, 'error': 'Failed to update order'}), 500
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating order status: {e}")
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
@@ -86,6 +86,13 @@ def dashboard():
|
||||
'color': 'info',
|
||||
'url': url_for('warehouse.warehouse_index')
|
||||
},
|
||||
{
|
||||
'name': 'Label Printing',
|
||||
'description': 'Print and manage thermal labels for orders',
|
||||
'icon': 'fa-print',
|
||||
'color': 'success',
|
||||
'url': url_for('labels.labels_index')
|
||||
},
|
||||
{
|
||||
'name': 'Settings',
|
||||
'description': 'Configure application settings',
|
||||
|
||||
105
app/templates/modules/labels/index.html
Normal file
105
app/templates/modules/labels/index.html
Normal file
@@ -0,0 +1,105 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Labels Module - Quality App v2{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container-fluid py-5">
|
||||
<div class="row mb-4">
|
||||
<div class="col-12">
|
||||
<h1 class="mb-2">
|
||||
<i class="fas fa-print"></i> Labels Module
|
||||
</h1>
|
||||
<p class="text-muted">Manage and print labels for thermal printers</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Print Module Card -->
|
||||
<div class="col-md-6 col-lg-4 mb-4">
|
||||
<div class="card shadow-sm h-100 module-launcher">
|
||||
<div class="card-body text-center">
|
||||
<div class="launcher-icon mb-3">
|
||||
<i class="fas fa-print text-primary"></i>
|
||||
</div>
|
||||
<h5 class="card-title">Print Labels</h5>
|
||||
<p class="card-text text-muted">Print labels directly to thermal printers with live preview.</p>
|
||||
<a href="{{ url_for('labels.print_module') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-arrow-right"></i> Open Printing
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Print Lost Labels Card -->
|
||||
<div class="col-md-6 col-lg-4 mb-4">
|
||||
<div class="card shadow-sm h-100 module-launcher">
|
||||
<div class="card-body text-center">
|
||||
<div class="launcher-icon mb-3">
|
||||
<i class="fas fa-file-pdf text-danger"></i>
|
||||
</div>
|
||||
<h5 class="card-title">Print Lost Labels</h5>
|
||||
<p class="card-text text-muted">Search and reprint labels for orders that need reprinting.</p>
|
||||
<a href="{{ url_for('labels.print_lost_labels') }}" class="btn btn-danger btn-sm">
|
||||
<i class="fas fa-arrow-right"></i> Reprint Labels
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Module Overview Section -->
|
||||
<div class="row mt-5">
|
||||
<div class="col-12">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-light">
|
||||
<h5 class="mb-0"><i class="fas fa-info-circle"></i> Module Overview</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h6><i class="fas fa-check-circle text-success"></i> Key Features:</h6>
|
||||
<ul class="text-muted">
|
||||
<li>Real-time label preview</li>
|
||||
<li>Direct thermal printer integration</li>
|
||||
<li>PDF export fallback</li>
|
||||
<li>Batch label printing</li>
|
||||
<li>QZ Tray support for Windows/Mac/Linux</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h6><i class="fas fa-chart-pie text-primary"></i> Supported Printers:</h6>
|
||||
<ul class="text-muted">
|
||||
<li>Zebra thermal printers</li>
|
||||
<li>Epson TM series</li>
|
||||
<li>Brother thermal printers</li>
|
||||
<li>Generic thermal printers via QZ Tray</li>
|
||||
<li>PDF export for any printer</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.module-launcher {
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.module-launcher:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
|
||||
}
|
||||
|
||||
.launcher-icon {
|
||||
font-size: 48px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.launcher-icon i {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
985
app/templates/modules/labels/print_lost_labels.html
Normal file
985
app/templates/modules/labels/print_lost_labels.html
Normal file
@@ -0,0 +1,985 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<!-- Print Lost Labels CSS with theme support -->
|
||||
<style>
|
||||
/* Print Module Theme Support */
|
||||
.scan-container {
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
.card.search-card,
|
||||
.card.scan-form-card,
|
||||
.card.scan-table-card {
|
||||
background-color: var(--bg-primary);
|
||||
border-color: var(--border-color);
|
||||
color: var(--text-primary);
|
||||
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.scan-table {
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.scan-table thead th {
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-color);
|
||||
}
|
||||
|
||||
.scan-table tbody td {
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-color);
|
||||
}
|
||||
|
||||
.scan-table tbody tr:hover {
|
||||
background-color: rgba(13, 110, 253, 0.08);
|
||||
}
|
||||
|
||||
.form-control,
|
||||
.form-control-sm,
|
||||
select {
|
||||
background-color: var(--input-bg);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--input-border);
|
||||
}
|
||||
|
||||
.form-control:focus,
|
||||
.form-control-sm:focus,
|
||||
select:focus {
|
||||
background-color: var(--input-bg);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--input-focus-border);
|
||||
box-shadow: 0 0 0 3px var(--input-focus-shadow);
|
||||
}
|
||||
|
||||
.floating-help-btn {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.floating-help-btn a {
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-color: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border-radius: 50%;
|
||||
text-align: center;
|
||||
line-height: 50px;
|
||||
font-size: 24px;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.floating-help-btn a:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
/* Compact table styling for print_lost_labels page */
|
||||
.print-lost-labels-compact .scan-table.print-module-table {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.print-lost-labels-compact .scan-table.print-module-table thead th {
|
||||
font-size: 10px;
|
||||
padding: 6px 8px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody td {
|
||||
font-size: 9px;
|
||||
padding: 4px 6px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
/* Keep important data slightly larger and bold */
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody td:nth-child(2) {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Make numbers more compact */
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody td:nth-child(5),
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody td:nth-child(9),
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody td:nth-child(13) {
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
/* Reduce row height */
|
||||
.print-lost-labels-compact .scan-table.print-module-table tbody tr {
|
||||
height: auto;
|
||||
min-height: 24px;
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- Floating Help Button -->
|
||||
<div class="floating-help-btn">
|
||||
<a href="{{ url_for('labels.help', page='print_lost_labels') }}" target="_blank" title="Print Lost Labels Help">
|
||||
📖
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- ROW 1: Search Card (full width) -->
|
||||
<div class="scan-container lost-labels print-lost-labels-compact">
|
||||
<div class="card search-card">
|
||||
<div style="display: flex; align-items: center; gap: 15px; flex-wrap: wrap;">
|
||||
<label for="search-input" style="font-weight: bold; white-space: nowrap;">Search Order (CP...):</label>
|
||||
<input type="text" id="search-input" class="search-field" placeholder="Type to search..." oninput="searchOrder()" style="flex: 1; min-width: 200px; max-width: 300px;">
|
||||
<button id="fetch-matching-btn" class="btn btn-secondary" style="padding: 7px 16px; font-size: 14px; white-space: nowrap;" onclick="fetchMatchingOrders()">Find All</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ROW 2: Two cards side by side (25% / 75% layout) -->
|
||||
<div class="row-container">
|
||||
<!-- Print Preview Card (left, 25% width) -->
|
||||
<div class="card scan-form-card" style="display: flex; flex-direction: column; justify-content: flex-start; align-items: center; min-height: 700px; flex: 0 0 25%; position: relative; padding: 15px;">
|
||||
<div class="label-view-title" style="width: 100%; text-align: center; padding: 0 0 15px 0; font-size: 18px; font-weight: bold; letter-spacing: 0.5px;">Label View</div>
|
||||
<!-- Pairing Keys Section -->
|
||||
<div style="width: 100%; text-align: center; margin-bottom: 15px;">
|
||||
<div id="client-select-container" style="display: none; margin-bottom: 8px;">
|
||||
<label for="client-select" style="font-size: 11px; font-weight: 600; display: block; margin-bottom: 4px;">Select Printer/Client:</label>
|
||||
<select id="client-select" class="form-control form-control-sm" style="width: 85%; margin: 0 auto; font-size: 11px;"></select>
|
||||
</div>
|
||||
<!-- Manage Keys Button - Only visible for superadmin -->
|
||||
{% if session.role == 'superadmin' %}
|
||||
<a href="{{ url_for('main.download_extension') }}" class="btn btn-info btn-sm" target="_blank" style="font-size: 11px; padding: 4px 12px;">🔑 Manage Keys</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- Label Preview Section -->
|
||||
<div id="label-preview" style="padding: 10px; position: relative; background: #fafafa; width: 301px; height: 434.7px;">
|
||||
<!-- ...label content rectangle and barcode frames as in print_module.html... -->
|
||||
<div id="label-content" style="position: absolute; top: 65.7px; left: 11.34px; width: 227.4px; height: 321.3px; background: white;">
|
||||
<div style="position: absolute; top: 0; left: 0; right: 0; height: 32.13px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 12px; color: #000; z-index: 10;"></div>
|
||||
<div id="customer-name-row" style="position: absolute; top: 32.13px; left: 0; right: 0; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 11px; color: #000;"></div>
|
||||
<div style="position: absolute; top: 32.13px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 64.26px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 96.39px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 128.52px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 160.65px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 224.91px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 257.04px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 289.17px; left: 0; right: 0; height: 1px; background: #999;"></div>
|
||||
<div style="position: absolute; left: 90.96px; top: 64.26px; width: 1px; height: 257.04px; background: #999;"></div>
|
||||
<div style="position: absolute; top: 64.26px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Quantity ordered</div>
|
||||
<div id="quantity-ordered-value" style="position: absolute; top: 64.26px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: bold; color: #000;"></div>
|
||||
<div style="position: absolute; top: 96.39px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Customer order</div>
|
||||
<div id="client-order-info" style="position: absolute; top: 96.39px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; color: #000;"></div>
|
||||
<div style="position: absolute; top: 128.52px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Delivery date</div>
|
||||
<div id="delivery-date-value" style="position: absolute; top: 128.52px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; color: #000;"></div>
|
||||
<div style="position: absolute; top: 160.65px; left: 0; width: 90.96px; height: 64.26px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Product description</div>
|
||||
<div id="description-value" style="position: absolute; top: 160.65px; left: 90.96px; width: 136.44px; height: 64.26px; display: flex; align-items: center; justify-content: center; font-size: 8px; color: #000; text-align: center; padding: 2px; overflow: hidden;"></div>
|
||||
<div style="position: absolute; top: 224.91px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Size</div>
|
||||
<div id="size-value" style="position: absolute; top: 224.91px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: bold; color: #000;"></div>
|
||||
<div style="position: absolute; top: 257.04px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Article code</div>
|
||||
<div id="article-code-value" style="position: absolute; top: 257.04px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: bold; color: #000;"></div>
|
||||
<div style="position: absolute; top: 289.17px; left: 0; width: 90.96px; height: 32.13px; display: flex; align-items: center; padding-left: 5px; font-size: 10px; color: #000;">Prod. order</div>
|
||||
<div id="prod-order-value" style="position: absolute; top: 289.17px; left: 90.96px; width: 136.44px; height: 32.13px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: bold; color: #000;"></div>
|
||||
</div>
|
||||
<div id="barcode-frame">
|
||||
<svg id="barcode-display"></svg>
|
||||
<div id="barcode-text"></div>
|
||||
</div>
|
||||
<div id="vertical-barcode-frame">
|
||||
<svg id="vertical-barcode-display"></svg>
|
||||
<div id="vertical-barcode-text"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Print Options (copied from print_module.html) -->
|
||||
<div style="width: 100%; margin-top: 20px;">
|
||||
<!-- Print Method Selection -->
|
||||
<div style="margin-bottom: 15px;" role="group" aria-labelledby="print-method-label">
|
||||
<div id="print-method-label" style="font-size: 12px; font-weight: 600; color: #495057; margin-bottom: 8px;">
|
||||
📄 Print Method:
|
||||
</div>
|
||||
|
||||
<!-- Print method options in horizontal layout -->
|
||||
<div style="display: flex; gap: 15px; flex-wrap: wrap;">
|
||||
<div class="form-check" style="margin-bottom: 6px;">
|
||||
<input class="form-check-input" type="radio" name="printMethod" id="qzTrayPrint" value="qztray" checked>
|
||||
<label class="form-check-label" for="qzTrayPrint" style="font-size: 11px; line-height: 1.2;">
|
||||
<strong>🖨️ Direct Print</strong> <span id="qztray-status" class="badge badge-success" style="font-size: 9px; padding: 2px 6px;">Ready</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check" id="pdf-option-container" style="display: none; margin-bottom: 6px;">
|
||||
<input class="form-check-input" type="radio" name="printMethod" id="pdfGenerate" value="pdf">
|
||||
<label class="form-check-label" for="pdfGenerate" style="font-size: 11px; line-height: 1.2;">
|
||||
<strong>📄 PDF Export</strong> <span class="text-muted" style="font-size: 10px;">(fallback)</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Printer Selection for QZ Tray (Compact) -->
|
||||
<div id="qztray-printer-selection" style="margin-bottom: 10px;">
|
||||
<label for="qztray-printer-select" style="font-size: 11px; font-weight: 600; color: #495057; margin-bottom: 3px; display: block;">
|
||||
Printer:
|
||||
</label>
|
||||
<select id="qztray-printer-select" class="form-control form-control-sm" style="font-size: 11px; padding: 3px 6px;">
|
||||
<option value="">Loading...</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Labels Range Selection -->
|
||||
<div style="margin-bottom: 15px;">
|
||||
<label for="labels-range-input" style="font-size: 11px; font-weight: 600; color: #495057; margin-bottom: 3px; display: block;">
|
||||
Select Labels Range:
|
||||
</label>
|
||||
<input type="text" id="labels-range-input" class="form-control form-control-sm"
|
||||
placeholder="e.g., 003 or 003-007"
|
||||
style="font-size: 11px; padding: 3px 6px; text-align: center;">
|
||||
<div style="font-size: 9px; color: #6c757d; margin-top: 2px; text-align: center;">
|
||||
Single: "005" | Range: "003-007" | Leave empty for all
|
||||
</div>
|
||||
</div>
|
||||
<!-- Print Button -->
|
||||
<div style="width: 100%; text-align: center; margin-bottom: 10px;">
|
||||
<button id="print-label-btn" class="btn btn-success" style="font-size: 13px; padding: 8px 24px; border-radius: 5px; font-weight: 600;">
|
||||
🖨️ Print Labels
|
||||
</button>
|
||||
</div>
|
||||
<!-- Print Information -->
|
||||
<div style="width: 100%; text-align: center; color: #6c757d; font-size: 10px; line-height: 1.3;">
|
||||
<small>(e.g., CP00000711-001, 002, ...)</small>
|
||||
</div>
|
||||
<!-- QZ Tray Installation Info - Simplified -->
|
||||
<div id="qztray-info" style="width: 100%; margin-top: 15px; padding-top: 15px; border-top: 1px solid #e9ecef;">
|
||||
<div style="background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 10px; text-align: center;">
|
||||
<div style="font-size: 10px; color: #495057; margin-bottom: 8px;">
|
||||
QZ Tray is required for direct printing
|
||||
</div>
|
||||
<a href="https://filebrowser.moto-adv.com/filebrowser/api/public/dl/Fk0ZaiEY/QP_Tray/qz-tray-2.2.6-SNAPSHOT-x86_64.exe?token=TJ7gSu3CRcWWQuyFLoZv5I8j4diDjP47DDqWRtM0oKAx-2_orj1stfKPJsuuqKR9mE2GQNm1jlZ0BPR7lfZ3gHmu56SkY9fC5AJlC9n_80oX643ojlGc-U7XVb1SDd0w" class="btn btn-outline-secondary btn-sm" style="font-size: 10px; padding: 4px 16px;">
|
||||
📥 Download QZ Tray
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Orders Table Card (right, 75% width) -->
|
||||
<div class="card scan-table-card" style="min-height: 700px; flex: 0 0 75%; margin: 0;">
|
||||
<h3>Data Preview</h3>
|
||||
<div class="report-table-container">
|
||||
<table class="scan-table print-module-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Comanda Productie</th>
|
||||
<th>Cod Articol</th>
|
||||
<th>Descr. Com. Prod</th>
|
||||
<th>Cantitate</th>
|
||||
<th>Data Livrare</th>
|
||||
<th>Dimensiune</th>
|
||||
<th>Com. Achiz. Client</th>
|
||||
<th>Nr. Linie</th>
|
||||
<th>Customer Name</th>
|
||||
<th>Customer Art. Nr.</th>
|
||||
<th>Open Order</th>
|
||||
<th>Line</th>
|
||||
<th>Printed</th>
|
||||
<th>Created</th>
|
||||
<th>Qty to Print</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="unprinted-orders-table">
|
||||
<!-- Data will be dynamically loaded here -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- JavaScript Libraries -->
|
||||
<!-- JsBarcode library for real barcode generation -->
|
||||
<script src="{{ url_for('static', filename='JsBarcode.all.min.js') }}"></script>
|
||||
<!-- Add html2canvas library for capturing preview as image -->
|
||||
<script src="{{ url_for('static', filename='html2canvas.min.js') }}"></script>
|
||||
<!-- PATCHED QZ Tray library - works with custom server using pairing key authentication -->
|
||||
<script src="{{ url_for('static', filename='qz-tray.js') }}"></script>
|
||||
<script>
|
||||
|
||||
// Store all orders data for searching
|
||||
const allOrders = {{ orders|tojson|safe }};
|
||||
let selectedOrderData = null;
|
||||
|
||||
// QZ Tray Integration
|
||||
let qzTray = null;
|
||||
let availablePrinters = [];
|
||||
|
||||
// Function to display the last N orders in the table
|
||||
function displayRecentOrders(limit = 20) {
|
||||
const tbody = document.getElementById('unprinted-orders-table');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
if (allOrders.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="16" style="text-align:center; color:#6c757d;">No printed orders found.</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the last N orders (they are already sorted by updated_at DESC from backend)
|
||||
const recentOrders = allOrders.slice(0, limit);
|
||||
|
||||
recentOrders.forEach((order, idx) => {
|
||||
const tr = document.createElement('tr');
|
||||
|
||||
// Format data_livrare as DD/MM/YYYY if possible
|
||||
let dataLivrareFormatted = '-';
|
||||
if (order.data_livrare) {
|
||||
const d = new Date(order.data_livrare);
|
||||
if (!isNaN(d)) {
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
dataLivrareFormatted = `${day}/${month}/${year}`;
|
||||
} else {
|
||||
dataLivrareFormatted = order.data_livrare;
|
||||
}
|
||||
}
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>${order.id}</td>
|
||||
<td><strong>${order.comanda_productie}</strong></td>
|
||||
<td>${order.cod_articol || '-'}</td>
|
||||
<td>${order.descr_com_prod}</td>
|
||||
<td style="text-align: right; font-weight: 600;">${order.cantitate}</td>
|
||||
<td style="text-align: center;">${dataLivrareFormatted}</td>
|
||||
<td style="text-align: center;">${order.dimensiune || '-'}</td>
|
||||
<td>${order.com_achiz_client || '-'}</td>
|
||||
<td style="text-align: right;">${order.nr_linie_com_client || '-'}</td>
|
||||
<td>${order.customer_name || '-'}</td>
|
||||
<td>${order.customer_article_number || '-'}</td>
|
||||
<td>${order.open_for_order || '-'}</td>
|
||||
<td style="text-align: right;">${order.line_number || '-'}</td>
|
||||
<td style="text-align: center;">${order.printed_labels == 1 ? '<span style="color: #28a745; font-weight: bold;">✓ Yes</span>' : '<span style="color: #dc3545;">✗ No</span>'}</td>
|
||||
<td style="font-size: 11px; color: #6c757d;">${order.created_at || '-'}</td>
|
||||
<td>1</td>
|
||||
`;
|
||||
|
||||
tr.addEventListener('click', function() {
|
||||
document.querySelectorAll('.print-module-table tbody tr').forEach(row => {
|
||||
row.classList.remove('selected');
|
||||
const cells = row.querySelectorAll('td');
|
||||
cells.forEach(cell => {
|
||||
cell.style.backgroundColor = '';
|
||||
cell.style.color = '';
|
||||
});
|
||||
});
|
||||
this.classList.add('selected');
|
||||
const cells = this.querySelectorAll('td');
|
||||
cells.forEach(cell => {
|
||||
cell.style.backgroundColor = '#007bff';
|
||||
cell.style.color = 'white';
|
||||
});
|
||||
updatePreviewCard(order);
|
||||
});
|
||||
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
function searchOrder() {
|
||||
const searchValue = document.getElementById('search-input').value.trim().toLowerCase();
|
||||
if (!searchValue) {
|
||||
selectedOrderData = null;
|
||||
return;
|
||||
}
|
||||
// Search for matching order
|
||||
const matchedOrder = allOrders.find(order =>
|
||||
order.comanda_productie && order.comanda_productie.toLowerCase().includes(searchValue)
|
||||
);
|
||||
if (matchedOrder) {
|
||||
selectedOrderData = matchedOrder;
|
||||
} else {
|
||||
selectedOrderData = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all matching orders and populate preview table
|
||||
function fetchMatchingOrders() {
|
||||
const searchValue = document.getElementById('search-input').value.trim().toLowerCase();
|
||||
if (!searchValue) {
|
||||
alert('Please enter an order code to search.');
|
||||
return;
|
||||
}
|
||||
// Find all matching orders
|
||||
const matchingOrders = allOrders.filter(order =>
|
||||
order.comanda_productie && order.comanda_productie.toLowerCase().includes(searchValue)
|
||||
);
|
||||
const tbody = document.getElementById('unprinted-orders-table');
|
||||
tbody.innerHTML = '';
|
||||
if (matchingOrders.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="16" style="text-align:center; color:#dc3545;">No matching orders found.</td></tr>';
|
||||
// Clear preview card
|
||||
updatePreviewCard(null);
|
||||
return;
|
||||
}
|
||||
matchingOrders.forEach((order, idx) => {
|
||||
const tr = document.createElement('tr');
|
||||
// Format data_livrare as DD/MM/YYYY if possible
|
||||
let dataLivrareFormatted = '-';
|
||||
if (order.data_livrare) {
|
||||
const d = new Date(order.data_livrare);
|
||||
if (!isNaN(d)) {
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
dataLivrareFormatted = `${day}/${month}/${year}`;
|
||||
} else {
|
||||
dataLivrareFormatted = order.data_livrare;
|
||||
}
|
||||
}
|
||||
tr.innerHTML = `
|
||||
<td>${order.id}</td>
|
||||
<td><strong>${order.comanda_productie}</strong></td>
|
||||
<td>${order.cod_articol || '-'}</td>
|
||||
<td>${order.descr_com_prod}</td>
|
||||
<td style="text-align: right; font-weight: 600;">${order.cantitate}</td>
|
||||
<td style="text-align: center;">${dataLivrareFormatted}</td>
|
||||
<td style="text-align: center;">${order.dimensiune || '-'}</td>
|
||||
<td>${order.com_achiz_client || '-'}</td>
|
||||
<td style="text-align: right;">${order.nr_linie_com_client || '-'}</td>
|
||||
<td>${order.customer_name || '-'}</td>
|
||||
<td>${order.customer_article_number || '-'}</td>
|
||||
<td>${order.open_for_order || '-'}</td>
|
||||
<td style="text-align: right;">${order.line_number || '-'}</td>
|
||||
<td style="text-align: center;">${order.printed_labels == 1 ? '<span style=\"color: #28a745; font-weight: bold;\">✓ Yes</span>' : '<span style=\"color: #dc3545;\">✗ No</span>'}</td>
|
||||
<td style="font-size: 11px; color: #6c757d;">${order.created_at || '-'}</td>
|
||||
<td>1</td>
|
||||
`;
|
||||
tr.addEventListener('click', function() {
|
||||
document.querySelectorAll('.print-module-table tbody tr').forEach(row => {
|
||||
row.classList.remove('selected');
|
||||
const cells = row.querySelectorAll('td');
|
||||
cells.forEach(cell => {
|
||||
cell.style.backgroundColor = '';
|
||||
cell.style.color = '';
|
||||
});
|
||||
});
|
||||
this.classList.add('selected');
|
||||
const cells = this.querySelectorAll('td');
|
||||
cells.forEach(cell => {
|
||||
cell.style.backgroundColor = '#007bff';
|
||||
cell.style.color = 'white';
|
||||
});
|
||||
updatePreviewCard(order);
|
||||
});
|
||||
tbody.appendChild(tr);
|
||||
// Update preview card with the first matching order
|
||||
if (idx === 0) updatePreviewCard(order);
|
||||
});
|
||||
}
|
||||
|
||||
// QZ Tray and Print Button Logic (copied/adapted from print_module.html)
|
||||
async function initializeQZTray() {
|
||||
try {
|
||||
if (typeof qz === 'undefined') {
|
||||
document.getElementById('qztray-status').textContent = 'Library Error';
|
||||
document.getElementById('qztray-status').className = 'badge badge-danger';
|
||||
return false;
|
||||
}
|
||||
qz.websocket.setClosedCallbacks(function() {
|
||||
document.getElementById('qztray-status').textContent = 'Disconnected';
|
||||
document.getElementById('qztray-status').className = 'badge badge-warning';
|
||||
});
|
||||
await qz.websocket.connect();
|
||||
qzTray = qz;
|
||||
const version = await qz.api.getVersion();
|
||||
document.getElementById('qztray-status').textContent = 'Ready';
|
||||
document.getElementById('qztray-status').className = 'badge badge-success';
|
||||
document.getElementById('qztray-printer-selection').style.display = 'block';
|
||||
document.getElementById('pdf-option-container').style.display = 'none';
|
||||
await loadQZTrayPrinters();
|
||||
return true;
|
||||
} catch (error) {
|
||||
document.getElementById('qztray-status').textContent = 'Not Connected';
|
||||
document.getElementById('qztray-status').className = 'badge badge-danger';
|
||||
document.getElementById('qztray-printer-selection').style.display = 'none';
|
||||
document.getElementById('pdf-option-container').style.display = 'block';
|
||||
document.getElementById('pdfGenerate').checked = true;
|
||||
document.getElementById('qzTrayPrint').disabled = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadQZTrayPrinters() {
|
||||
try {
|
||||
if (!qzTray) return;
|
||||
const printers = await qzTray.printers.find();
|
||||
availablePrinters = printers;
|
||||
const printerSelect = document.getElementById('qztray-printer-select');
|
||||
printerSelect.innerHTML = '<option value="">Select a printer...</option>';
|
||||
printers.forEach(printer => {
|
||||
const option = document.createElement('option');
|
||||
option.value = printer;
|
||||
option.textContent = printer;
|
||||
printerSelect.appendChild(option);
|
||||
});
|
||||
const thermalPrinter = printers.find(p =>
|
||||
p.toLowerCase().includes('thermal') ||
|
||||
p.toLowerCase().includes('label') ||
|
||||
p.toLowerCase().includes('zebra') ||
|
||||
p.toLowerCase().includes('epson')
|
||||
);
|
||||
if (thermalPrinter) {
|
||||
printerSelect.value = thermalPrinter;
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
// Print Button Handler
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Display last 20 printed orders on page load
|
||||
displayRecentOrders(20);
|
||||
|
||||
setTimeout(initializeQZTray, 1000);
|
||||
document.getElementById('print-label-btn').addEventListener('click', async function(e) {
|
||||
e.preventDefault();
|
||||
const selectedRow = document.querySelector('.print-module-table tbody tr.selected');
|
||||
if (!selectedRow) {
|
||||
alert('Please select an order first from the table below.');
|
||||
return;
|
||||
}
|
||||
const printMethod = document.querySelector('input[name="printMethod"]:checked').value;
|
||||
if (printMethod === 'qztray') {
|
||||
await handleQZTrayPrint(selectedRow);
|
||||
} else {
|
||||
handlePDFGeneration(selectedRow);
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('input[name="printMethod"]').forEach(radio => {
|
||||
radio.addEventListener('change', updatePrintMethodUI);
|
||||
});
|
||||
updatePrintMethodUI();
|
||||
});
|
||||
|
||||
function updatePrintMethodUI() {
|
||||
const printMethod = document.querySelector('input[name="printMethod"]:checked').value;
|
||||
const printerSelection = document.getElementById('qztray-printer-selection');
|
||||
const printButton = document.getElementById('print-label-btn');
|
||||
if (printMethod === 'qztray') {
|
||||
printButton.textContent = '🖨️ Print Labels';
|
||||
printButton.className = 'btn btn-primary';
|
||||
} else {
|
||||
printerSelection.style.display = 'none';
|
||||
printButton.textContent = '📄 Generate PDF';
|
||||
printButton.className = 'btn btn-success';
|
||||
}
|
||||
}
|
||||
|
||||
async function handleQZTrayPrint(selectedRow) {
|
||||
try {
|
||||
if (!qzTray) {
|
||||
await initializeQZTray();
|
||||
if (!qzTray) throw new Error('QZ Tray not available');
|
||||
}
|
||||
const selectedPrinter = document.getElementById('qztray-printer-select').value;
|
||||
if (!selectedPrinter) {
|
||||
alert('Please select a printer first');
|
||||
return;
|
||||
}
|
||||
const cells = selectedRow.querySelectorAll('td');
|
||||
const orderData = {
|
||||
id: cells[0].textContent,
|
||||
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()
|
||||
};
|
||||
|
||||
// Parse labels range input
|
||||
const labelsRangeInput = document.getElementById('labels-range-input').value.trim();
|
||||
let labelNumbers = [];
|
||||
|
||||
if (labelsRangeInput) {
|
||||
if (labelsRangeInput.includes('-')) {
|
||||
// Range format: "003-007"
|
||||
const rangeParts = labelsRangeInput.split('-');
|
||||
if (rangeParts.length === 2) {
|
||||
const start = parseInt(rangeParts[0]);
|
||||
const end = parseInt(rangeParts[1]);
|
||||
if (!isNaN(start) && !isNaN(end) && start > 0 && end >= start && end <= orderData.cantitate) {
|
||||
for (let i = start; i <= end; i++) {
|
||||
labelNumbers.push(i);
|
||||
}
|
||||
} else {
|
||||
alert(`Invalid range. Please use format "001-${String(orderData.cantitate).padStart(3, '0')}" or single number.`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
alert('Invalid range format. Use "003-007" format.');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Single number format: "005"
|
||||
const singleNumber = parseInt(labelsRangeInput);
|
||||
if (!isNaN(singleNumber) && singleNumber > 0 && singleNumber <= orderData.cantitate) {
|
||||
labelNumbers.push(singleNumber);
|
||||
} else {
|
||||
alert(`Invalid label number. Please use 1-${orderData.cantitate}.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No range specified, print all labels (original behavior)
|
||||
for (let i = 1; i <= orderData.cantitate; i++) {
|
||||
labelNumbers.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Print the specified labels
|
||||
for (let i = 0; i < labelNumbers.length; i++) {
|
||||
const labelNumber = labelNumbers[i];
|
||||
await generatePDFAndPrint(selectedPrinter, orderData, labelNumber, orderData.cantitate);
|
||||
if (i < labelNumbers.length - 1) await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
// Show success message
|
||||
const rangeText = labelsRangeInput ?
|
||||
(labelNumbers.length === 1 ? `label ${String(labelNumbers[0]).padStart(3, '0')}` :
|
||||
`labels ${String(labelNumbers[0]).padStart(3, '0')}-${String(labelNumbers[labelNumbers.length-1]).padStart(3, '0')}`) :
|
||||
`all ${orderData.cantitate} labels`;
|
||||
alert(`Successfully printed ${rangeText} for order ${orderData.comanda_productie}`);
|
||||
|
||||
} catch (error) {
|
||||
alert('QZ Tray print error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function generatePDFAndPrint(selectedPrinter, orderData, pieceNumber, totalPieces) {
|
||||
try {
|
||||
const pdfData = {
|
||||
...orderData,
|
||||
quantity: 1,
|
||||
piece_number: pieceNumber,
|
||||
total_pieces: totalPieces
|
||||
};
|
||||
const response = await fetch('/generate_label_pdf', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(pdfData)
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to generate PDF');
|
||||
const pdfBlob = await response.blob();
|
||||
const pdfBase64 = await new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result.split(',')[1]);
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(pdfBlob);
|
||||
});
|
||||
const config = qz.configs.create(selectedPrinter, {
|
||||
scaleContent: false,
|
||||
rasterize: false,
|
||||
size: { width: 80, height: 100 },
|
||||
units: 'mm',
|
||||
margins: { top: 0, right: 0, bottom: 0, left: 0 }
|
||||
});
|
||||
const data = [{ type: 'pdf', format: 'base64', data: pdfBase64 }];
|
||||
await qz.print(config, data);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function handlePDFGeneration(selectedRow) {
|
||||
// Check if labels range is specified
|
||||
const labelsRangeInput = document.getElementById('labels-range-input').value.trim();
|
||||
if (labelsRangeInput) {
|
||||
alert('PDF generation currently supports printing all labels only. Please use QZ Tray for custom label ranges, or leave the range field empty for PDF generation.');
|
||||
return;
|
||||
}
|
||||
|
||||
const orderId = selectedRow.querySelector('td').textContent;
|
||||
const quantityCell = selectedRow.querySelector('td:nth-child(5)');
|
||||
const quantity = quantityCell ? parseInt(quantityCell.textContent) : 1;
|
||||
const prodOrderCell = selectedRow.querySelector('td:nth-child(2)');
|
||||
const prodOrder = prodOrderCell ? prodOrderCell.textContent.trim() : 'N/A';
|
||||
const button = document.getElementById('print-label-btn');
|
||||
const originalText = button.textContent;
|
||||
button.textContent = 'Generating PDF...';
|
||||
button.disabled = true;
|
||||
fetch(`/generate_labels_pdf/${orderId}/true`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||
return response.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `labels_${prodOrder}_${quantity}pcs.pdf`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
const printWindow = window.open(url, '_blank');
|
||||
if (printWindow) {
|
||||
printWindow.focus();
|
||||
setTimeout(() => {
|
||||
printWindow.print();
|
||||
setTimeout(() => { window.URL.revokeObjectURL(url); }, 2000);
|
||||
}, 1500);
|
||||
} else {
|
||||
setTimeout(() => { window.URL.revokeObjectURL(url); }, 1000);
|
||||
}
|
||||
setTimeout(() => {}, 1000);
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Failed to generate PDF labels. Error: ' + error.message);
|
||||
})
|
||||
.finally(() => {
|
||||
button.textContent = originalText;
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
// Update the preview card with order data (as in print_module.html)
|
||||
function updatePreviewCard(order) {
|
||||
function set(id, value) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.textContent = value || '';
|
||||
}
|
||||
// Always clear barcode SVGs before updating
|
||||
const barcode = document.getElementById('barcode-display');
|
||||
if (barcode) barcode.innerHTML = '';
|
||||
const vbarcode = document.getElementById('vertical-barcode-display');
|
||||
if (vbarcode) vbarcode.innerHTML = '';
|
||||
if (!order) {
|
||||
set('customer-name-row', '');
|
||||
set('quantity-ordered-value', '');
|
||||
set('client-order-info', '');
|
||||
set('delivery-date-value', '');
|
||||
set('description-value', '');
|
||||
set('size-value', '');
|
||||
set('article-code-value', '');
|
||||
set('prod-order-value', '');
|
||||
set('barcode-text', '');
|
||||
set('vertical-barcode-text', '');
|
||||
return;
|
||||
}
|
||||
set('customer-name-row', order.customer_name || '');
|
||||
set('quantity-ordered-value', order.cantitate || '');
|
||||
set('client-order-info', (order.com_achiz_client && order.nr_linie_com_client) ? `${order.com_achiz_client}-${order.nr_linie_com_client}` : '');
|
||||
// Format delivery date as DD/MM/YYYY
|
||||
let deliveryDateFormatted = '';
|
||||
if (order.data_livrare) {
|
||||
const d = new Date(order.data_livrare);
|
||||
if (!isNaN(d)) {
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
deliveryDateFormatted = `${day}/${month}/${year}`;
|
||||
} else {
|
||||
deliveryDateFormatted = order.data_livrare;
|
||||
}
|
||||
}
|
||||
set('delivery-date-value', deliveryDateFormatted);
|
||||
set('description-value', order.descr_com_prod || '');
|
||||
set('size-value', order.dimensiune || '');
|
||||
set('article-code-value', order.cod_articol || '');
|
||||
set('prod-order-value', (order.comanda_productie && order.cantitate) ? `${order.comanda_productie}-${order.cantitate}` : '');
|
||||
set('barcode-text', order.comanda_productie ? `${order.comanda_productie}/001` : '');
|
||||
set('vertical-barcode-text', (order.com_achiz_client && order.nr_linie_com_client) ? `${order.com_achiz_client}/${order.nr_linie_com_client}` : '');
|
||||
// Generate barcodes if JsBarcode is available (with debugging like print_module.html)
|
||||
const horizontalBarcodeData = order.comanda_productie ? `${order.comanda_productie}/001` : 'N/A';
|
||||
const verticalBarcodeData = (order.com_achiz_client && order.nr_linie_com_client) ? `${order.com_achiz_client}/${order.nr_linie_com_client}` : '000000/00';
|
||||
|
||||
console.log('🔍 BARCODE DEBUG - Order data:', order);
|
||||
console.log('🔍 Attempting to generate horizontal barcode:', horizontalBarcodeData);
|
||||
console.log('🔍 JsBarcode available?', typeof JsBarcode !== 'undefined');
|
||||
console.log('🔍 JsBarcode object:', typeof JsBarcode !== 'undefined' ? JsBarcode : 'undefined');
|
||||
|
||||
// Function to generate barcodes (can be called after library loads)
|
||||
const generateBarcodes = () => {
|
||||
if (horizontalBarcodeData !== 'N/A' && typeof JsBarcode !== 'undefined') {
|
||||
try {
|
||||
const barcodeElement = document.querySelector("#barcode-display");
|
||||
console.log('🔍 Horizontal barcode element:', barcodeElement);
|
||||
console.log('🔍 Element innerHTML before:', barcodeElement ? barcodeElement.innerHTML : 'null');
|
||||
|
||||
JsBarcode("#barcode-display", horizontalBarcodeData, {
|
||||
format: "CODE128",
|
||||
width: 2,
|
||||
height: 40,
|
||||
displayValue: false,
|
||||
margin: 2,
|
||||
lineColor: "#000000",
|
||||
background: "#ffffff"
|
||||
});
|
||||
|
||||
console.log('🔍 Element innerHTML after:', barcodeElement ? barcodeElement.innerHTML : 'null');
|
||||
console.log('✅ Horizontal barcode generated successfully');
|
||||
|
||||
// Force black color on all barcode elements
|
||||
const barcodeSvg = document.getElementById('barcode-display');
|
||||
if (barcodeSvg) {
|
||||
console.log('🔍 SVG elements found:', barcodeSvg.querySelectorAll('rect, path').length);
|
||||
barcodeSvg.querySelectorAll('rect').forEach((r, i) => {
|
||||
console.log(`🔍 Setting rect ${i} to black`);
|
||||
r.setAttribute('fill', '#000000');
|
||||
r.setAttribute('stroke', '#000000');
|
||||
});
|
||||
barcodeSvg.querySelectorAll('path').forEach((p, i) => {
|
||||
console.log(`🔍 Setting path ${i} to black`);
|
||||
p.setAttribute('fill', '#000000');
|
||||
p.setAttribute('stroke', '#000000');
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('❌ Failed to generate horizontal barcode:', e);
|
||||
}
|
||||
} else {
|
||||
console.warn('⚠️ Skipping horizontal barcode generation:',
|
||||
horizontalBarcodeData === 'N/A' ? 'No data' : 'JsBarcode not loaded');
|
||||
}
|
||||
|
||||
// Generate vertical barcode visual using JsBarcode (will be rotated by CSS)
|
||||
console.log('🔍 Attempting to generate vertical barcode:', verticalBarcodeData);
|
||||
|
||||
if (verticalBarcodeData !== '000000/00' && typeof JsBarcode !== 'undefined') {
|
||||
try {
|
||||
const verticalElement = document.querySelector("#vertical-barcode-display");
|
||||
console.log('🔍 Vertical barcode element:', verticalElement);
|
||||
|
||||
JsBarcode("#vertical-barcode-display", verticalBarcodeData, {
|
||||
format: "CODE128",
|
||||
width: 1.5,
|
||||
height: 35,
|
||||
displayValue: false,
|
||||
margin: 2,
|
||||
lineColor: "#000000",
|
||||
background: "#ffffff"
|
||||
});
|
||||
console.log('✅ Vertical barcode generated successfully');
|
||||
|
||||
// Force black color on all vertical barcode elements
|
||||
const vbarcodeSvg = document.getElementById('vertical-barcode-display');
|
||||
if (vbarcodeSvg) {
|
||||
vbarcodeSvg.querySelectorAll('rect').forEach(r => {
|
||||
r.setAttribute('fill', '#000000');
|
||||
r.setAttribute('stroke', '#000000');
|
||||
});
|
||||
vbarcodeSvg.querySelectorAll('path').forEach(p => {
|
||||
p.setAttribute('fill', '#000000');
|
||||
p.setAttribute('stroke', '#000000');
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('❌ Failed to generate vertical barcode:', e);
|
||||
}
|
||||
} else {
|
||||
console.warn('⚠️ Skipping vertical barcode generation:',
|
||||
verticalBarcodeData === '000000/00' ? 'Default value' : 'JsBarcode not loaded');
|
||||
}
|
||||
};
|
||||
|
||||
// Try to generate immediately
|
||||
generateBarcodes();
|
||||
|
||||
// If JsBarcode is not loaded, wait a bit and try again (for CDN fallback)
|
||||
if (typeof JsBarcode === 'undefined') {
|
||||
setTimeout(() => {
|
||||
console.log('🔍 Retry after 1s - JsBarcode available?', typeof JsBarcode !== 'undefined');
|
||||
generateBarcodes();
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function selectOrder(orderId) {
|
||||
// Find order by ID
|
||||
const order = allOrders.find(o => o.id === orderId);
|
||||
if (order) {
|
||||
// Populate search field
|
||||
document.getElementById('search-input').value = order.comanda_productie;
|
||||
|
||||
// Display in search result
|
||||
displaySelectedOrder(order);
|
||||
|
||||
// Highlight selected row
|
||||
document.querySelectorAll('#orders-table tr').forEach(row => {
|
||||
row.classList.remove('selected');
|
||||
});
|
||||
event.currentTarget.classList.add('selected');
|
||||
|
||||
// Scroll to top
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
|
||||
function displaySelectedOrder(order) {
|
||||
selectedOrderData = order;
|
||||
|
||||
const resultDiv = document.getElementById('search-result');
|
||||
const tbody = document.getElementById('selected-order-row');
|
||||
|
||||
// Format date
|
||||
let dateStr = '-';
|
||||
if (order.data_livrare) {
|
||||
dateStr = order.data_livrare;
|
||||
}
|
||||
|
||||
// Format created_at
|
||||
let createdStr = '-';
|
||||
if (order.created_at) {
|
||||
createdStr = order.created_at;
|
||||
}
|
||||
|
||||
tbody.innerHTML = `
|
||||
<tr>
|
||||
<td>${order.id}</td>
|
||||
<td><strong>${order.comanda_productie}</strong></td>
|
||||
<td>${order.cod_articol || '-'}</td>
|
||||
<td>${order.descr_com_prod}</td>
|
||||
<td style="text-align: right; font-weight: 600;">${order.cantitate}</td>
|
||||
<td style="text-align: center;">${dateStr}</td>
|
||||
<td style="text-align: center;">${order.dimensiune || '-'}</td>
|
||||
<td>${order.com_achiz_client || '-'}</td>
|
||||
<td style="text-align: right;">${order.nr_linie_com_client || '-'}</td>
|
||||
<td>${order.customer_name || '-'}</td>
|
||||
<td>${order.customer_article_number || '-'}</td>
|
||||
<td>${order.open_for_order || '-'}</td>
|
||||
<td style="text-align: right;">${order.line_number || '-'}</td>
|
||||
<td style="text-align: center;">
|
||||
${order.printed_labels == 1 ? '<span style="color: #28a745; font-weight: bold;">✓ Yes</span>' : '<span style="color: #dc3545;">✗ No</span>'}
|
||||
</td>
|
||||
<td style="font-size: 11px; color: #6c757d;">${createdStr}</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
resultDiv.style.display = 'block';
|
||||
document.getElementById('print-button').disabled = false;
|
||||
}
|
||||
|
||||
function printLabels() {
|
||||
if (!selectedOrderData) {
|
||||
alert('Please select an order first');
|
||||
return;
|
||||
}
|
||||
|
||||
const quantity = parseInt(document.getElementById('quantity-input').value);
|
||||
if (!quantity || quantity < 1) {
|
||||
alert('Please enter a valid quantity');
|
||||
return;
|
||||
}
|
||||
|
||||
// Redirect to print module with order data
|
||||
const orderIds = [selectedOrderData.id];
|
||||
const url = `/print_module?order_ids=${orderIds.join(',')}&quantity=${quantity}`;
|
||||
window.location.href = url;
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
1665
app/templates/modules/labels/print_module.html
Normal file
1665
app/templates/modules/labels/print_module.html
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user