| |
| |
| |
| |
| |
| |
| |
| |
| (function() { |
| 'use strict'; |
| |
| |
| |
| |
| if (!window.__VAI_BLOB_REGISTRY) { |
| window.__VAI_BLOB_REGISTRY = []; |
| var isUnloading = false; |
| |
| |
| function cleanupBlobs() { |
| isUnloading = true; |
| window.__VAI_BLOB_REGISTRY.forEach(function(e) { |
| if (!e.revoked && e.url) { |
| try { URL.revokeObjectURL(e.url); e.revoked = true; } catch(err) {} |
| } |
| }); |
| } |
| |
| window.addEventListener('pagehide', cleanupBlobs); |
| window.addEventListener('beforeunload', cleanupBlobs); |
| window.addEventListener('unload', cleanupBlobs); |
| |
| |
| var origRevoke = URL.revokeObjectURL; |
| URL.revokeObjectURL = function(url) { |
| if (isUnloading || !url || typeof url !== 'string' || !url.startsWith('blob:')) { |
| return origRevoke.apply(this, arguments); |
| } |
| var found = window.__VAI_BLOB_REGISTRY.find(function(e) { return e.url === url; }); |
| if (!found) { |
| window.__VAI_BLOB_REGISTRY.push({ url: url, revoked: false }); |
| } |
| }; |
| } |
| |
| |
| if (window._doExportExcel) { |
| var newDoExportExcel = async function(d, qd, code, qrUrl) { |
| var MONEY_FMT = '#,##0"đ"'; |
| var NUM_FMT = '#,##0'; |
| var WHITE = { argb: 'FFFFFFFF' }; |
| var WB = { |
| top: { style: 'thin', color: WHITE }, |
| bottom: { style: 'thin', color: WHITE }, |
| left: { style: 'thin', color: WHITE }, |
| right: { style: 'thin', color: WHITE } |
| }; |
| |
| var wb = new ExcelJS.Workbook(), ws = wb.addWorksheet('Báo giá'); |
| ws.views = [{ showGridLines: false }]; |
| ws.columns = [{ width: 5 }, { width: 11 }, { width: 28 }, { width: 13 }, |
| { width: 20 }, { width: 6 }, { width: 13 }, { width: 13 }, |
| { width: 15 }, { width: 14 }]; |
| |
| |
| ws.mergeCells('A1:J1'); |
| ws.getCell('A1').value = 'BẢNG BÁO GIÁ'; |
| ws.getCell('A1').font = { bold: true, size: 16, color: { argb: 'FF003F62' } }; |
| ws.getCell('A1').alignment = { horizontal: 'center' }; |
| |
| ws.getCell('A2').value = 'Khách hàng:'; |
| ws.mergeCells('B2:E2'); |
| ws.getCell('B2').value = (qd.customer ? qd.customer.name : '') || ''; |
| |
| ws.getCell('A3').value = 'SĐT:'; |
| ws.getCell('B3').value = (qd.customer ? qd.customer.phone : '') || ''; |
| ws.getCell('H3').value = 'Mã: ' + code; |
| |
| |
| var hr = ws.getRow(5); |
| ['STT', 'Tên SP', 'Mã', 'SL', 'Giá'].forEach(function(h, i) { |
| var c = hr.getCell(i + 1); |
| c.value = h; |
| c.font = { bold: true, color: { argb: 'FFFFFFFF' } }; |
| c.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF003F62' } }; |
| }); |
| |
| |
| var cr = 6, total = 0; |
| (qd.items || []).forEach(function(it, i) { |
| var row = ws.getRow(cr); |
| row.values = [i + 1, it.name || '', it.model || '', |
| it.qty || 1, (it.discPrice || it.price || 0) * (it.qty || 1)]; |
| total += (it.discPrice || it.price || 0) * (it.qty || 1); |
| cr++; |
| }); |
| |
| |
| ws.mergeCells(cr, 1, cr, 4); |
| ws.getCell('A' + cr).value = 'TỔNG CỘNG'; |
| ws.getCell('A' + cr).font = { bold: true }; |
| ws.getCell('E' + cr).value = total; |
| ws.getCell('E' + cr).font = { bold: true }; |
| ws.getCell('E' + cr).numFmt = '#,##0"đ"'; |
| |
| |
| var buf = await wb.xlsx.writeBuffer(); |
| var blob = new Blob([buf], { |
| type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
| }); |
| var url = URL.createObjectURL(blob); |
| |
| |
| window.__VAI_BLOB_REGISTRY.push({ url: url, revoked: false }); |
| |
| var a = document.createElement('a'); |
| a.href = url; |
| a.download = code + '.xlsx'; |
| document.body.appendChild(a); |
| a.click(); |
| |
| setTimeout(function() { |
| try { document.body.removeChild(a); } catch(e) {} |
| }, 100); |
| |
| if (typeof showToast === 'function') { |
| showToast('✅ Đã tải ' + code + '.xlsx'); |
| } |
| }; |
| |
| |
| window._doExportExcel = newDoExportExcel; |
| |
| |
| if (window.exportExcel && window.VAI_QR.exportExcel) { |
| window.VAI_QR.exportExcel = function(d, qd, code, qrUrl) { |
| newDoExportExcel(d, qd, code, qrUrl); |
| }; |
| } |
| } |
| |
| console.log('[QR Excel Final Fix] _doExportExcel overridden - multi-download enabled'); |
| })(); |