private void addGoalsCalculation(int years, DataRow dr) { double totalLoanEmi = 0; double totalCashAllocationForGoal = 0; int calculationYear = int.Parse(dr["StartYear"].ToString()); double surplusAmount = getSurplusAmount(dr); foreach (Goals goal in _cashFlow.LstGoals) { //Add Loan EMI if loan taken for goal //Loan for Goal double loanForGoalValue = 0; double emi = 0; if (goal.LoanForGoal != null) { if (calculationYear >= goal.LoanForGoal.StratYear && calculationYear < goal.LoanForGoal.EndYear) { dr[string.Format("(Loan EMI - {0})", goal.Name)] = (goal.LoanForGoal.EMI * 12); totalLoanEmi = totalLoanEmi + (goal.LoanForGoal.EMI * 12); } } if (surplusAmount > 0 && (calculationYear < int.Parse(goal.StartYear))) { GoalsValueCalculationInfo goalValCalInfo = GoalCalculationMgr.GetGoalValueCalculation(goal); if (goalValCalInfo == null) { goalValCalInfo = new GoalsValueCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId); GoalCalculationMgr.AddGoalValueCalculation(goalValCalInfo); } GoalsCalculationInfo goalcalInfo = new GoalsCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId, _optionId); goalValCalInfo.SetPortfolioValue(goalcalInfo.GetProfileValue()); double surplusAmountAfterInvestment = goalValCalInfo.SetInvestmentToAchiveGoal(calculationYear, surplusAmount); dr[string.Format("{0} - {1}", goal.Priority, goal.Name)] = surplusAmount - surplusAmountAfterInvestment; surplusAmount = surplusAmountAfterInvestment; } } }
private void addFirstRowData(int rowId) { DataRow dr = _dtCashFlow.NewRow(); dr["ID"] = rowId; dr["StartYear"] = _planner.StartDate.Year; #region "Add Incomes" double totalIncome = 0; double totalpostTaxIncome = 0; double totalTaxAmt = 0; foreach (Income income in _cashFlow.LstIncomes) { dr["(" + income.IncomeBy + ") " + income.Source] = income.Amount; totalIncome = totalIncome + income.Amount; dr["(" + income.IncomeBy + ") " + income.Source + " - Income Tax"] = income.IncomeTax; double taxAmt = (income.Amount * income.IncomeTax) / 100; totalTaxAmt = totalTaxAmt + taxAmt; dr["(" + income.IncomeBy + ") " + income.Source + " - Post Tax"] = income.Amount - taxAmt; totalpostTaxIncome = totalpostTaxIncome + (income.Amount - taxAmt); } dr["Total Income"] = totalIncome; dr["Total Tax Deduction"] = totalTaxAmt; dr["Total Post Tax Income"] = totalpostTaxIncome; #endregion #region "Add Expenses" double totalExpenses = 0; foreach (Expenses exp in _cashFlow.LstExpenses) { double expAmt = (exp.OccuranceType == ExpenseType.Monthly) ? exp.Amount * 12 : exp.Amount; dr[exp.Item] = expAmt; totalExpenses = totalExpenses + expAmt; } dr["Total Annual Expenses"] = totalExpenses; #endregion #region "Add Loans" double totalLoan = 0; foreach (Loan loan in _cashFlow.LstLoans) { double loanAmt = loan.Emis * 12; dr[loan.TypeOfLoan] = loanAmt; totalLoan = totalLoan + loanAmt; } dr["Total Annual Loans"] = totalLoan; #endregion #region "Add Goals" double totalLoanEmi = 0; double surplusCashFund = (totalpostTaxIncome - (totalExpenses + totalLoan + totalLoanEmi)); foreach (Goals goal in _cashFlow.LstGoals) { //1 Loan for Goal double loanForGoalValue = 0; double emi = 0; if (goal.LoanForGoal != null) { loanForGoalValue = goal.LoanForGoal.LoanAmount; if (_planner.StartDate.Year >= goal.LoanForGoal.StratYear) { dr[string.Format("(Loan EMI - {0})", goal.Name)] = goal.LoanForGoal.EMI; totalLoanEmi = totalLoanEmi + goal.LoanForGoal.EMI; emi = goal.LoanForGoal.EMI; } } //2 Cash Flow and fund allocation to goal if (surplusCashFund > 0) { _riskProfileInfo = new RiskProfileInfo(); GoalsValueCalculationInfo goalValCalInfo = new GoalsValueCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId); GoalsCalculationInfo goalcalInfo = new GoalsCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId, _optionId); goalValCalInfo.SetPortfolioValue(goalcalInfo.GetProfileValue()); GoalCalculationMgr.AddGoalValueCalculation(goalValCalInfo); double surplusAmountAfterInvestment = goalValCalInfo.SetInvestmentToAchiveGoal(_planner.StartDate.Year, surplusCashFund); dr[string.Format("{0} - {1}", goal.Priority, goal.Name)] = surplusCashFund - surplusAmountAfterInvestment; surplusCashFund = surplusAmountAfterInvestment; } else { _riskProfileInfo = new RiskProfileInfo(); GoalsValueCalculationInfo goalValCalInfo = new GoalsValueCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId); GoalsCalculationInfo goalcalInfo = new GoalsCalculationInfo(goal, _planner, _riskProfileInfo, _riskProfileId, _optionId); goalValCalInfo.SetPortfolioValue(goalcalInfo.GetProfileValue()); GoalCalculationMgr.AddGoalValueCalculation(goalValCalInfo); } } #endregion dr["Surplus Amount"] = totalpostTaxIncome - (totalExpenses + totalLoan + totalLoanEmi); _dtCashFlow.Rows.Add(dr); }