FIA Split + AUM Split must equal 100%
`;
formsWrapper.appendChild(formSection);
// Add event listeners for FIA/AUM validation
const fiaInput = formSection.querySelector(`[name="PYFIASplit${i}"]`);
const aumInput = formSection.querySelector(`[name="PYAUMSplit${i}"]`);
const warningDiv = formSection.querySelector('.aum-fia-warning');
function validateSplit() {
const fia = parseFloat(fiaInput.value) || 0;
const aum = parseFloat(aumInput.value) || 0;
if (fia + aum !== 100) {
warningDiv.style.display = 'block';
fiaAumValid[i - 1] = false;
} else {
warningDiv.style.display = 'none';
fiaAumValid[i - 1] = true;
}
}
fiaInput.addEventListener('input', validateSplit);
aumInput.addEventListener('input', validateSplit);
// Add event listener for Previous Year % of Business validation
const pyBusinessInput = formSection.querySelector(`[name="previousYearBusiness${i}"]`);
pyBusinessInput.addEventListener('input', validatePYBusinessSum);
// Add event listener for Current Year % of Business validation
const cyBusinessInput = formSection.querySelector(`[name="currentYearBusiness${i}"]`);
cyBusinessInput.addEventListener('input', validateCYBusinessSum);
}
const footer = document.createElement('footer');
footer.style.textAlign = 'center';
footer.style.marginTop = '2em';
footer.style.fontSize = '1.1em';
footer.style.color = '#000000';
footer.textContent = 'If you have any questions, please contact us at hello@trackthatadvisor.com!';
formsWrapper.appendChild(footer);
// Add single submit button at the bottom
const submitBtn = document.createElement('button');
submitBtn.type = 'submit';
submitBtn.textContent = 'Download Report';
submitBtn.style.marginTop = '1em';
// Create a form to wrap the dynamic sections and button
const dynamicForm = document.createElement('form');
dynamicForm.id = 'dynamicSourcesForm';
dynamicForm.appendChild(formsWrapper);
dynamicForm.appendChild(submitBtn);
dynamicForm.onsubmit = function(e) {
e.preventDefault();
// Validate all inputs
const inputs = formsWrapper.querySelectorAll('input[required]');
let valid = true;
inputs.forEach(input => {
if (!input.value.trim()) {
input.focus();
valid = false;
return false;
}
});
// Check FIA/AUM validation for all sources
if (fiaAumValid.some(v => v === false)) {
alert('Annuity/Insurance Split + AUM Split must equal 100% for all sources.');
valid = false;
}
// Check Previous Year % of Business sum
if (!validatePYBusinessSum()) {
pyBusinessWarning.style.display = 'block';
alert('Sum of Previous Year - % of Business across all sources must equal 100%.');
valid = false;
}
// Check Current Year % of Business sum
if (!validateCYBusinessSum()) {
cyBusinessWarning.style.display = 'block';
alert('Sum of Current Year - % of Business across all sources must equal 100%.');
valid = false;
}
if (!valid) return;
container.style.display = 'block';
// Existing report logic
const formData = new FormData(document.getElementById('sampleForm'));
const data = {
Name: formData.get('name'),
Email: formData.get('email'),
Goal: formData.get('goal')
};
let Goal = parseFloat(data.Goal) || 0;
// Format Goal as currency
const formattedGoal = Goal.toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });
// Main report box
let reportHtml = `
Name: ${data.Name}
Email: ${data.Email}
Production Goal: ${formattedGoal}
`;
// Sources/funnels box
reportHtml += `
Marketing Sources / Funnels
`;
let goalFIA = 0;
let goalAUM = 0;
let totalBusiness = 0;
let totalCaseSize = 0;
for (let i = 1; i
${sourceName}
Goal FIA: $${sourceGoalFIA.toLocaleString()}
Goal AUM: $${sourceGoalAUM.toLocaleString()}
Total Goal: $${sourceTotalGoal.toLocaleString()}
# Set 1st Needed: ${neededSetFirst}
# Kept 1st Needed: ${neededKeptFirst}
# New Clients Needed: ${neededNewClients}
Monthly Average Set 1st: ${monthlyAvgSetFirst}
Monthly Average Kept 1st: ${monthlyAvgKeptFirst}
`;
}
reportHtml += `
`;
document.getElementById('report').innerHTML = reportHtml;
document.getElementById('report').style.display = 'block';
container.style.display = 'none';
// --- Download logic ---
// Create a complete HTML document for download
const downloadHtml = `
Reverse Engineer Your Success
${reportHtml}
`.trim();
// Create a Blob and trigger download
const blob = new Blob([downloadHtml], { type: 'text/html' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'TTAReverseEngineeringReport.html';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
container.appendChild(dynamicForm);
container.style.display = 'block';
});