POS System Integration Tool

POS System Integration Tool

Simulate sales transactions and view integrated dashboard analytics.

Generated on:

Total Revenue

${formatCurrency(totalRevenue)}

Total Transactions

${totalTransactions}

Average Sale Value

${formatCurrency(avgSaleValue)}

Top Selling Product

${topSellingProduct}

`; renderDashboardCharts(salesByPaymentMethod); document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderDashboardCharts = (salesByPaymentMethod) => { const paymentCtx = document.getElementById('sales-by-payment-chart').getContext('2d'); if(charts.payment) charts.payment.destroy(); charts.payment = new Chart(paymentCtx, { type: 'doughnut', data: { labels: Object.keys(salesByPaymentMethod), datasets: [{ data: Object.values(salesByPaymentMethod), backgroundColor: ['#34d399', '#60a5fa', '#facc15'] }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { title: { display: true, text: 'Sales by Payment Method' }, legend: { position: 'bottom' } } } }); const timeCtx = document.getElementById('sales-by-time-chart').getContext('2d'); if(charts.time) charts.time.destroy(); const hourlySales = appData.transactions.reduce((acc, t) => { const hour = new Date(t.date).getHours(); acc[hour] = (acc[hour] || 0) + t.total; return acc; }, Array(24).fill(0)); charts.time = new Chart(timeCtx, { type: 'bar', data: { labels: Array.from({length: 15}, (_, i) => `${i+8}:00`), // 8am to 10pm datasets: [{ label: 'Sales Revenue', data: hourlySales.slice(8,23), backgroundColor: '#10b981' }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { title: { display: true, text: 'Hourly Sales' }, legend: { display: false } }, scales: { y: { beginAtZero: true } } } }); }; const renderPOSTerminal = () => { const posContent = document.getElementById('content-pos-terminal'); if (!posContent) return; const productGridHtml = appData.products.map(p => `

${p.name}

${formatCurrency(p.price)}

`).join(''); const cartItemsHtml = appData.currentCart.map(item => `

${item.name}

${formatCurrency(item.price)} x ${item.quantity}

${formatCurrency(item.price * item.quantity)}

`).join(''); const subtotal = appData.currentCart.reduce((sum, item) => sum + item.price * item.quantity, 0); const tax = subtotal * (appData.settings.taxRate / 100); const total = subtotal + tax; posContent.innerHTML = `
${productGridHtml}

Current Order

${cartItemsHtml || '

Cart is empty.

'}
Subtotal:${formatCurrency(subtotal)}
Tax (${appData.settings.taxRate}%):${formatCurrency(tax)}
Total:${formatCurrency(total)}

Payment Method

`; lucide.createIcons(); attachPOSListeners(); }; const renderConfiguration = () => { const configContent = document.getElementById('content-configuration'); if(!configContent) return; const productsHtml = appData.products.map(p => ` `).join(''); configContent.innerHTML = `

Product & Store Settings

${productsHtml}
Product Name Price ($) Stock
`; attachConfigListeners(); }; // --- EVENT HANDLERS & LOGIC --- const attachPOSListeners = () => { document.querySelectorAll('.product-card:not(.disabled)').forEach(card => { card.addEventListener('click', (e) => { const productId = parseInt(e.currentTarget.id.replace('product-', '')); addToCart(productId); }); }); document.querySelectorAll('.payment-btn').forEach(btn => { btn.addEventListener('click', (e) => { const method = e.currentTarget.dataset.method; completeSale(method); }); }); }; const addToCart = (productId) => { const product = appData.products.find(p => p.id === productId); const cartItem = appData.currentCart.find(item => item.id === productId); if(cartItem) { cartItem.quantity++; } else { appData.currentCart.push({ ...product, quantity: 1 }); } renderPOSTerminal(); }; const completeSale = (paymentMethod) => { if(appData.currentCart.length === 0) { alert('Cart is empty.'); return; } const subtotal = appData.currentCart.reduce((sum, item) => sum + item.price * item.quantity, 0); const tax = subtotal * (appData.settings.taxRate / 100); const total = subtotal + tax; appData.transactions.push({ id: Date.now(), items: [...appData.currentCart], total, paymentMethod, date: new Date().toISOString() }); appData.currentCart = []; appData.dashboardData = null; // Invalidate dashboard data renderPOSTerminal(); alert(`Sale of ${formatCurrency(total)} completed via ${paymentMethod}.`); calculateDashboardData(); renderDashboard(); }; const attachConfigListeners = () => { document.querySelectorAll('.config-input').forEach(input => { input.addEventListener('change', e => { const id = parseInt(e.target.dataset.id); const field = e.target.dataset.field; const value = field === 'name' ? e.target.value : parseFloat(e.target.value); const product = appData.products.find(p => p.id === id); if(product) product[field] = value; // No need to re-render config, but other tabs might need update renderPOSTerminal(); }); }); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; document.getElementById('pdf-generated-date').textContent = new Date().toLocaleDateString('en-US'); 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('POS-Sales-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: 'Sales Dashboard', id: 'sales-dashboard' }, { name: 'POS Terminal', id: 'pos-terminal' }, { name: 'Configuration', id: '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(); renderPOSTerminal(); renderConfiguration(); 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