From e473add476255ab02420aced0656e155362f9aa7 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 3 Feb 2026 10:01:55 +0000 Subject: [PATCH] editing barcode module --- core/templates/core/barcode_labels.html | 169 ++++++++++++++++++++---- 1 file changed, 143 insertions(+), 26 deletions(-) diff --git a/core/templates/core/barcode_labels.html b/core/templates/core/barcode_labels.html index 83b81b7..2bc32f7 100644 --- a/core/templates/core/barcode_labels.html +++ b/core/templates/core/barcode_labels.html @@ -6,7 +6,7 @@

Barcode Label Printing

@@ -33,20 +33,32 @@ {% for product in products %} - +
{{ product.name_en }}
{{ product.name_ar }} {{ product.sku }} - +
+ + +
{% endfor %} @@ -120,8 +132,11 @@
-
+
3. Live Preview (Single Label)
+
@@ -154,6 +169,8 @@ .print-only { display: none; } } @media print { + #sidebar, .top-navbar, .navbar, footer { display: none !important; } + #content, main { margin: 0 !important; padding: 0 !important; width: 100% !important; } .no-print { display: none !important; } .print-only { display: block; } body { margin: 0; padding: 0; background: white; -webkit-print-color-adjust: exact; } @@ -162,6 +179,22 @@ size: A4; margin: 0; } + + /* Direct Print Mode: Remove A4 constraints */ + body.direct-print-mode @page { + size: auto; + margin: 0; + } + body.direct-print-mode .label-sheet { + width: auto; + margin: 0; + padding: 0; + } + body.direct-print-mode .label-item { + border: none !important; + margin: 0 !important; + page-break-after: always; + } .label-sheet { display: flex; @@ -369,18 +402,19 @@ const labelQueueBody = document.getElementById('labelQueue'); const emptyQueue = document.getElementById('emptyQueue'); const printArea = document.getElementById('printArea'); + let lastAddedProduct = null; // Add to Queue document.querySelectorAll('.add-to-queue').forEach(btn => { btn.addEventListener('click', () => { const product = { id: btn.dataset.id, - name: btn.dataset.name, + name: btn.dataset.name, nameAr: btn.dataset.nameAr, sku: btn.dataset.sku, price: btn.dataset.price, qty: 1 }; - + lastAddedProduct = product; const existing = queue.find(p => p.id === product.id); if (existing) { existing.qty++; @@ -402,7 +436,7 @@ labelQueueBody.innerHTML = queue.map((p, index) => ` -
${p.name}
+
${p.nameAr ? p.nameAr + " | " : ""}${p.name}
${p.sku} @@ -446,14 +480,20 @@ // Preview Logic function updatePreview() { - if (queue.length === 0) return; - const lastProduct = queue[queue.length - 1]; + let product = null; + if (queue.length > 0) { + product = queue[queue.length - 1]; + } else if (lastAddedProduct) { + product = lastAddedProduct; + } - document.querySelector('.preview-name').innerText = lastProduct.name; - document.querySelector('.preview-sku').innerText = lastProduct.sku; - document.querySelector('.preview-price').innerText = 'OMR ' + parseFloat(lastProduct.price).toFixed(3); + if (!product) return; - JsBarcode("#previewBarcode", lastProduct.sku, { + document.querySelector('.preview-name').innerHTML = (product.nameAr ? `
${product.nameAr}
` : '') + `
${product.name}
`; + document.querySelector('.preview-sku').innerText = product.sku; + document.querySelector('.preview-price').innerText = 'OMR ' + parseFloat(product.price).toFixed(3); + + JsBarcode("#previewBarcode", product.sku, { format: "CODE128", width: 2, height: 40, @@ -467,8 +507,88 @@ document.querySelector('.preview-sku').style.display = document.getElementById('showSKU').checked ? '' : 'none'; } - // Prepare Print Area - function preparePrint() { + // Direct Print Logic + function directPrintFromRow(btn) { + const product = { + id: btn.dataset.id, + name: btn.dataset.name, nameAr: btn.dataset.nameAr, + sku: btn.dataset.sku, + price: btn.dataset.price, + qty: 1 + }; + performDirectPrint(product); + } + + function printSingleFromPreview() { + let product = null; + if (queue.length > 0) { + product = queue[queue.length - 1]; + } else if (lastAddedProduct) { + product = lastAddedProduct; + } + if (product) performDirectPrint(product); + } + + function performDirectPrint(product) { + document.body.classList.add('direct-print-mode'); + printArea.innerHTML = ''; + const labelType = document.getElementById('labelType').value; + const showName = document.getElementById('showName').checked; + const showPrice = document.getElementById('showPrice').checked; + const showSKU = document.getElementById('showSKU').checked; + + const sheet = document.createElement('div'); + sheet.className = 'label-sheet'; + + const label = document.createElement('div'); + label.className = `label-item label-${labelType}`; + + let content = ''; + if (labelType === 'l7656') { + if (showName) content += `
${product.nameAr ? product.nameAr + " " : ""}${product.name}
`; + content += ``; + if (showPrice) content += `
${parseFloat(product.price).toFixed(3)}
`; + } else { + if (showName) { if (product.nameAr) content += `
${product.nameAr}
`; content += `
${product.name}
`; } + content += ``; + if (showSKU || showPrice) { + content += `
`; + if (showSKU) content += `${product.sku}`; + if (showPrice) content += `OMR ${parseFloat(product.price).toFixed(3)}`; + content += `
`; + } + } + + label.innerHTML = content; + sheet.appendChild(label); + printArea.appendChild(sheet); + + let bWidth = 1.5; + let bHeight = 30; + if (labelType === 'l7651') { bWidth = 1.0; bHeight = 20; } + else if (labelType === 'l7656') { bWidth = 0.8; bHeight = 8; } + else if (labelType === 'a4-40') { bWidth = 1.2; bHeight = 25; } + else if (labelType === 'price-tag') { bWidth = 1.0; bHeight = 15; } + + JsBarcode("#direct-barcode", product.sku, { + format: "CODE128", + width: bWidth, + height: bHeight, + displayValue: false, + margin: 0 + }); + + setTimeout(() => { + window.print(); + document.body.classList.remove('direct-print-mode'); + preparePrint(); // Restore full queue print area + }, 100); + } + + // Prepare Print Area (Full Queue) + function preparePrint() { + if (document.body.classList.contains('direct-print-mode')) return; + printArea.innerHTML = ''; const labelType = document.getElementById('labelType').value; const showName = document.getElementById('showName').checked; @@ -478,7 +598,6 @@ const sheet = document.createElement('div'); sheet.className = 'label-sheet'; - // Add specific sheet class for grid layouts if (labelType === 'a4-24') sheet.classList.add('sheet-a4-24'); else if (labelType === 'a4-40') sheet.classList.add('sheet-a4-40'); else if (labelType === 'l7651') sheet.classList.add('sheet-l7651'); @@ -492,12 +611,11 @@ let content = ''; if (labelType === 'l7656') { - // Horizontal layout for very short labels - if (showName) content += `
${p.name}
`; + if (showName) content += `
${p.nameAr ? p.nameAr + " " : ""}${p.name}
`; content += ``; if (showPrice) content += `
${parseFloat(p.price).toFixed(3)}
`; } else { - if (showName) content += `
${p.name}
`; + if (showName) { if (p.nameAr) content += `
${p.nameAr}
`; content += `
${p.name}
`; } content += ``; if (showSKU || showPrice) { content += `
`; @@ -514,7 +632,6 @@ printArea.appendChild(sheet); - // Generate barcodes queue.forEach(p => { for (let i = 0; i < p.qty; i++) { const svgId = `barcode-${p.id}-${i}`;