updated / print module / keypairing options

This commit is contained in:
Quality System Admin
2025-11-06 20:37:19 +02:00
parent c91b7d0a4d
commit f1ff492787
12 changed files with 3236 additions and 562 deletions

View File

@@ -33,7 +33,10 @@
<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;">
@@ -194,6 +197,77 @@ let selectedOrderData = null;
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) {
@@ -345,6 +419,9 @@ async function loadQZTrayPrinters() {
// 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();