Daily Spending Cutback Analyzer

Daily Spending Cutback Analyzer

Identify Frequent Small Expenses

No expenses added yet.

Total Current Spending: Weekly: $0.00 | Monthly: $0.00 | Annual: $0.00

Plan Cutbacks

Add expenses in Tab 1 to plan cutbacks.

Total Projected Savings: Weekly: $0.00 | Monthly: $0.00 | Annual: $0.00

Savings Summary & Export

Your savings summary will appear here once cutbacks are planned.

Add expenses in Tab 1 to plan cutbacks.

'; dsca_updateTotalProjectedSavingsDisplay(); return; } dsca_dailyExpenses.forEach(exp => { const currentCosts = dsca_calculateItemCosts(exp); const itemDiv = document.createElement('div'); itemDiv.className = 'dsca-cutback-item'; itemDiv.innerHTML = `

${exp.name}

Current: $${exp.costPerOccurrence.toFixed(2)}/occurrence, ${exp.occurrencesPerDay}x/day, ${exp.daysPerWeek} days/wk. (Annual: $${currentCosts.annual.toFixed(2)})

Projected Saving: Weekly: $0.00 | Monthly: $0.00 | Annual: $0.00

`; area.appendChild(itemDiv); dsca_calculateAndDisplayItemSavings(exp.id); // Initial calculation for this item }); dsca_updateTotalProjectedSavingsDisplay(); } function dsca_updateExpenseCutback(expenseId) { const expense = dsca_dailyExpenses.find(exp => exp.id === expenseId); if (!expense) return; expense.newCostPerOccurrence = parseFloat(document.getElementById(`newCost_${expenseId}`).value) || 0; expense.newOccurrencesPerDay = parseInt(document.getElementById(`newTimesDay_${expenseId}`).value) || 0; expense.newDaysPerWeek = parseInt(document.getElementById(`newDaysWeek_${expenseId}`).value) || 0; // Basic validation if (expense.newCostPerOccurrence < 0) expense.newCostPerOccurrence = 0; if (expense.newOccurrencesPerDay < 0) expense.newOccurrencesPerDay = 0; if (expense.newDaysPerWeek < 0) expense.newDaysPerWeek = 0; if (expense.newDaysPerWeek > 7) expense.newDaysPerWeek = 7; dsca_calculateAndDisplayItemSavings(expenseId); dsca_updateTotalProjectedSavingsDisplay(); } function dsca_calculateAndDisplayItemSavings(expenseId) { const expense = dsca_dailyExpenses.find(exp => exp.id === expenseId); if (!expense) return; const current = dsca_calculateItemCosts(expense); const newCalcItem = { costPerOccurrence: expense.newCostPerOccurrence, occurrencesPerDay: expense.newOccurrencesPerDay, daysPerWeek: expense.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); document.getElementById(`savedWeekly_${expenseId}`).textContent = (current.weekly - newCosts.weekly).toFixed(2); document.getElementById(`savedMonthly_${expenseId}`).textContent = (current.monthly - newCosts.monthly).toFixed(2); document.getElementById(`savedAnnual_${expenseId}`).textContent = (current.annual - newCosts.annual).toFixed(2); } function dsca_updateTotalProjectedSavingsDisplay() { let totalSavedWeekly = 0; dsca_dailyExpenses.forEach(exp => { const current = dsca_calculateItemCosts(exp); const newCalcItem = { costPerOccurrence: exp.newCostPerOccurrence, occurrencesPerDay: exp.newOccurrencesPerDay, daysPerWeek: exp.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); totalSavedWeekly += (current.weekly - newCosts.weekly); }); const totalSavedMonthly = totalSavedWeekly * WEEKS_PER_MONTH_APPROX; const totalSavedAnnual = totalSavedWeekly * 52; const displayDiv = document.getElementById('dscaTotalProjectedSavingsDisplay'); if(displayDiv) { displayDiv.innerHTML = `Total Projected Savings: Weekly: $${totalSavedWeekly.toFixed(2)} | Monthly: $${totalSavedMonthly.toFixed(2)} | Annual: $${totalSavedAnnual.toFixed(2)}`; } } // --- Savings Summary (Tab 3) & PDF --- function dsca_generateSavingsSummaryDisplay() { const summaryArea = document.getElementById('dscaPlanSummaryArea'); const detailsContainer = document.getElementById('dscaPlanDetailsTableContainer'); let totalCurrentAnnual = 0; let totalSavedAnnual = 0; dsca_dailyExpenses.forEach(exp => { const current = dsca_calculateItemCosts(exp); const newCalcItem = { costPerOccurrence: exp.newCostPerOccurrence, occurrencesPerDay: exp.newOccurrencesPerDay, daysPerWeek: exp.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); totalCurrentAnnual += current.annual; totalSavedAnnual += (current.annual - newCosts.annual); }); const newProjectedAnnual = totalCurrentAnnual - totalSavedAnnual; summaryArea.innerHTML = `

Overall Savings Metrics

Total Current Annual Spending (on these items): $${totalCurrentAnnual.toFixed(2)}

Total Projected Annual Savings: $${totalSavedAnnual.toFixed(2)}

New Projected Annual Spending (on these items): $${newProjectedAnnual.toFixed(2)}

`; let tableHTML = `

Detailed Cutback Plan:

