calculateSavingsAndInvestment function

Map<String, double> calculateSavingsAndInvestment(
  1. double income,
  2. double expense,
  3. double spending,
  4. double moneyReceived,
  5. double transactionFee,
  6. double savingsPercentage,
)

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
  };
}