public DataSet BindfinancialPlan_grid()
        {
            planResult = financialPlanResult();
            DataSet dataS = expDAL.getFinancialPlanResult();

            return(dataS);
        }
Example #2
0
        public FinancialDecisionBO financialDecision(string loanType, decimal loanAmount, int targetMonths, decimal interestRate)
        {
            expenseB    = expenseD.GetExpenseDetail();
            incomeB     = incomeD.GetIncomeDetail();
            expenseT    = planCompute.InsertExpenseManage(expenseB, incomeB);
            totalIncome = incomeB.bankAccount + incomeB.jobIncome + incomeB.rentalIncome + incomeB.retirementPension + incomeB.socialSecurity + incomeB.otherSources;
            decimal saving_value              = (totalIncome * 34) / 100;
            decimal lastMonthexpense          = expenseT.householdActual_value + expenseT.healthActual_value + expenseT.educationActual_value + expenseT.travelActual_value + expenseT.lifestyleActual_value;
            decimal lastMonthexppercentage    = (lastMonthexpense / totalIncome) * 100;
            decimal lastMonthSavingAmount     = totalIncome - lastMonthexpense;
            decimal lastMonthSavingPercentage = 100 - lastMonthexppercentage;
            decimal maximum_saving            = (totalIncome * 50) / 100;

            decimal totalMonths          = (decimal)(loanAmount / saving_value);
            decimal annualinterestAmount = (decimal)(loanAmount * (interestRate / 100)) / 12;
            decimal interestAmount       = (decimal)annualinterestAmount * targetMonths;
            decimal totalTargetLoanAount = loanAmount + interestAmount;
            decimal loanEMI           = totalTargetLoanAount / targetMonths;
            decimal loanEMIpercentage = (loanEMI / totalIncome) * 100;

            financialD.targetMonths1           = targetMonths;
            financialD.interestRate            = interestRate;
            financialD.totalAmountwithInterest = totalTargetLoanAount;
            financialD.EMIamount = loanEMI;


            if ((decimal)34.00 < loanEMIpercentage && loanEMIpercentage <= (decimal)50.00) //More saving required for payignloan EMI
            {
                planResult1 = planCompute.financialPlanResult();
                decimal total = loanEMIpercentage - (decimal)34.00;
                financialD.savingDiffPercentage = total;
                financialD.savingDiffAmount     = (total * totalIncome) / 100;
                decimal estHouseholdTH = expenseT.householdTh - (decimal)(((decimal)((expenseT.householdTh / 66) * 100) * total) / 100);
                expenseT.householdTh = estHouseholdTH;
                decimal estHealthTH = expenseT.healthTh - (decimal)(((decimal)((expenseT.healthTh / 66) * 100) * total) / 100);
                expenseT.healthTh = estHealthTH;
                decimal estEducationTH = expenseT.educationTH - (decimal)(((decimal)((expenseT.educationTH / 66) * 100) * total) / 100);
                expenseT.educationTH = estEducationTH;
                decimal estTravelTH = expenseT.travelTH - (decimal)(((decimal)((expenseT.travelTH / 66) * 100) * total) / 100);
                expenseT.travelTH = estTravelTH;
                decimal estLifestyleTH = expenseT.lifestyleTH - (decimal)(((decimal)((expenseT.lifestyleTH / 66) * 100) * total) / 100);
                expenseT.lifestyleTH = estLifestyleTH;

                thresholdDifference();

                decimal totalExpensePercentage = expenseT.householdActual_percentage + expenseT.healthActual_percentage + expenseT.educationActual_percentage + expenseT.travelActual_percentage + expenseT.lifestyleActual_percentage;
                decimal savingdiff             = basicSaving - (100 - totalExpensePercentage);
                decimal totalTH = expenseT.householdTh + expenseT.healthTh + expenseT.educationTH + expenseT.lifestyleTH + expenseT.travelTH;
                savingRemain = totalTH - totalExpensePercentage;


                i = 0;

                for (int n = 0; n < m; n++)             //adjusting priority expense types percentages
                {
                    // temp= arrexpenseneg[n];
                    while (arrexpenseneg[n] != 0)
                    {
                        for (int l = 0; l < size; l++)
                        {
                            if (arrExpense[l] >= arrexpenseneg[n])
                            {
                                arrExpense[l]    = arrExpense[l] - arrexpenseneg[n];
                                arrexpenseneg[n] = 0;
                            }
                            else if (arrExpense[l] < arrexpenseneg[n] && arrExpense[l] != 0)
                            {
                                arrexpenseneg[n] = arrexpenseneg[n] - arrExpense[l];
                                arrExpense[l]    = 0;
                            }
                        }
                        savingRemain     = savingRemain - arrexpenseneg[n];
                        arrexpenseneg[n] = 0;
                    }
                }
                for (int p = 0; p < size; p++)           //Adding remaining percentages of all types of expenses to basic saving percentages
                {
                    if (arrExpense[p] > 0)
                    {
                        basicSaving = basicSaving + arrExpense[p];
                        //arrExpense[p]=0;
                    }
                }

                UpdatingExpenses(arrExpense, arrexpName, arrexpenseneg, arrexpName1);
            }
            else if ((decimal)34.00 >= loanEMIpercentage)                                                        //Loan EMI amount getting save easily
            {
                if (loanEMIpercentage > lastMonthSavingPercentage && lastMonthSavingPercentage < (decimal)34.00) //User need to save more amount as compare to last month and he/she may follow ideal financial plan
                {
                    decimal total = loanEMIpercentage - lastMonthSavingPercentage;
                    financialD.savingDiffPercentage = total;

                    financialD.savingDiffAmount = (total * totalIncome) / 100;
                    thresholdDifference();

                    i = 0;

                    while (total != 0)
                    {
                        if (arrExpense[i] >= total)
                        {
                            arrExpense[i] = arrExpense[i] - total;
                            total         = 0;
                        }
                        else if (arrExpense[i] < total)
                        {
                            total         = total - arrExpense[i];
                            arrExpense[i] = 0;
                            i++;
                        }
                    }
                    financialDecisionCompute(total);
                }
                else if (lastMonthSavingPercentage >= loanEMIpercentage && lastMonthSavingPercentage <= (decimal)34.00)// saving is enough to pay EMI of loan but user may follow ideal financial plan
                {
                    decimal total = (decimal)34.00 - lastMonthSavingPercentage;
                    financialD.savingDiffPercentage = (decimal)0.00;

                    financialD.savingDiffAmount = (decimal)0.00;
                    thresholdDifference();
                    financialDecisionCompute(total);
                }
                planResult1 = UpdatingExpenses(arrExpense, arrexpName, arrexpenseneg, arrexpName1);
            }

            expDAL.UpdateExpense_PlanResult(planResult1);
            return(financialD);
        }