`; if (dsca_dailyExpenses.length === 0) { tableHTML += ``; } else { dsca_dailyExpenses.forEach(exp => { const current = dsca_calculateItemCosts(exp); const newCalcItem = { costPerOccurrence: exp.newCostPerOccurrence, occurrencesPerDay: exp.newOccurrencesPerDay, daysPerWeek: exp.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); const savedAnnual = current.annual - newCosts.annual; let cutbackDesc = `Cost: $${exp.costPerOccurrence.toFixed(2)} -> $${exp.newCostPerOccurrence.toFixed(2)}. `; cutbackDesc += `Freq: ${exp.occurrencesPerDay}x/day, ${exp.daysPerWeek}d/wk -> ${exp.newOccurrencesPerDay}x/day, ${exp.newDaysPerWeek}d/wk.`; tableHTML += ``; }); } tableHTML += '
ExpenseOriginal Annual ($)Cutback PlanNew Annual ($)Annual Saving ($)
No expenses defined.
${exp.name}${current.annual.toFixed(2)} ${cutbackDesc} ${newCosts.annual.toFixed(2)}${savedAnnual.toFixed(2)}
'; detailsContainer.innerHTML = tableHTML; } function dsca_generatePdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); let yPos = 20; const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim(); const accentColor = getComputedStyle(document.documentElement).getPropertyValue('--accent-color').trim(); const textColor = getComputedStyle(document.documentElement).getPropertyValue('--text-color').trim(); doc.setFontSize(20); doc.setTextColor(primaryColor); doc.text("Daily Spending Cutback Analysis", doc.internal.pageSize.getWidth() / 2, yPos, { align: 'center' }); yPos += 15; let totalCurrentAnnual = 0, totalSavedAnnual = 0; dsca_dailyExpenses.forEach(exp => { const current = dsca_calculateItemCosts(exp); const newCalcItem = { costPerOccurrence: exp.newCostPerOccurrence, occurrencesPerDay: exp.newOccurrencesPerDay, daysPerWeek: exp.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); totalCurrentAnnual += current.annual; totalSavedAnnual += (current.annual - newCosts.annual); }); const newProjectedAnnual = totalCurrentAnnual - totalSavedAnnual; doc.setFontSize(14); doc.setTextColor(primaryColor); doc.text("Overall Savings Summary", 14, yPos); yPos += 8; doc.setFontSize(11); doc.setTextColor(textColor); doc.text(`Total Current Annual Spending (on listed items): $${totalCurrentAnnual.toFixed(2)}`, 14, yPos); yPos += 7; doc.setTextColor(accentColor); doc.text(`Total Projected Annual Savings: $${totalSavedAnnual.toFixed(2)}`, 14, yPos); yPos += 7; doc.setTextColor(textColor); doc.text(`New Projected Annual Spending (on listed items): $${newProjectedAnnual.toFixed(2)}`, 14, yPos); yPos += 10; if (dsca_dailyExpenses.length > 0) { if (yPos > 250) { doc.addPage(); yPos = 20; } doc.setFontSize(14); doc.setTextColor(primaryColor); doc.text("Detailed Cutback Plan", 14, yPos); yPos += 8; const tableBody = dsca_dailyExpenses.map(exp => { const current = dsca_calculateItemCosts(exp); const newCalcItem = { costPerOccurrence: exp.newCostPerOccurrence, occurrencesPerDay: exp.newOccurrencesPerDay, daysPerWeek: exp.newDaysPerWeek }; const newCosts = dsca_calculateItemCosts(newCalcItem); const savedAnnual = current.annual - newCosts.annual; let cutbackDesc = `Cost: $${exp.costPerOccurrence.toFixed(2)} -> $${exp.newCostPerOccurrence.toFixed(2)}. `; cutbackDesc += `Freq: ${exp.occurrencesPerDay}x/day, ${exp.daysPerWeek}d/wk -> ${exp.newOccurrencesPerDay}x/day, ${exp.newDaysPerWeek}d/wk.`; return [exp.name, `$${current.annual.toFixed(2)}`, cutbackDesc, `$${newCosts.annual.toFixed(2)}`, `$${savedAnnual.toFixed(2)}`]; }); doc.autoTable({ startY: yPos, head: [['Expense', 'Original Annual ($)', 'Cutback Plan', 'New Annual ($)', 'Annual Saving ($)']], body: tableBody, theme: 'grid', headStyles: { fillColor: primaryColor, textColor: '#ffffff' }, styles: { fontSize: 8, cellPadding: 1.5 }, columnStyles: { 2: { cellWidth: 'wrap', overflow: 'linebreak', minCellWidth: 50 } }, didDrawPage: (data) => { yPos = data.cursor.y; } }); } else { doc.setFontSize(11); doc.text("No detailed cutback items defined.", 14, yPos); } doc.save('daily_spending_cutback_analysis.pdf'); } // Initialize document.addEventListener('DOMContentLoaded', () => { dsca_showTab(0); dsca_renderDailyExpensesTable(); dsca_updateTotalCurrentSpendingDisplay(); // Demo data dsca_dailyExpenses.push({id: 'exp_001', name: 'Takeout Coffee', costPerOccurrence: 4.00, occurrencesPerDay: 1, daysPerWeek: 5, newCostPerOccurrence: 4.00, newOccurrencesPerDay: 1, newDaysPerWeek: 2}); dsca_dailyExpenses.push({id: 'exp_002', name: 'Lunch at Work', costPerOccurrence: 12.00, occurrencesPerDay: 1, daysPerWeek: 3, newCostPerOccurrence: 8.00, newOccurrencesPerDay: 1, newDaysPerWeek: 1}); dsca_renderDailyExpensesTable(); dsca_updateTotalCurrentSpendingDisplay(); });
Scroll to Top