public override MonthlyStatement GenerateStatement(MonthlyUsage monthlyUsage) { var statement = new MonthlyStatement(); statement.TotalCost = 54.90f; return(statement); }
public override MonthlyStatement GenerateStatement(MonthlyUsage monthlyUsage) { var statement = new MonthlyStatement(); statement.CallCost = 0.12f * monthlyUsage.CallMinutes; statement.SmsCost = 0.12f * monthlyUsage.SmsCount; statement.TotalCost = statement.CallCost + statement.SmsCost; return(statement); }
public override MonthlyStatement GenerateStatement(MonthlyUsage monthlyUsage) { var monthlyStatement = new MonthlyStatement { TotalCost = 54.90f }; return(monthlyStatement); }
public override MonthlyStatement GenerateStatement(MonthlyUsage monthlyUsage) { var monthlyStatement = new MonthlyStatement { CallCost = 0.12f * monthlyUsage.CallMinutes, SmsCost = 0.12f * monthlyUsage.SmsCount }; monthlyStatement.TotalCost = monthlyStatement.CallCost + monthlyStatement.SmsCost; return(monthlyStatement); }
public void Stacked_Chart(bool change) { DataTable dt = new DataTable(); DateTime from_month = new DateTime(); DateTime to_month = new DateTime(); Dispatcher.Invoke(() => { from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); to_month = Convert.ToDateTime(date_month_to.SelectedDate); StackedSeriesCollection.Clear(); }); string freq = "Monthly"; if ((to_month - from_month).TotalDays < 93) { freq = "Weekly"; } dt = MonthlyStatement.GetHistoricalTransactionsByCategory("", freq, from_month, to_month); string[] selectcategories = categories.Skip(3).ToArray(); Dispatcher.Invoke(() => { foreach (string category in selectcategories) { ChartValues <DateModel> chartvalues = new ChartValues <DateModel>(dt.AsEnumerable().Where(r => r["category"].ToString() == category) .Select(r => new DateModel { DateTime = Convert.ToDateTime(r["period"]), Value = r.Field <double?>("amount") ?? 0 })); if (chartvalues.Count != 0) { StackedSeriesCollection.Add(new StackedColumnSeries { Values = chartvalues, StackMode = StackMode.Values, Title = category }); } } }); if (!change) { Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, (Action)(() => { DataContext = this; })); } }
public void PayAsYouGoCustomer_IsChargedBasedOnTheSumOfCostOfCallAndSms() { var customer = new PayAsYouGoCustomer(); var usage = new MonthlyUsage { CallMinutes = 100, SmsCount = 100, Customer = customer }; var statement = new MonthlyStatement(); customer.GenerateStatment(usage); Assert.AreEqual(12.0f, statement.CallCost); Assert.AreEqual(12.0f, statement.SmsCost); Assert.AreEqual(24.0f, statement.TotalCost); }
public void UnlimitedCustomer_IsChargedAFlatRatePerMonth() { var customer = new UnlimitedCustomer(); var usage = new MonthlyUsage { CallMinutes = 100, SmsCount = 100, Customer = customer }; var statement = new MonthlyStatement(); customer.GenerateStatment(usage); Assert.AreEqual(0, statement.CallCost); Assert.AreEqual(0, statement.SmsCost); Assert.AreEqual(54.90f, statement.TotalCost); }
public void MakeExpenseChart(bool change) { //bar chart MonthlyStatement statement = new MonthlyStatement(); Dispatcher.Invoke(() => { statement.holder = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First(); statement.statement_date = Convert.ToDateTime(date_month.SelectedDate); }); if (!change) { SeriesCollection_budget = new SeriesCollection(); } Tuple <List <double>, List <double>, List <string> > result = statement.CompareMonths(statement.statement_date.AddMonths(-1)); ChartValues <double> ChartValues_thismonth = new ChartValues <double>(result.Item1); ChartValues <double> ChartValues_lastmonth = new ChartValues <double>(result.Item2); List <string> labels = result.Item3; Dispatcher.Invoke(() => { ColumnSeries colseries_thismonth = new ColumnSeries(); colseries_thismonth.Title = string.Format("{0:MMM yyyy}", statement.statement_date); colseries_thismonth.Values = ChartValues_thismonth; colseries_thismonth.DataLabels = true; colseries_thismonth.ColumnPadding = 0; colseries_thismonth.MaxColumnWidth = 15; ColumnSeries colseries_lastmonth = new ColumnSeries(); colseries_lastmonth.Title = string.Format("{0:MMM yyyy}", statement.statement_date.AddMonths(-1)); colseries_lastmonth.Values = ChartValues_lastmonth; colseries_lastmonth.ColumnPadding = 0; colseries_lastmonth.MaxColumnWidth = 15; SeriesCollection_budget.Clear(); SeriesCollection_budget.Add(colseries_thismonth); SeriesCollection_budget.Add(colseries_lastmonth); if (!change) { Labels = labels.ToArray(); Formatter = value => value.ToString("C0"); DataContext = this; } }); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var monthlyUsage = new MonthlyUsage(); monthlyUsage.Customer = new Customer(); monthlyUsage.CallMinutes = 100; monthlyUsage.SmsCount = 500; monthlyUsage.Customer.Type = CustomerType.Unlimited; var monthlyStatement = new MonthlyStatement(); monthlyStatement.CallCost = 1; monthlyStatement.Generate(monthlyUsage); Console.WriteLine(monthlyStatement.TotalCost); }
public void Category_Chart(bool change) { DataTable dt = new DataTable(); DateTime from_month = new DateTime(); DateTime to_month = new DateTime(); string selected_category = ""; Dispatcher.Invoke(() => { from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); to_month = Convert.ToDateTime(date_month_to.SelectedDate); selected_category = comboCategory.SelectedItem.ToString(); }); string freq = "Monthly"; if ((to_month - from_month).TotalDays < 93) { freq = "Weekly"; } dt = MonthlyStatement.GetHistoricalTransactionsByCategory(selected_category, freq, from_month, to_month); Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action)(() => { Series_Category.Clear(); foreach (Holder holder in HoldersItems) { if (dt.AsEnumerable().Any(r => r["holder"].ToString() == holder.HolderName)) { Series_Category.Add(new LineSeries { Values = new ChartValues <DateModel>(dt.AsEnumerable().Where(r => r["holder"].ToString() == holder.HolderName) .Select(r => new DateModel { DateTime = Convert.ToDateTime(r["period"]), Value = r.Field <double?>("amount") ?? 0 })), Title = holder.HolderName, Fill = Brushes.Transparent }); } } if (!change) { CategoryChart.DataContext = this; } })); }
public void FillDataGrid(string category) { //filling datagrid string selected_person = ""; DateTime statement_month = new DateTime(); Dispatcher.Invoke(() => { selected_person = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First(); statement_month = (DateTime)date_month.SelectedDate; }); DataTable dt = MonthlyStatement.GetTransactionsByCategory(category, statement_month, selected_person); Dispatcher.Invoke(() => { DataGridLineItems.DataContext = dt; }); }
public void NetWorth_Chart(bool change = false) { DataTable dt = new DataTable(); DateTime from_month = new DateTime(); DateTime to_month = new DateTime(); string datatable = "MonthlyBalance"; Dispatcher.Invoke(() => { from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); to_month = Convert.ToDateTime(date_month_to.SelectedDate); }); if ((to_month - from_month).TotalDays < 93) { datatable = "DailyBalance"; } dt = MonthlyStatement.GetHistoricalNetWorth(datatable, from_month, to_month); Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action)(() => { Series_NetWorth.Clear(); foreach (Holder holder in HoldersItems) { if (dt.AsEnumerable().Any(r => r["holder"].ToString() == holder.HolderName)) { Series_NetWorth.Add(new LineSeries { Values = new ChartValues <DateModel>(dt.AsEnumerable().Where(r => r["holder"].ToString() == holder.HolderName) .Select(r => new DateModel { DateTime = Convert.ToDateTime(r["period"]), Value = r.Field <double?>("NetWorth") ?? 0 })), Title = holder.HolderName }); } } if (!change) { NetWorthChart.DataContext = this; } })); }
public void Savings_Chart(bool change = false) { DataTable dt = new DataTable(); DateTime from_month = new DateTime(); DateTime to_month = new DateTime(); Dispatcher.Invoke(() => { from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); to_month = Convert.ToDateTime(date_month_to.SelectedDate); }); dt = MonthlyStatement.GetHistoricalSavings(from_month, to_month); Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action)(() => { Series_Savings.Clear(); foreach (Holder holder in HoldersItems) { if (dt.AsEnumerable().Any(r => r["holder"].ToString() == holder.HolderName)) { Series_Savings.Add(new LineSeries() { Values = new ChartValues <DateModel>(dt.AsEnumerable().Where(r => r["holder"].ToString() == holder.HolderName) .Select(r => new DateModel { DateTime = Convert.ToDateTime(r["period"]), Value = r.Field <double?>("amount") ?? 0 })), Title = holder.HolderName }); } } if (!change) { SavingsChart.DataContext = this; } })); }
public void GetAlert() { int n_undefined = 0; int n_duplicates = 0; DateTime this_month = new DateTime(); DateTime statement_month = new DateTime(); Dispatcher.Invoke(() => { this_month = new DateTime(Convert.ToDateTime(date_month.SelectedDate).Year, Convert.ToDateTime(date_month.SelectedDate).Month, 1); statement_month = (DateTime)date_month.SelectedDate; }); Tuple <int, int> untreated_data = MonthlyStatement.CheckUndefinedOrDuplicates(this_month, statement_month); n_undefined = untreated_data.Item1; n_duplicates = untreated_data.Item2; Dispatcher.Invoke(() => { if (n_undefined > 0 || n_duplicates > 0) { alert_undefined.Foreground = Brushes.Red; alert_undefined.FontWeight = FontWeights.Bold; alert_undefined.Text = "Found " + (n_undefined > 0 ? n_undefined.ToString() + " undefined items" : "") + (n_undefined > 0 && n_duplicates > 0 ? " and " : "") + (n_duplicates > 0 ? n_duplicates.ToString() + " duplicate items" : ""); } else { alert_undefined.Foreground = Brushes.Black; alert_undefined.FontWeight = FontWeights.Normal; alert_undefined.Text = "Data looks good"; } }); }
public void Make_Grid(bool change) { DataTable dt = new DataTable(); string selected_person = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First(); dt.Columns.Add("RowHeader"); foreach (string rowheader in new [] { "Mean", "Median", "Standard Deviation" }) { DataRow row = dt.NewRow(); row["RowHeader"] = rowheader; dt.Rows.Add(row); } Dispatcher.Invoke(() => { DataGridAverage.DataContext = dt; }); DateTime from_month = from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); DateTime to_month = Convert.ToDateTime(date_month_to.SelectedDate); //savings Task saving_task = Task.Run(() => { Tuple <string, string, string> mean_median_std = MonthlyStatement.GetHistoricalAggregateCategoryAmount("savings", selected_person, from_month, to_month); Dispatcher.Invoke(() => { dt.Columns.Add("savings"); dt.Rows[0]["savings"] = mean_median_std.Item1; dt.Rows[1]["savings"] = mean_median_std.Item2; dt.Rows[2]["savings"] = mean_median_std.Item3; DataGridAverage.DataContext = dt; }); }); //expenses Task expense_task = Task.Run(() => { Tuple <string, string, string> mean_median_std = MonthlyStatement.GetHistoricalAggregateCategoryAmount("expenses", selected_person, from_month, to_month); Dispatcher.Invoke(() => { dt.Columns.Add("expenses"); dt.Rows[0]["expenses"] = mean_median_std.Item1; dt.Rows[1]["expenses"] = mean_median_std.Item2; dt.Rows[2]["expenses"] = mean_median_std.Item3; DataGridAverage.DataContext = dt; }); }); //categories Task categories_task = Task.Run(() => { foreach (string category in BudgetCategory.GetCategories()) { if (category != "Miscellaneous" && !category.Contains("Investment")) { Tuple <string, string, string> mean_median_std = MonthlyStatement.GetHistoricalAggregateCategoryAmount(category, selected_person, from_month, to_month); Dispatcher.Invoke(() => { if (!change) { DataGridTextColumn c = new DataGridTextColumn(); c.Header = category; c.IsReadOnly = true; c.CellStyle = (System.Windows.Style)FindResource("RightAlignment"); c.Binding = new System.Windows.Data.Binding(category); DataGridAverage.Columns.Add(c); } dt.Columns.Add(category); dt.Rows[0][category] = mean_median_std.Item1; dt.Rows[1][category] = mean_median_std.Item2; dt.Rows[2][category] = mean_median_std.Item3; }); } } Dispatcher.Invoke(() => { DataGridAverage.DataContext = dt; }); }); tasks.Add(categories_task); tasks.Add(saving_task); tasks.Add(expense_task); }
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"); }); }