Best-Seller Ranking Tracker
Monitor product rankings and analyze sales performance.
Total Products Tracked
0
Average Rank Change
0
Top Mover
N/A
Product Rankings
| Rank | Product | Sales Volume |
|---|
Top 5 Products by Sales
Add New Product
Product Database
Best-Seller Performance Report
Report Date:
Performance Rankings
| Rank | Change | Product | Category | Sales Volume ($) |
|---|
Top 5 Products by Sales
Report generated by the Best-Seller Ranking Tracker.
${p.category}
${p.name} (Rank: ${p.currentRank})
`);
});
}
// --- FORMS & EVENT HANDLERS ---
productForm.addEventListener('submit', (e) => {
e.preventDefault();
const data = {
name: document.getElementById('product-name').value,
category: document.getElementById('product-category').value,
currentRank: parseInt(document.getElementById('product-current-rank').value),
prevRank: parseInt(document.getElementById('product-prev-rank').value),
sales: parseFloat(document.getElementById('product-sales').value),
};
if (editingProductId) {
const product = products.find(p => p.id === editingProductId);
Object.assign(product, data);
} else {
data.id = Date.now();
products.push(data);
}
resetForm();
renderAll();
});
document.getElementById('cancel-edit-btn').addEventListener('click', resetForm);
document.getElementById('product-list').addEventListener('click', (e) => {
if (e.target.classList.contains('product-edit')) setupEditForm(parseInt(e.target.dataset.id));
if (e.target.classList.contains('product-delete')) deleteProduct(parseInt(e.target.dataset.id));
});
function resetForm() { productForm.reset(); editingProductId = null; document.getElementById('form-title').textContent = 'Add New Product'; document.getElementById('cancel-edit-btn').style.display = 'none'; }
function setupEditForm(id) {
const p = products.find(p => p.id === id); if (!p) return;
document.getElementById('product-id').value = p.id;
document.getElementById('product-name').value = p.name;
document.getElementById('product-category').value = p.category;
document.getElementById('product-current-rank').value = p.currentRank;
document.getElementById('product-prev-rank').value = p.prevRank;
document.getElementById('product-sales').value = p.sales;
editingProductId = id;
document.getElementById('form-title').textContent = 'Edit Product';
document.getElementById('cancel-edit-btn').style.display = 'inline-block';
}
function deleteProduct(id) { if (confirm('Delete this product?')) { products = products.filter(p => p.id !== id); renderAll(); } }
downloadPdfBtn.addEventListener('click', generatePdf);
// --- TABS & NAVIGATION ---
window.switchTab = (tabName) => { currentTab = tabName; Object.values(tabBtns).forEach(b=>b.classList.replace('tab-active', 'tab-inactive')); Object.values(tabContents).forEach(c=>c.style.display='none'); tabBtns[tabName].classList.replace('tab-inactive', 'tab-active'); tabContents[tabName].style.display = 'block'; };
window.navigateTabs = (dir) => { if (dir==='next' && currentTab==='dashboard') switchTab('config'); else if (dir==='prev' && currentTab==='config') switchTab('dashboard'); };
// --- PDF GENERATION ---
async function generatePdf() {
const { jsPDF } = window.jspdf;
const pdfReportElement = document.getElementById('pdf-report');
const sortedProducts = [...products].sort((a, b) => a.currentRank - b.currentRank);
document.getElementById('pdf-date').textContent = new Date().toLocaleDateString('en-US');
const pdfTableBody = document.getElementById('pdf-table-body');
pdfTableBody.innerHTML = '';
sortedProducts.forEach(p => {
const change = p.prevRank - p.currentRank;
let changeText = '-';
if (change > 0) changeText = `+${change}`;
if (change < 0) changeText = `${change}`;
pdfTableBody.insertAdjacentHTML('beforeend', `