You Receive in Payout
${formatCurrency(netAmount)}
`;
document.getElementById('download-pdf-btn').addEventListener('click', generatePdf);
};
const renderConfiguration = () => {
const configContent = document.getElementById('content-config');
if (!configContent) return;
configContent.innerHTML = `
`;
document.getElementById('fee-config-form').addEventListener('submit', handleConfigUpdate);
};
const handleConfigUpdate = (e) => {
e.preventDefault();
appData.fees.card_us.percent = parseFloat(document.getElementById('fee-card_us-percent').value);
appData.fees.card_us.fixed = parseFloat(document.getElementById('fee-card_us-fixed').value);
appData.fees.card_intl.percent = parseFloat(document.getElementById('fee-card_intl-percent').value);
appData.fees.card_intl.fixed = parseFloat(document.getElementById('fee-card_intl-fixed').value);
appData.fees.ach.percent = parseFloat(document.getElementById('fee-ach-percent').value);
appData.fees.ach.cap = parseFloat(document.getElementById('fee-ach-cap').value);
alert('Fee structure updated!');
};
const generatePdf = () => {
if (!calculationResult) return;
loadingOverlay.style.display = 'flex';
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
let y = 40;
pdf.setFontSize(18);
pdf.setFont('helvetica', 'bold');
pdf.text('Stripe Payment Fee Report', pdf.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 30;
pdf.setFontSize(10);
pdf.setFont('helvetica', 'normal');
pdf.text(`Generated on: ${new Date().toLocaleDateString()}`, 40, y);
y += 30;
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Calculation Summary', 40, y);
y += 15;
pdf.autoTable({
startY: y,
head: [['Parameter', 'Value']],
body: [
['Calculation Mode', calculationInputs.mode],
['Initial Amount', formatCurrency(calculationInputs.initialAmount)],
['Payment Method', calculationInputs.method],
],
theme: 'striped'
});
y = pdf.autoTable.previous.finalY + 30;
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Fee Breakdown', 40, y);
y += 15;
pdf.autoTable({
startY: y,
head: [['Description', 'Amount']],
body: [
['Amount Charged to Customer', formatCurrency(calculationResult.grossAmount)],
['Stripe Processing Fee', formatCurrency(calculationResult.stripeFee)],
['Net Amount Received', formatCurrency(calculationResult.netAmount)],
],
theme: 'grid',
headStyles: { fillColor: [109, 40, 217] }, // Violet header
foot: [
[{ content: 'Net Amount Received', colSpan: 1, styles: { halign: 'right', fontStyle: 'bold' } },
{ content: formatCurrency(calculationResult.netAmount), styles: { fontStyle: 'bold' } }]
],
footStyles: { fillColor: [245, 243, 255] }
});
pdf.save(`Stripe-Fee-Report.pdf`);
loadingOverlay.style.display = 'none';
};
// --- 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: 'Fee Calculator', id: 'calculator' },
{ name: 'Fee Structure', id: 'config' }
];
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));
});
renderCalculator();
renderConfiguration();
switchTab(0);
lucide.createIcons();
};
initializeUI();
prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); });
nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); });
});