コード例 #1
0
        /// -------------------------------------------------------------
        ///
        public override void renderContent()
        {
            int lineWidth = 30;

            List <string> forecastData = new List <string>();

            forecastData.Add("Forecast for " + periods + (isMonthBased ? " months" : " years"));
            forecastData.Add("");

            double estimatedSavings = currentBudget.currentSavings;
            double monthlyBudgetSum = currentBudget.getMonthlyBudgetItemsSum();

            List <Loan> loans = new List <Loan>();

            foreach (Loan existingLoan in currentBudget.loans)
            {
                loans.Add(existingLoan.clone());
            }

            System.DateTime now           = System.DateTime.Now;
            List <string>   goalsAchieved = new List <string>();

            for (int p = 0; p < periods * (isMonthBased ? 1 : 12); p++)
            {
                bool shouldPrint = this.isMonthBased | (p % 12 == 0);
                now = now.AddMonths(1);

                if (shouldPrint)
                {
                    forecastData.Add("");
                    string monthName = now.ToString("MMM", CultureInfo.InvariantCulture);
                    forecastData.Add((p / (isMonthBased ? 1 : 12) + 1) + ": " + monthName + ", " + now.Year);
                }

                double monthlyLeftovers = monthlyBudgetSum;
                double debtSum          = 0;

                foreach (Loan loan in loans)
                {
                    if (loan.amount != 0)
                    {
                        double interest = (-loan.amount * loan.interestPercentage / 100) / 12;
                        loan.amount += (loan.monthlyPayment - interest);

                        monthlyLeftovers -= loan.monthlyPayment;

                        if (loan.amount > 0)
                        {
                            estimatedSavings += loan.amount;
                            loan.amount       = 0;
                        }

                        debtSum += loan.amount;

                        if (shouldPrint)
                        {
                            forecastData.Add(Formatter.formatAmountLine(loan.title, loan.amount, lineWidth));
                        }
                    }
                }

                estimatedSavings  = estimatedSavings + (estimatedSavings * (currentBudget.savingsGrowthRate / 100) / 12);
                estimatedSavings += monthlyLeftovers;
                if (shouldPrint)
                {
                    forecastData.Add(Formatter.formatAmountLine("Savings", estimatedSavings, lineWidth));
                }

                if (shouldPrint)
                {
                    foreach (FinanceItem goal in currentBudget.debtGoals)
                    {
                        if (debtSum >= goal.amount && !goalsAchieved.Contains(goal.title))
                        {
                            goalsAchieved.Add(goal.title);
                            forecastData.Add('^' + Formatter.formatAmountLine(goal.title, goal.amount, lineWidth));
                        }
                    }

                    foreach (FinanceItem goal in currentBudget.savingsGoals)
                    {
                        if (estimatedSavings >= goal.amount && !goalsAchieved.Contains(goal.title))
                        {
                            goalsAchieved.Add(goal.title);
                            forecastData.Add('^' + Formatter.formatAmountLine(goal.title, goal.amount, lineWidth));
                        }
                    }
                }
            }

            Render.renderColumnContent(forecastData);
        }
コード例 #2
0
        /// -------------------------------------------------------------
        ///
        public override void renderContent()
        {
            int lineWidth = 30;

            currentBudget.sortBudgetItems();

            List <string> financeData = new List <string>();

            financeData.Add("~~~~~~  Monthly Budget  ~~~~~~");
            financeData.Add("");

            foreach (FinanceItem budgetItem in currentBudget.monthlyBudgetItems)
            {
                financeData.Add(Formatter.formatAmountLine(budgetItem.title, budgetItem.amount, lineWidth));
            }
            financeData.Add("");
            foreach (FinanceItem budgetItem in currentBudget.monthlyIntrPrinc)
            {
                financeData.Add(Formatter.formatAmountLine(budgetItem.title, budgetItem.amount, lineWidth));
            }

            financeData.Add("______________________________");
            financeData.Add("");
            financeData.Add(Formatter.formatAmountLine("Saving/Net Amount", currentBudget.getMonthlyNetSum(), lineWidth));

            financeData.Add("");
            financeData.Add("");
            financeData.Add("");
            financeData.Add("");
            financeData.Add("~~~~~~~~~~~  Debt  ~~~~~~~~~~~");
            financeData.Add("");

            foreach (Loan loan in currentBudget.loans)
            {
                financeData.Add(Formatter.formatAmountLine(loan.title + " (" + loan.shortName + ")", loan.amount, lineWidth));
                financeData.Add(Formatter.formatAmountLine(" - Monthly payment", loan.monthlyPayment, lineWidth));
                financeData.Add(Formatter.formatAmountLine(" - Interest %", loan.interestPercentage, lineWidth, 2));
                financeData.Add(Formatter.formatAmountLine(" - Annual principal", loan.calculatePrincipal(12), lineWidth));
                financeData.Add("");
            }

            financeData.Add("");
            financeData.Add("");
            financeData.Add("");
            financeData.Add("~~~~~~~~~  Savings  ~~~~~~~~~~");
            financeData.Add("");
            financeData.Add(Formatter.formatAmountLine("Current savings", currentBudget.currentSavings, lineWidth));
            financeData.Add(Formatter.formatAmountLine("Savings growth %", currentBudget.savingsGrowthRate, lineWidth, 2));
            financeData.Add(Formatter.formatAmountLine("Annual growth", currentBudget.calculateSavings(12), lineWidth));

            financeData.Add("");
            financeData.Add("");
            financeData.Add("");
            financeData.Add("~~~~~~~~~~  Goals  ~~~~~~~~~~~");
            financeData.Add("");
            if (currentBudget.savingsGoals.Count > 0)
            {
                financeData.Add("Savings Goals");
            }
            foreach (FinanceItem savingsGoal in currentBudget.savingsGoals)
            {
                financeData.Add(Formatter.formatAmountLine(" - " + savingsGoal.title, savingsGoal.amount, lineWidth));
            }
            financeData.Add("");
            if (currentBudget.debtGoals.Count > 0)
            {
                financeData.Add("Debt Goals");
            }
            foreach (FinanceItem debtGoal in currentBudget.debtGoals)
            {
                financeData.Add(Formatter.formatAmountLine(" - " + debtGoal.title, debtGoal.amount, lineWidth));
            }

            List <FinanceItem> chartItems = currentBudget.monthlyBudgetItems.ToList().Concat(currentBudget.monthlyIntrPrinc).ToList();

            chartItems.Add(new FinanceItem(
                               "Savings",
                               -currentBudget.getMonthlyNetSum()
                               ));
            PieChart simpleChart = new PieChart(10, chartItems);

            Render.renderChart(simpleChart.chart, chartItems);

            Render.renderColumnContent(financeData);
        }