' + '

📦 ManuTrade AI — 庫存優化器報告

' + '

生成日期:' + new Date().toISOString().slice(0,10) + ' || 已分析 ' + inventory.length + ' 項產品

'; // Summary boxes var totalValue = 0, deadStockValue = 0, clearanceItems = 0, totalVelocity = 0, totalStock = 0; for(var i = 0; i < inventory.length; i++){ totalValue += inventory[i].stockValue || 0; totalStock += inventory[i].currentStock || 0; totalVelocity += inventory[i].monthlyVelocity || 0; if(inventory[i].status === 'Critical' || inventory[i].status === 'Inactive'){ deadStockValue += inventory[i].stockValue || 0; clearanceItems++; } } var clearancePct = totalValue > 0 ? Math.round((deadStockValue / totalValue) * 100) : 0; var turnoverRate = totalStock > 0 ? (totalVelocity / totalStock).toFixed(2) : '0.00'; h += '';
' + '
$' + totalValue.toLocaleString('en-US',{minimumFractionDigits:0,maximumFractionDigits:0}) + '
Total Stock Value
' + '
$' + deadStockValue.toLocaleString('en-US',{minimumFractionDigits:0,maximumFractionDigits:0}) + '
Dead Stock Value
' + '
' + clearancePct + '%
Clearance Rate %
' + '
' + turnoverRate + '
Turnover Rate
' + '
'; // Table h += ''; for(var j = 0; j < inventory.length; j++){ var it = inventory[j]; var bc = 'badge-healthy'; if(it.status === 'Warning' || it.status === 'Out of Stock') bc = 'badge-warning'; if(it.status === 'Critical' || it.status === 'Inactive') bc = 'badge-critical'; var stLabel = it.status; if(stLabel === 'Healthy') stLabel = 'Healthy'; else if(stLabel === 'Warning') stLabel = 'Warning'; else if(stLabel === 'Critical') stLabel = 'Critical'; else if(stLabel === 'Inactive') stLabel = 'Inactive'; else if(stLabel === 'Out of Stock') stLabel = 'Out of Stock'; h += ''; } h += '
SKUProductUnit CostStockAvg. Monthly SalesDays of StockStatusValue
' + esc(it.sku) + '' + esc(it.productName) + '$' + (it.unitCost || 0).toFixed(2) + '' + it.currentStock + '' + (it.monthlyVelocity || 0).toFixed(1) + '' + it.daysOfStock + '' + stLabel + '$' + (it.stockValue || 0).toFixed(2) + '
'; // AI Analysis h += '

🤖 AI Analysis

' + aiContent + '
'; h += ''; var w = window.open('','_blank'); w.document.write(h); w.document.close(); setTimeout(function(){ w.print(); }, 600); }); // ── Status helpers ── function showStatus(type, msg){ var s = document.getElementById('status'); s.className = 'status show ' + type; s.textContent = msg; } function hideStatus(){ document.getElementById('status').classList.remove('show'); }