示例#1
0
        public DataDefinitions()
        {
            InitializeComponent();

            Holder holder = new Holder();

            HoldersItems             = holder.HolderCollection();
            HoldersRadio.DataContext = this;

            FinancialInstitution financialinstitutions = new FinancialInstitution();

            FinancialInstitutions = financialinstitutions.GetFinancialInstitutions();
            Accounts = FinancialInstitutions.First().Accounts;
            if (!Accounts.Any(r => r.IsChecked == true))
            {
                Accounts.First().IsChecked = true;
            }
            ReportFormats = Accounts.First().ExcelImportFormats;
            if (!ReportFormats.Any(r => r.IsChecked == true))
            {
                ReportFormats.First().IsChecked = true;
            }

            comboBank.DataContext   = this;
            comboBank.SelectedIndex = 0;

            AccountRadio.DataContext = this;

            comboFormat.DataContext   = this;
            comboFormat.SelectedIndex = 0;

            comboDate.SelectedIndex      = 4;
            Holders.ItemsSource          = holder.GetHolders;
            Categories.ItemsSource       = BudgetCategory.GetCategories();
            CustomCategories.ItemsSource = BudgetCategory.GetCategories().Concat(new[] { "" });

            SetSalaryDatepicker();
            DisplayDefaultSalary();

            DataGridDefinitions.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
            UpdateDataGrid();
        }
