E-commerce Profitability Analysis Tool

E-commerce Profitability Analysis Tool

Analyze your product portfolio to understand true profitability and make data-driven decisions.

Generated on:

Total Revenue

${formatCurrency(totalRevenue)}

Net Profit

${formatCurrency(totalProfit)}

Overall Margin

${overallMargin.toFixed(1)}%

Top Product

${topProfitProduct ? topProfitProduct.name : 'N/A'}

Profit Contribution by Product

${tableRows}
ProductSales VolumeRevenueGross ProfitMargin
`; renderProfitChart(products); document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderProfitChart = (products) => { const ctx = document.getElementById('profit-chart').getContext('2d'); if (charts.profit) charts.profit.destroy(); charts.profit = new Chart(ctx, { type: 'bar', data: { labels: products.map(p => p.name), datasets: [{ label: 'Gross Profit', data: products.map(p => p.grossProfit), backgroundColor: '#16a34a' }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, ticks: { callback: (v) => formatCurrency(v) } } } } }); }; const renderDataConfig = () => { const configContent = document.getElementById('content-data-configuration'); if (!configContent) return; const productRows = appData.products.map(p => ` `).join(''); configContent.innerHTML = `

Product & Sales Data

${productRows}
NameVolumeCOGS ($)Shipping ($)Price ($)

Business-Wide Costs

`; lucide.createIcons(); attachConfigListeners(); }; // --- EVENT HANDLERS & LOGIC --- const attachConfigListeners = () => { const handler = () => { document.querySelectorAll('.config-input').forEach(input => { const id = parseInt(input.dataset.id); const field = input.dataset.field; const value = input.type === 'number' ? parseFloat(input.value) || 0 : input.value; const product = appData.products.find(p => p.id === id); if (product) product[field] = value; }); document.querySelectorAll('.config-input-general').forEach(input => { const field = input.dataset.field; appData.config[field] = parseFloat(input.value) || 0; }); appData.analysisResults = null; renderDashboard(); }; document.querySelectorAll('.config-input, .config-input-general').forEach(input => input.addEventListener('change', handler)); document.querySelectorAll('.remove-product-btn').forEach(btn => btn.addEventListener('click', e => { const id = parseInt(e.currentTarget.dataset.id); appData.products = appData.products.filter(p => p.id !== id); appData.analysisResults = null; renderDataConfig(); renderDashboard(); })); document.getElementById('add-product-btn').addEventListener('click', () => { const newId = appData.products.length > 0 ? Math.max(...appData.products.map(p => p.id)) + 1 : 1; appData.products.push({ id: newId, name: 'New Product', salesVolume: 0, cogs: 10, shipping: 5, price: 30 }); renderDataConfig(); }); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; document.getElementById('pdf-generated-date').textContent = new Date().toLocaleString(); const pdfHeader = document.getElementById('pdf-header'); pdfHeader.classList.remove('hidden'); const fullContent = document.getElementById('pdf-content-area'); html2canvas(fullContent, { scale: 2, useCORS: true, logging: false, windowWidth: 1200 }) .then(canvas => { pdfHeader.classList.add('hidden'); const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'landscape', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, imgHeight); pdf.save('E-commerce-Profitability-Report.pdf'); loadingOverlay.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); pdfHeader.classList.add('hidden'); loadingOverlay.style.display = 'none'; alert('An error occurred generating the PDF.'); }); }; // --- TAB NAVIGATION & INITIALIZATION --- const switchTab = (tabIndex) => { activeTabIndex = tabIndex; document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex)); document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex)); updateNavButtons(); }; const updateNavButtons = () => { prevTabBtn.disabled = activeTabIndex === 0; nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1; }; const initializeUI = () => { const tabs = [ { name: 'Profitability Dashboard', id: 'profit-dashboard' }, { name: 'Data Configuration', id: 'data-configuration' } ]; tabIdentifiers = tabs.map(t => t.id); tabsContainer.innerHTML = tabs.map(tab => ``).join(''); mainContent.innerHTML = tabs.map(tab => `
`).join(''); tabs.forEach((tab, index) => { document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index)); }); renderDashboard(); renderDataConfig(); switchTab(0); }; initializeUI(); prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); }); });
Scroll to Top