export function netWorthCalculator(form: FormTs) {
form.addRow(row => {
row.addTextPanel('header', {
computedValue: () => 'Net Worth Calculator',
customStyles: { 'font-size': '1.5rem', 'font-weight': '600', 'color': '#1e293b' }
});
});
form.addSpacer({ height: 20 });
// Liquid Assets Section
const liquidSection = form.addSubform('liquid', { title: '💵 Cash & Liquid Assets' });
liquidSection.addRow(row => {
row.addMoney('checkingAccounts', {
label: 'Checking Accounts',
min: 0,
max: 100000000,
defaultValue: 5000,
tooltip: 'Total balance in all checking accounts'
}, '1fr');
row.addMoney('savingsAccounts', {
label: 'Savings Accounts',
min: 0,
max: 100000000,
defaultValue: 15000,
tooltip: 'Include high-yield savings, money market accounts'
}, '1fr');
});
liquidSection.addRow(row => {
row.addMoney('cashOnHand', {
label: 'Cash on Hand',
min: 0,
max: 1000000,
defaultValue: 500,
tooltip: 'Physical cash, petty cash'
}, '1fr');
row.addMoney('cds', {
label: 'CDs & Money Market',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Certificates of deposit, money market funds'
}, '1fr');
});
// Investment Assets Section
const investmentSection = form.addSubform('investments', { title: '📈 Investment Assets' });
investmentSection.addRow(row => {
row.addMoney('stocks', {
label: 'Stocks & ETFs',
min: 0,
max: 100000000,
defaultValue: 25000,
tooltip: 'Individual stocks, ETFs, mutual funds (taxable accounts)'
}, '1fr');
row.addMoney('bonds', {
label: 'Bonds',
min: 0,
max: 100000000,
defaultValue: 5000,
tooltip: 'Government and corporate bonds'
}, '1fr');
});
investmentSection.addRow(row => {
row.addMoney('retirement401k', {
label: '401(k) / 403(b)',
min: 0,
max: 100000000,
defaultValue: 50000,
tooltip: 'Employer-sponsored retirement accounts'
}, '1fr');
row.addMoney('iraAccounts', {
label: 'IRA Accounts',
min: 0,
max: 100000000,
defaultValue: 20000,
tooltip: 'Traditional IRA, Roth IRA, SEP IRA'
}, '1fr');
});
investmentSection.addRow(row => {
row.addMoney('otherInvestments', {
label: 'Other Investments',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'HSA, 529 plans, crypto, alternative investments'
}, '1fr');
row.addMoney('businessOwnership', {
label: 'Business Ownership',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Value of business interests'
}, '1fr');
});
// Property Assets Section
const propertySection = form.addSubform('property', { title: '🏠 Property & Physical Assets' });
propertySection.addRow(row => {
row.addMoney('primaryHome', {
label: 'Primary Residence',
min: 0,
max: 100000000,
defaultValue: 350000,
tooltip: 'Current market value of your home'
}, '1fr');
row.addMoney('otherRealEstate', {
label: 'Other Real Estate',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Rental properties, vacation homes, land'
}, '1fr');
});
propertySection.addRow(row => {
row.addMoney('vehicles', {
label: 'Vehicles',
min: 0,
max: 10000000,
defaultValue: 25000,
tooltip: 'Cars, motorcycles, boats, RVs (current value)'
}, '1fr');
row.addMoney('valuables', {
label: 'Jewelry & Collectibles',
min: 0,
max: 100000000,
defaultValue: 5000,
tooltip: 'Jewelry, art, antiques, collections'
}, '1fr');
});
propertySection.addRow(row => {
row.addMoney('otherAssets', {
label: 'Other Assets',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Furniture, electronics, other valuable items'
});
});
form.addSpacer({ height: 20, showLine: true, lineStyle: 'dashed' });
// Liabilities Section
const liabilitiesSection = form.addSubform('liabilities', { title: '💳 Liabilities (Debts)' });
liabilitiesSection.addRow(row => {
row.addMoney('mortgageBalance', {
label: 'Mortgage Balance',
min: 0,
max: 100000000,
defaultValue: 250000,
tooltip: 'Remaining balance on primary residence'
}, '1fr');
row.addMoney('otherMortgages', {
label: 'Other Property Loans',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Mortgages on rental/investment properties'
}, '1fr');
});
liabilitiesSection.addRow(row => {
row.addMoney('autoLoans', {
label: 'Auto Loans',
min: 0,
max: 1000000,
defaultValue: 15000,
tooltip: 'Total balance on all vehicle loans'
}, '1fr');
row.addMoney('studentLoans', {
label: 'Student Loans',
min: 0,
max: 10000000,
defaultValue: 25000,
tooltip: 'Federal and private student loans'
}, '1fr');
});
liabilitiesSection.addRow(row => {
row.addMoney('creditCards', {
label: 'Credit Card Debt',
min: 0,
max: 1000000,
defaultValue: 3000,
tooltip: 'Total balance on all credit cards'
}, '1fr');
row.addMoney('personalLoans', {
label: 'Personal Loans',
min: 0,
max: 10000000,
defaultValue: 0,
tooltip: 'Personal loans, lines of credit'
}, '1fr');
});
liabilitiesSection.addRow(row => {
row.addMoney('medicalDebt', {
label: 'Medical Debt',
min: 0,
max: 10000000,
defaultValue: 0,
tooltip: 'Unpaid medical bills'
}, '1fr');
row.addMoney('otherDebts', {
label: 'Other Debts',
min: 0,
max: 100000000,
defaultValue: 0,
tooltip: 'Tax debt, family loans, other obligations'
}, '1fr');
});
form.addSpacer({ height: 20, showLine: true, lineStyle: 'dashed' });
// Assets Summary
const assetsSummarySection = form.addSubform('assetsSummary', { title: '📊 Assets Summary', isCollapsible: true });
assetsSummarySection.addRow(row => {
row.addPriceDisplay('totalLiquid', {
label: 'Total Liquid Assets',
computedValue: () => {
const checking = liquidSection.decimal('checkingAccounts')?.value() || 0;
const savings = liquidSection.decimal('savingsAccounts')?.value() || 0;
const cash = liquidSection.decimal('cashOnHand')?.value() || 0;
const cds = liquidSection.decimal('cds')?.value() || 0;
return Math.round((checking + savings + cash + cds) * 100) / 100;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('totalInvestments', {
label: 'Total Investments',
computedValue: () => {
const stocks = investmentSection.decimal('stocks')?.value() || 0;
const bonds = investmentSection.decimal('bonds')?.value() || 0;
const retirement = investmentSection.decimal('retirement401k')?.value() || 0;
const ira = investmentSection.decimal('iraAccounts')?.value() || 0;
const other = investmentSection.decimal('otherInvestments')?.value() || 0;
const business = investmentSection.decimal('businessOwnership')?.value() || 0;
return Math.round((stocks + bonds + retirement + ira + other + business) * 100) / 100;
},
variant: 'default'
}, '1fr');
});
assetsSummarySection.addRow(row => {
row.addPriceDisplay('totalProperty', {
label: 'Total Property',
computedValue: () => {
const home = propertySection.decimal('primaryHome')?.value() || 0;
const otherRE = propertySection.decimal('otherRealEstate')?.value() || 0;
const vehicles = propertySection.decimal('vehicles')?.value() || 0;
const valuables = propertySection.decimal('valuables')?.value() || 0;
const other = propertySection.decimal('otherAssets')?.value() || 0;
return Math.round((home + otherRE + vehicles + valuables + other) * 100) / 100;
},
variant: 'default'
}, '1fr');
row.addPriceDisplay('totalAssets', {
label: 'TOTAL ASSETS',
computedValue: () => {
// Liquid
const checking = liquidSection.decimal('checkingAccounts')?.value() || 0;
const savings = liquidSection.decimal('savingsAccounts')?.value() || 0;
const cash = liquidSection.decimal('cashOnHand')?.value() || 0;
const cds = liquidSection.decimal('cds')?.value() || 0;
// Investments
const stocks = investmentSection.decimal('stocks')?.value() || 0;
const bonds = investmentSection.decimal('bonds')?.value() || 0;
const retirement = investmentSection.decimal('retirement401k')?.value() || 0;
const ira = investmentSection.decimal('iraAccounts')?.value() || 0;
const otherInv = investmentSection.decimal('otherInvestments')?.value() || 0;
const business = investmentSection.decimal('businessOwnership')?.value() || 0;
// Property
const home = propertySection.decimal('primaryHome')?.value() || 0;
const otherRE = propertySection.decimal('otherRealEstate')?.value() || 0;
const vehicles = propertySection.decimal('vehicles')?.value() || 0;
const valuables = propertySection.decimal('valuables')?.value() || 0;
const otherAssets = propertySection.decimal('otherAssets')?.value() || 0;
return Math.round((checking + savings + cash + cds + stocks + bonds + retirement + ira + otherInv + business + home + otherRE + vehicles + valuables + otherAssets) * 100) / 100;
},
variant: 'success'
}, '1fr');
});
// Liabilities Summary
const liabilitiesSummarySection = form.addSubform('liabilitiesSummary', { title: '📊 Liabilities Summary', isCollapsible: true });
liabilitiesSummarySection.addRow(row => {
row.addPriceDisplay('totalLiabilities', {
label: 'TOTAL LIABILITIES',
computedValue: () => {
const mortgage = liabilitiesSection.decimal('mortgageBalance')?.value() || 0;
const otherMortgages = liabilitiesSection.decimal('otherMortgages')?.value() || 0;
const auto = liabilitiesSection.decimal('autoLoans')?.value() || 0;
const student = liabilitiesSection.decimal('studentLoans')?.value() || 0;
const credit = liabilitiesSection.decimal('creditCards')?.value() || 0;
const personal = liabilitiesSection.decimal('personalLoans')?.value() || 0;
const medical = liabilitiesSection.decimal('medicalDebt')?.value() || 0;
const other = liabilitiesSection.decimal('otherDebts')?.value() || 0;
return Math.round((mortgage + otherMortgages + auto + student + credit + personal + medical + other) * 100) / 100;
},
variant: 'default'
});
});
// Net Worth Result
const resultSection = form.addSubform('result', { title: '💎 Your Net Worth', isCollapsible: false });
resultSection.addRow(row => {
row.addPriceDisplay('netWorth', {
label: 'NET WORTH',
computedValue: () => {
// Liquid
const checking = liquidSection.decimal('checkingAccounts')?.value() || 0;
const savings = liquidSection.decimal('savingsAccounts')?.value() || 0;
const cash = liquidSection.decimal('cashOnHand')?.value() || 0;
const cds = liquidSection.decimal('cds')?.value() || 0;
// Investments
const stocks = investmentSection.decimal('stocks')?.value() || 0;
const bonds = investmentSection.decimal('bonds')?.value() || 0;
const retirement = investmentSection.decimal('retirement401k')?.value() || 0;
const ira = investmentSection.decimal('iraAccounts')?.value() || 0;
const otherInv = investmentSection.decimal('otherInvestments')?.value() || 0;
const business = investmentSection.decimal('businessOwnership')?.value() || 0;
// Property
const home = propertySection.decimal('primaryHome')?.value() || 0;
const otherRE = propertySection.decimal('otherRealEstate')?.value() || 0;
const vehicles = propertySection.decimal('vehicles')?.value() || 0;
const valuables = propertySection.decimal('valuables')?.value() || 0;
const otherAssets = propertySection.decimal('otherAssets')?.value() || 0;
const totalAssets = checking + savings + cash + cds + stocks + bonds + retirement + ira + otherInv + business + home + otherRE + vehicles + valuables + otherAssets;
// Liabilities
const mortgage = liabilitiesSection.decimal('mortgageBalance')?.value() || 0;
const otherMortgages = liabilitiesSection.decimal('otherMortgages')?.value() || 0;
const auto = liabilitiesSection.decimal('autoLoans')?.value() || 0;
const student = liabilitiesSection.decimal('studentLoans')?.value() || 0;
const credit = liabilitiesSection.decimal('creditCards')?.value() || 0;
const personal = liabilitiesSection.decimal('personalLoans')?.value() || 0;
const medical = liabilitiesSection.decimal('medicalDebt')?.value() || 0;
const other = liabilitiesSection.decimal('otherDebts')?.value() || 0;
const totalLiabilities = mortgage + otherMortgages + auto + student + credit + personal + medical + other;
return Math.round((totalAssets - totalLiabilities) * 100) / 100;
},
variant: 'large'
});
});
resultSection.addRow(row => {
row.addTextPanel('homeEquity', {
label: 'Home Equity',
computedValue: () => {
const home = propertySection.decimal('primaryHome')?.value() || 0;
const mortgage = liabilitiesSection.decimal('mortgageBalance')?.value() || 0;
const equity = home - mortgage;
return `$${equity.toLocaleString()}`;
},
customStyles: { 'font-size': '1.1rem', 'text-align': 'center', 'color': '#475569' }
}, '1fr');
row.addTextPanel('debtToAssetRatio', {
label: 'Debt-to-Asset Ratio',
computedValue: () => {
// Calculate total assets
const checking = liquidSection.decimal('checkingAccounts')?.value() || 0;
const savings = liquidSection.decimal('savingsAccounts')?.value() || 0;
const cash = liquidSection.decimal('cashOnHand')?.value() || 0;
const cds = liquidSection.decimal('cds')?.value() || 0;
const stocks = investmentSection.decimal('stocks')?.value() || 0;
const bonds = investmentSection.decimal('bonds')?.value() || 0;
const retirement = investmentSection.decimal('retirement401k')?.value() || 0;
const ira = investmentSection.decimal('iraAccounts')?.value() || 0;
const otherInv = investmentSection.decimal('otherInvestments')?.value() || 0;
const business = investmentSection.decimal('businessOwnership')?.value() || 0;
const home = propertySection.decimal('primaryHome')?.value() || 0;
const otherRE = propertySection.decimal('otherRealEstate')?.value() || 0;
const vehicles = propertySection.decimal('vehicles')?.value() || 0;
const valuables = propertySection.decimal('valuables')?.value() || 0;
const otherAssets = propertySection.decimal('otherAssets')?.value() || 0;
const totalAssets = checking + savings + cash + cds + stocks + bonds + retirement + ira + otherInv + business + home + otherRE + vehicles + valuables + otherAssets;
// Calculate total liabilities
const mortgage = liabilitiesSection.decimal('mortgageBalance')?.value() || 0;
const otherMortgages = liabilitiesSection.decimal('otherMortgages')?.value() || 0;
const auto = liabilitiesSection.decimal('autoLoans')?.value() || 0;
const student = liabilitiesSection.decimal('studentLoans')?.value() || 0;
const credit = liabilitiesSection.decimal('creditCards')?.value() || 0;
const personal = liabilitiesSection.decimal('personalLoans')?.value() || 0;
const medical = liabilitiesSection.decimal('medicalDebt')?.value() || 0;
const other = liabilitiesSection.decimal('otherDebts')?.value() || 0;
const totalLiabilities = mortgage + otherMortgages + auto + student + credit + personal + medical + other;
if (totalAssets === 0) return '0%';
const ratio = (totalLiabilities / totalAssets) * 100;
return `${(Number(ratio) || 0).toFixed(1)}%`;
},
customStyles: { 'font-size': '1.1rem', 'text-align': 'center', 'color': '#475569' }
}, '1fr');
});
// Summary Section
const summarySection = form.addSubform('summary', {
title: '📋 Summary',
isCollapsible: false,
sticky: 'bottom'
});
summarySection.addRow(row => {
row.addTextPanel('summaryText', {
computedValue: () => {
// Calculate net worth for summary
const checking = liquidSection.decimal('checkingAccounts')?.value() || 0;
const savings = liquidSection.decimal('savingsAccounts')?.value() || 0;
const cash = liquidSection.decimal('cashOnHand')?.value() || 0;
const cds = liquidSection.decimal('cds')?.value() || 0;
const stocks = investmentSection.decimal('stocks')?.value() || 0;
const bonds = investmentSection.decimal('bonds')?.value() || 0;
const retirement = investmentSection.decimal('retirement401k')?.value() || 0;
const ira = investmentSection.decimal('iraAccounts')?.value() || 0;
const otherInv = investmentSection.decimal('otherInvestments')?.value() || 0;
const business = investmentSection.decimal('businessOwnership')?.value() || 0;
const home = propertySection.decimal('primaryHome')?.value() || 0;
const otherRE = propertySection.decimal('otherRealEstate')?.value() || 0;
const vehicles = propertySection.decimal('vehicles')?.value() || 0;
const valuables = propertySection.decimal('valuables')?.value() || 0;
const otherAssets = propertySection.decimal('otherAssets')?.value() || 0;
const totalAssets = checking + savings + cash + cds + stocks + bonds + retirement + ira + otherInv + business + home + otherRE + vehicles + valuables + otherAssets;
const mortgage = liabilitiesSection.decimal('mortgageBalance')?.value() || 0;
const otherMortgages = liabilitiesSection.decimal('otherMortgages')?.value() || 0;
const auto = liabilitiesSection.decimal('autoLoans')?.value() || 0;
const student = liabilitiesSection.decimal('studentLoans')?.value() || 0;
const credit = liabilitiesSection.decimal('creditCards')?.value() || 0;
const personal = liabilitiesSection.decimal('personalLoans')?.value() || 0;
const medical = liabilitiesSection.decimal('medicalDebt')?.value() || 0;
const other = liabilitiesSection.decimal('otherDebts')?.value() || 0;
const totalLiabilities = mortgage + otherMortgages + auto + student + credit + personal + medical + other;
const netWorth = totalAssets - totalLiabilities;
if (netWorth >= 0) {
return `Your net worth is $${netWorth.toLocaleString()}. You own more than you owe!`;
} else {
return `Your net worth is -$${Math.abs(netWorth).toLocaleString()}. Focus on paying down debt and building assets.`;
}
},
customStyles: { 'font-size': '0.95rem', 'font-weight': '500', 'text-align': 'center', 'color': '#1e293b' }
});
});
summarySection.addRow(row => {
row.addTextPanel('disclaimer', {
computedValue: () => 'Track your net worth monthly to measure financial progress. This calculator provides estimates - consult a financial advisor for personalized planning.',
customStyles: { 'font-size': '0.8rem', 'color': '#64748b', 'text-align': 'center' }
});
});
form.configureSubmitButton({
label: 'Save My Net Worth'
});
}