Example #3
0
        public Int32 UpdateExpense_PlanResult(FinancialPlanResult finPlan)
        {
            int result;

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("sp_update_Result_expense_plan", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Expenses", "Household");
                command.Parameters.AddWithValue("@Percentage_of_total_income_on_expense", finPlan.householdPlan_percentage);
                command.Parameters.AddWithValue("@Amount_of_total_income_on_expense", finPlan.householdPlan_value);
                command.Parameters.AddWithValue("@Possible_saving_percentage", finPlan.householdSavingPersentages);
                command.Parameters.AddWithValue("@Possible_saving_amount", finPlan.householdSavingAmount);


                result = command.ExecuteNonQuery();
                command.Dispose();
                connection.Close();


                connection.Open();
                SqlCommand command1 = new SqlCommand("sp_update_Result_expense_plan", connection);
                command1.CommandType = CommandType.StoredProcedure;
                command1.Parameters.AddWithValue("@Expenses", "Health");
                command1.Parameters.AddWithValue("@Percentage_of_total_income_on_expense", finPlan.healthPlan_percentage);
                command1.Parameters.AddWithValue("@Amount_of_total_income_on_expense", finPlan.healthPlan_value);
                command1.Parameters.AddWithValue("@Possible_saving_percentage", finPlan.healthSavingPersentages);
                command1.Parameters.AddWithValue("@Possible_saving_amount", finPlan.healthSavingAmount);


                result = command1.ExecuteNonQuery();
                command1.Dispose();
                connection.Close();


                connection.Open();
                SqlCommand command2 = new SqlCommand("sp_update_Result_expense_plan", connection);
                command2.CommandType = CommandType.StoredProcedure;
                command2.Parameters.AddWithValue("@Expenses", "Education");
                command2.Parameters.AddWithValue("@Percentage_of_total_income_on_expense", finPlan.educationPlan_percentage);
                command2.Parameters.AddWithValue("@Amount_of_total_income_on_expense", finPlan.educationPlan_value);
                command2.Parameters.AddWithValue("@Possible_saving_percentage", finPlan.educationSavingPersentages);
                command2.Parameters.AddWithValue("@Possible_saving_amount", finPlan.educationSavingAmount);


                result = command2.ExecuteNonQuery();
                command2.Dispose();
                connection.Close();


                connection.Open();
                SqlCommand command3 = new SqlCommand("sp_update_Result_expense_plan", connection);
                command3.CommandType = CommandType.StoredProcedure;
                command3.Parameters.AddWithValue("@Expenses", "Travel");
                command3.Parameters.AddWithValue("@Percentage_of_total_income_on_expense", finPlan.travelPlan_percentage);
                command3.Parameters.AddWithValue("@Amount_of_total_income_on_expense", finPlan.travelPlan_value);
                command3.Parameters.AddWithValue("@Possible_saving_percentage", finPlan.travelSavingPersentages);
                command3.Parameters.AddWithValue("@Possible_saving_amount", finPlan.travelSavingAmount);


                result = command3.ExecuteNonQuery();
                command3.Dispose();
                connection.Close();


                connection.Open();
                SqlCommand command4 = new SqlCommand("sp_update_Result_expense_plan", connection);
                command4.CommandType = CommandType.StoredProcedure;
                command4.Parameters.AddWithValue("@Expenses", "Lifestyle");
                command4.Parameters.AddWithValue("@Percentage_of_total_income_on_expense", finPlan.lifestylePlan_percentage);
                command4.Parameters.AddWithValue("@Amount_of_total_income_on_expense", finPlan.lifestylePlan_value);
                command4.Parameters.AddWithValue("@Possible_saving_percentage", finPlan.lifestyleSavingPersentages);
                command4.Parameters.AddWithValue("@Possible_saving_amount", finPlan.lifestyleSavingAmount);


                result = command4.ExecuteNonQuery();
                command4.Dispose();

                if (result > 0)
                {
                    return(result);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
        }