calculateSavingsAndInvestment function
Implementation
Map<String, double> calculateSavingsAndInvestment(
double income,
double expense,
double spending,
double moneyReceived,
double transactionFee,
double savingsPercentage) {
// Calculate net income
double netIncome = income - expense - spending;
// Calculate amount to save
double amountToSave = (netIncome * (savingsPercentage / 100)) / 30;
// Calculate amount to invest
double amountToInvest = amountToSave - moneyReceived - transactionFee;
// Return savings and investment amount
return {
'savings': amountToSave.roundToDouble(),
'investment': amountToInvest >= 0 ? amountToInvest : 0
// Ensure investment amount is non-negative
};
}