示例#2
0
        public void GetStatementItems(bool first)
        {
            //filling textblocks
            MonthlyStatement statement = new MonthlyStatement();

            Dispatcher.Invoke(() =>
            {
                statement.statement_date = (DateTime)date_month.SelectedDate;
                statement.holder         = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First();

                Dictionary <string, double> category_amounts = statement.GetAggregateCategoryAmount();

                ///grid assets
                NetWorthGrid.Children.Clear();
                List <AccountType> acctypes = new List <AccountType>();
                FinancialInstitution financialinstitutions = new FinancialInstitution();
                int row = 1;
                foreach (FinancialInstitution fi in financialinstitutions.GetFinancialInstitutions().Where(e => e.Accounts.Any(a => a.AccountType != AccountType.CreditCard)))
                {
                    if (first)
                    {
                        NetWorthGrid.RowDefinitions.Add(new RowDefinition());
                    }
                    TextBlock txt_fi = Helpers.GridHelper.CreateTextInGrid(fi.InstitutionName, row, 0, false, HorizontalAlignment.Left, false, true, true);
                    NetWorthGrid.Children.Add(txt_fi);

                    foreach (Account acc in fi.Accounts)
                    {
                        if (acc.AccountType != AccountType.CreditCard)
                        {
                            if (!acctypes.Contains(acc.AccountType))
                            {
                                if (first)
                                {
                                    NetWorthGrid.ColumnDefinitions.Add(new ColumnDefinition());
                                }
                                TextBlock txt_acc = Helpers.GridHelper.CreateTextInGrid(acc.AccountTypeDescription, 0, acctypes.Count + 1, false, HorizontalAlignment.Center, true, false, true);
                                NetWorthGrid.Children.Add(txt_acc);
                                acctypes.Add(acc.AccountType);
                            }
                            double balance     = statement.GetBalance(acc.AccountType, fi.ShortName);
                            TextBlock txt_data = Helpers.GridHelper.CreateTextInGrid(string.Format("{0:C2}", balance), row, acctypes.IndexOf(acc.AccountType) + 1, false, HorizontalAlignment.Right, false, false, true);
                            NetWorthGrid.Children.Add(txt_data);
                        }
                    }
                    row++;
                }
                if (first)
                {
                    NetWorthGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }
                TextBlock txt_total_bank = Helpers.GridHelper.CreateTextInGrid("Total", 0, acctypes.Count + 1, false, HorizontalAlignment.Center, true, false, true);
                NetWorthGrid.Children.Add(txt_total_bank);
                for (int r = 1; r < row; r++)
                {
                    double amount = 0;
                    for (int c = 1; c <= acctypes.Count; c++)
                    {
                        TextBlock selected_txt = NetWorthGrid.Children.Cast <TextBlock>().Where(e => Grid.GetColumn(e) == c && Grid.GetRow(e) == r).FirstOrDefault();
                        if (selected_txt != null)
                        {
                            amount += Convert.ToDouble(selected_txt.Text.Replace("$", "").Replace(",", ""));
                        }
                    }
                    txt_total_bank = Helpers.GridHelper.CreateTextInGrid(string.Format("{0:C2}", amount), r, acctypes.Count + 1, false, HorizontalAlignment.Right, true, false, true);
                    NetWorthGrid.Children.Add(txt_total_bank);
                }

                if (first)
                {
                    NetWorthGrid.RowDefinitions.Add(new RowDefinition());
                }
                TextBlock txt_total_accounttype = Helpers.GridHelper.CreateTextInGrid("Total", row, 0, false, HorizontalAlignment.Left, true, false, true);
                NetWorthGrid.Children.Add(txt_total_accounttype);
                for (int c = 1; c <= acctypes.Count + 1; c++)
                {
                    double amount = 0;
                    for (int r = 1; r < row; r++)
                    {
                        TextBlock selected_txt = NetWorthGrid.Children.Cast <TextBlock>().Where(e => Grid.GetColumn(e) == c && Grid.GetRow(e) == r).FirstOrDefault();
                        if (selected_txt != null)
                        {
                            amount += Convert.ToDouble(selected_txt.Text.Replace("$", "").Replace(",", ""));
                        }
                    }
                    txt_total_accounttype = Helpers.GridHelper.CreateTextInGrid(string.Format("{0:C2}", amount), row, c, false, HorizontalAlignment.Right, true, false, true);
                    NetWorthGrid.Children.Add(txt_total_accounttype);
                }

                ///grid statement
                amt_gross_salary.Text = string.Format("{0:C2}", category_amounts["Gross Salary"]);
                //amt_ret_contribution.Text = string.Format("{0:C2}", -1 * category_amounts["Retirement Contribution"]);
                amt_netpay.Text            = string.Format("{0:C2}", category_amounts["Payroll"]);
                amt_other_withholding.Text = (-1 * (double.Parse(amt_gross_salary.Text, NumberStyles.Currency)
                                                    - double.Parse(amt_netpay.Text, NumberStyles.Currency)
                                                    + double.Parse(amt_ret_contribution.Text, NumberStyles.Currency))).ToString("C2");

                //amt_ret_income.Text = string.Format("{0:C2}", category_amounts["Retirement Income"]);
                amt_other_income.Text = string.Format("{0:C2}", category_amounts["Other Income"]);
                amt_total_income.Text = (double.Parse(amt_netpay.Text, NumberStyles.Currency)
                                         + double.Parse(amt_ret_income.Text, NumberStyles.Currency)
                                         + double.Parse(amt_other_income.Text, NumberStyles.Currency)).ToString("C2");

                amt_rent.Text           = string.Format("{0:C2}", category_amounts["Rent"]);
                amt_utilities.Text      = string.Format("{0:C2}", category_amounts["Utilities"]);
                amt_commute.Text        = string.Format("{0:C2}", category_amounts["Commute"]);
                amt_groceries.Text      = string.Format("{0:C2}", category_amounts["Groceries"]);
                amt_restaurants.Text    = string.Format("{0:C2}", category_amounts["Restaurants"]);
                amt_cash.Text           = string.Format("{0:C2}", category_amounts["Cash"]);
                amt_living_expense.Text = (double.Parse(amt_rent.Text, NumberStyles.Currency)
                                           + double.Parse(amt_utilities.Text, NumberStyles.Currency)
                                           + double.Parse(amt_commute.Text, NumberStyles.Currency)
                                           + double.Parse(amt_groceries.Text, NumberStyles.Currency)
                                           + double.Parse(amt_restaurants.Text, NumberStyles.Currency)
                                           + double.Parse(amt_cash.Text, NumberStyles.Currency)).ToString("C2");

                amt_shopping.Text      = string.Format("{0:C2}", category_amounts["Shopping"]);
                amt_entertainment.Text = string.Format("{0:C2}", category_amounts["Entertainment"]);
                amt_travel.Text        = string.Format("{0:C2}", category_amounts["Travel"]);
                amt_medical.Text       = string.Format("{0:C2}", category_amounts["Medical"]);
                amt_other_expense.Text = (double.Parse(amt_shopping.Text, NumberStyles.Currency)
                                          + double.Parse(amt_entertainment.Text, NumberStyles.Currency)
                                          + double.Parse(amt_travel.Text, NumberStyles.Currency)
                                          + double.Parse(amt_medical.Text, NumberStyles.Currency)).ToString("C2");

                amt_total_expense.Text = (double.Parse(amt_living_expense.Text, NumberStyles.Currency) + double.Parse(amt_other_expense.Text, NumberStyles.Currency)).ToString("C2");

                amt_savings_before_misc.Text = (double.Parse(amt_total_income.Text, NumberStyles.Currency) + double.Parse(amt_total_expense.Text, NumberStyles.Currency)).ToString("C2");

                amt_misc.Text             = string.Format("{0:C2}", category_amounts["Miscellaneous"]);
                amt_investment_gains.Text = string.Format("{0:C2}", category_amounts["Investment Gains"]);

                amt_net_savings.Text = (double.Parse(amt_total_income.Text, NumberStyles.Currency)
                                        + double.Parse(amt_total_expense.Text, NumberStyles.Currency)
                                        + double.Parse(amt_misc.Text, NumberStyles.Currency)
                                        + double.Parse(amt_investment_gains.Text, NumberStyles.Currency)
                                        ).ToString("C2");
            });
        }