window.printItemBarcode = function(sku, nameAr, nameEn, price) { if (!sku) { Swal.fire('Error', 'This item has no SKU/Barcode assigned.', 'error'); return; } document.getElementById('barcodeLabelName').innerHTML = '
' + nameAr + '
' + nameEn + '
'; document.getElementById('barcodeLabelPrice').textContent = 'OMR ' + price; JsBarcode("#barcodeSvg", sku, { format: "CODE128", lineColor: "#000", width: 2, height: 50, displayValue: true }); const modal = new bootstrap.Modal(document.getElementById('barcodePrintModal')); modal.show(); }; window.executeBarcodePrint = function() { const qty = parseInt(document.getElementById('barcodeQty').value) || 1; const width = parseInt(document.getElementById('barcodeWidth').value) || 40; const height = parseInt(document.getElementById('barcodeHeight').value) || 25; // Get content const nameHtml = document.getElementById('barcodeLabelName').innerHTML; const price = document.getElementById('barcodeLabelPrice').innerText; const svg = document.getElementById('barcodeSvg').outerHTML; // Create a hidden iframe const iframe = document.createElement('iframe'); iframe.style.position = 'absolute'; iframe.style.width = '0px'; iframe.style.height = '0px'; iframe.style.border = 'none'; document.body.appendChild(iframe); const doc = iframe.contentWindow.document; let labelsHtml = ''; for (let i = 0; i < qty; i++) { labelsHtml += `
${nameHtml}
${svg}
${price}
`; } doc.open(); doc.write(` ${labelsHtml} `); doc.close(); iframe.contentWindow.focus(); setTimeout(() => { iframe.contentWindow.print(); setTimeout(() => { document.body.removeChild(iframe); }, 2000); }, 500); }; window.printPosReceiptFromInvoice = function(inv) { const container = document.getElementById('posReceiptContent'); const itemsHtml = inv.items.map(item => { const itemTotal = item.unit_price * item.quantity; const vatRate = parseFloat(item.vat_rate !== undefined && item.vat_rate !== null ? item.vat_rate : 0); const vatAmount = itemTotal * (vatRate / (100 + vatRate)); return ` ${item.name_en} / ${item.name_ar}
${item.quantity} x ${parseFloat(item.unit_price).toFixed(3)} ${vatAmount.toFixed(2)} ${itemTotal.toFixed(3)} `; }).join(''); const totalVat = inv.items.reduce((sum, item) => { const itemTotal = item.unit_price * item.quantity; const vatRate = parseFloat(item.vat_rate !== undefined && item.vat_rate !== null ? item.vat_rate : 0); return sum + (itemTotal * (vatRate / (100 + vatRate))); }, 0); const subtotal = inv.items.reduce((sum, item) => sum + (item.unit_price * item.quantity), 0); const companyName = ""; const outletName = ""; const companyPhone = ""; const companyVat = ""; const companyLogo = ""; container.innerHTML = `
${companyLogo ? `Logo` : ''}
${companyName}
${inv.outlet_name ? `
${inv.outlet_name}
` : ''} ${companyPhone ? `
Tel: ${companyPhone}
` : ''} ${companyVat ? `
VAT: ${companyVat}
` : ''}
TAX INVOICE / فاتورة ضريبية
Inv / رقم: INV-${inv.id.toString().padStart(5, '0')}
Date / التاريخ: ${inv.invoice_date}
Customer / العميل: ${inv.customer_name || 'Walk-in / عميل عابر'}
${itemsHtml}
ITEM / الصنف VAT / الضريبة TOTAL / الإجمالي
Subtotal (Excl. VAT) / المجموع الفرعي (دون الضريبة) ${(subtotal - totalVat).toFixed(3)}
VAT / الضريبة ${totalVat.toFixed(2)}
TOTAL (Incl. VAT) / الإجمالي (شامل الضريبة) ${subtotal.toFixed(3)}
PAID / المدفوع ${parseFloat(inv.paid_amount).toFixed(3)}
BALANCE / الرصيد ${(subtotal - inv.paid_amount).toFixed(3)}

Thank You for your business! / شكراً لتعاملكم معنا!

`; const posModal = new bootstrap.Modal(document.getElementById('posReceiptModal')); posModal.show(); }; function printPosReceipt() { const content = document.getElementById('posReceiptContent').innerHTML; const printArea = document.getElementById('posPrintArea'); printArea.innerHTML = `
${content}
`; document.body.classList.add('printing-receipt'); window.print(); document.body.classList.remove('printing-receipt'); location.reload(); }