public static Form AmountByTransactionTypesReport(Control parameters) { try { DateTypesTagsControl pars = parameters as DateTypesTagsControl; DateTime StartDate = DateTime.Now; DateTime EndDate = DateTime.Now; IEnumerable<MoneyDataSet.AccountTypesRow> AccountTypes = null; IEnumerable<MoneyDataSet.TransactionTypesRow> TransactionTypes = null; IEnumerable<String> Tags = null; int AccountTypeCount = 0; int TransactionTypeCount = 0; int TagCount = 0; if (pars != null) { MethodInvoker inv = delegate() { StartDate = pars.dtpStartDate.Value; EndDate = pars.dtpEndDate.Value; AccountTypes = pars.lbAccountTypes.SelectedItems.Cast<MoneyDataSet.AccountTypesRow>().ToArray(); AccountTypeCount = pars.lbAccountTypes.Items.Count; TransactionTypes = pars.lbTransactionTypes.SelectedItems.Cast<MoneyDataSet.TransactionTypesRow>().ToArray(); TransactionTypeCount = pars.lbTransactionTypes.Items.Count; Tags = pars.lbTags.SelectedItems.Cast<String>().ToArray(); TagCount = pars.lbTags.Items.Count; }; pars.Invoke(inv); ReportChartForm form = new ReportChartForm(); form.Text = String.Format(Resources.Labels.AmountsByTransactionTypesFormTitleFormat, StartDate.ToShortDateString(), EndDate.ToShortDateString()); List<AmountByTransactionTypeEntry> entries = new List<AmountByTransactionTypeEntry>(); foreach (MoneyDataSet.TransactionTypesRow tt in TransactionTypes) { double amount = 0; foreach (MoneyDataSet.TransactionsRow t in MoneyDataKeeper.Instance.Transactions.Where(tr => ((tr.IsActive) && (tr.TypeID == tt.ID) && (AccountTypes.Contains(tr.AccountRow.AccountTypesRow)) && (tr.TransactionTime >= StartDate.Date) && ((!tr.GetTransactionTagsRows().Any()) || (tr.GetTransactionTagsRows().Select(tags => (tags.TagRow.Title)).Intersect(Tags).Any())) && (tr.TransactionTime < EndDate.Date.AddDays(1))))) { amount += Math.Abs(t.Amount * t.AccountRow.CurrenciesRow.ExchangeRate); } if (amount > 0) { entries.Add(new AmountByTransactionTypeEntry(tt.Title, amount)); } } StringBuilder title = new StringBuilder(); if (AccountTypes.Count() != AccountTypeCount) { title.AppendLine(String.Format(Resources.Labels.OnlyAccountTypes, String.Join(Consts.UI.EnumerableSeparator, AccountTypes.Select(a => (a.Title))))); } if (TransactionTypes.Count() != TransactionTypeCount) { title.AppendLine(String.Format(Resources.Labels.OnlyTransactionTypesTypes, String.Join(Consts.UI.EnumerableSeparator, TransactionTypes.Select(a => (a.Title))))); } if (Tags.Count() != TagCount) { title.AppendLine(String.Format(Resources.Labels.OnlyTags, String.Join(Consts.UI.EnumerableSeparator, Tags))); } if (!String.IsNullOrWhiteSpace(title.ToString())) { form.Chart.Titles.Add(title.ToString()); } // form.Chart.Series[0].ChartType = SeriesChartType.Pie; form.Chart.DataSource = entries; form.Chart.ChartAreas[0].AxisY.LabelStyle.Format = Consts.UI.NumericFormat; form.Chart.Series[0].XValueType = ChartValueType.String; form.Chart.Series[0].YValueType = ChartValueType.Double; form.Chart.Series[0].YValuesPerPoint = 1; form.Chart.Series[0].ShadowOffset = 1; form.Chart.Series[0].ToolTip = Consts.UI.SmallChartToolTip; form.Chart.Series[0].Palette = ChartColorPalette.Pastel; form.Chart.Series[0].XValueMember = AmountByTransactionTypeEntry.TransactionTypeTitle; form.Chart.Series[0].YValueMembers = AmountByTransactionTypeEntry.AmountTitle; form.Chart.DataBind(); return form; } } catch (Exception e) { Log.Write(e); } return null; }
public static Form AmountByTagsChartReport(Control parameters) { try { MoneyDataKeeper keeper = MoneyDataKeeper.Instance; DateTypesTagsControl pars = parameters as DateTypesTagsControl; DateTime StartDate = DateTime.Now; DateTime EndDate = DateTime.Now; IEnumerable<MoneyDataSet.AccountTypesRow> AccountTypes = null; IEnumerable<MoneyDataSet.TransactionTypesRow> TransactionTypes = null; IEnumerable<String> Tags = null; int AccountTypeCount = 0; int TransactionTypeCount = 0; int TagCount = 0; if (pars != null) { MethodInvoker inv = delegate() { StartDate = pars.dtpStartDate.Value; EndDate = pars.dtpEndDate.Value; AccountTypes = pars.lbAccountTypes.SelectedItems.Cast<MoneyDataSet.AccountTypesRow>().ToArray(); AccountTypeCount = pars.lbAccountTypes.Items.Count; TransactionTypes = pars.lbTransactionTypes.SelectedItems.Cast<MoneyDataSet.TransactionTypesRow>().ToArray(); TransactionTypeCount = pars.lbTransactionTypes.Items.Count; Tags = pars.lbTags.SelectedItems.Cast<String>().ToArray(); TagCount = pars.lbTags.Items.Count; }; pars.Invoke(inv); ReportChartForm form = new ReportChartForm(); form.Text = String.Format(Resources.Labels.AmountByTagsFormTitleFormat, StartDate.ToShortDateString(), EndDate.ToShortDateString()); List<AmountByTagEntry> entries = new List<AmountByTagEntry>(); foreach (MoneyDataSet.TagsRow tag in keeper.DataSet.Tags.Where(t => (Tags.Contains(t.Title)))) { double spent = 0; double earned = 0; IEnumerable<MoneyDataSet.TransactionsRow> transactionList = keeper.Transactions.Where(t => ((t.IsActive) && (!t.TypeID.Equals(MoneyDataSet.IDs.TransactionTypes.Correction)) && (TransactionTypes.Contains(t.TransactionTypesRow)) && (AccountTypes.Contains(t.AccountRow.AccountTypesRow)) && (t.EntryTime >= StartDate.Date) && (t.EntryTime < EndDate.Date.AddDays(1)) && (t.GetTransactionTagsRows().Where(tt => (tt.TagID == tag.ID)).Any()))); foreach (MoneyDataSet.TransactionsRow transaction in transactionList) { if (transaction.TransactionTypesRow.IsIncome) { earned += transaction.Amount * transaction.AccountRow.CurrenciesRow.ExchangeRate; } else { spent += transaction.Amount * transaction.AccountRow.CurrenciesRow.ExchangeRate; } } if ((spent != 0) || (earned != 0)) { entries.Add(new AmountByTagEntry(tag.Title, spent, earned)); } } StringBuilder title = new StringBuilder(); if (AccountTypes.Count() != AccountTypeCount) { title.AppendLine(String.Format(Resources.Labels.OnlyAccountTypes, String.Join(Consts.UI.EnumerableSeparator, AccountTypes.Select(a => (a.Title))))); } if (TransactionTypes.Count() != TransactionTypeCount) { title.AppendLine(String.Format(Resources.Labels.OnlyTransactionTypesTypes, String.Join(Consts.UI.EnumerableSeparator,TransactionTypes.Select(a => (a.Title))))); } if (Tags.Count() != TagCount) { title.AppendLine(String.Format(Resources.Labels.OnlyTags, String.Join(Consts.UI.EnumerableSeparator, Tags))); } if (!String.IsNullOrWhiteSpace(title.ToString())) { form.Chart.Titles.Add(title.ToString()); } form.Chart.DataSource = entries; Legend legend = new Legend(); form.Chart.Legends.Add(legend); form.Chart.ChartAreas[0].AxisY.LabelStyle.Format = Consts.UI.NumericFormat; form.Chart.Series[0].XValueType = ChartValueType.String; form.Chart.Series[0].YValueType = ChartValueType.Double; form.Chart.Series[0].YValuesPerPoint = 1; form.Chart.Series[0].ShadowOffset = 1; form.Chart.Series[0].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.SpentTitle); form.Chart.Series[0].Color = Color.DarkSalmon; form.Chart.Series[0].XValueMember = AmountByTagEntry.TagTitle; form.Chart.Series[0].YValueMembers = AmountByTagEntry.SpentTitle; form.Chart.Series[0].Legend = legend.Name; form.Chart.Series[0].LegendText = Resources.Labels.SpentTitle; form.Chart.Series.Add(new Series()); form.Chart.Series[1].XValueType = ChartValueType.String; form.Chart.Series[1].YValueType = ChartValueType.Double; form.Chart.Series[1].YValuesPerPoint = 1; form.Chart.Series[1].ShadowOffset = 1; form.Chart.Series[1].XValueMember = AmountByTagEntry.TagTitle; form.Chart.Series[1].YValueMembers = AmountByTagEntry.EarnedTitle; form.Chart.Series[1].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.EarnedTitle); form.Chart.Series[1].Color = Color.SteelBlue; form.Chart.Series[1].Legend = legend.Name; form.Chart.Series[1].LegendText = Resources.Labels.EarnedTitle; form.Chart.DataBind(); return form; } } catch (Exception e) { Log.Write(e); } return null; }
public static Form ActualBalanceChangesReport(Control parameters) { try { MoneyDataKeeper keeper = MoneyDataKeeper.Instance; DateOnlyControl pars = parameters as DateOnlyControl; DateTime StartDate = DateTime.Now; DateTime EndDate = DateTime.Now; if (pars != null) { MethodInvoker inv = delegate() { StartDate = pars.dtpStartDate.Value; EndDate = pars.dtpEndDate.Value; }; pars.Invoke(inv); ReportChartForm form = new ReportChartForm(); form.Text = String.Format(Resources.Labels.ActualBalanceChangesFormTitleFormat, StartDate.ToShortDateString(), EndDate.ToShortDateString()); List<BalanceByDateEntry> entries = new List<BalanceByDateEntry>(); DateTime current = StartDate.Date; while (current < EndDate) { double assets = 0; double debts = 0; foreach (MoneyDataSet.AccountsRow account in keeper.Accounts) { if (account.AccountTypesRow.IsDebit) { assets += keeper.GetAccountBalace(account, current) * account.CurrenciesRow.ExchangeRate; } else { debts += Math.Abs(keeper.GetAccountBalace(account, current) * account.CurrenciesRow.ExchangeRate); } } entries.Add(new BalanceByDateEntry(current, assets, debts)); current = current.AddDays(1); } List<BalanceByDateEntry> entriesForecast = new List<BalanceByDateEntry>(); double assetsForecast = 0; double debtsForecast = 0; foreach (MoneyDataSet.AccountsRow account in keeper.Accounts) { if (account.AccountTypesRow.IsDebit) { assetsForecast += keeper.GetAccountBalace(account, StartDate) * account.CurrenciesRow.ExchangeRate; } else { debtsForecast += Math.Abs(keeper.GetAccountBalace(account, StartDate) * account.CurrenciesRow.ExchangeRate); } } entriesForecast.Add(new BalanceByDateEntry(StartDate.Date, assetsForecast, debtsForecast)); foreach (MoneyDataKeeper.ActivePlannedTransactionEntry plan in keeper.GetActivePlannedTransactions(StartDate, EndDate).OrderBy(o => (o.Date))) { // skipping plans without date if (plan.Date.Equals(DateTime.MaxValue)) continue; if (plan.PlannedTransaction.AccountTypeRow.IsDebit) { if (plan.PlannedTransaction.TransactionTypeRow.IsIncome) { assetsForecast += plan.PlannedTransaction.Amount * plan.PlannedTransaction.CurrenciesRow.ExchangeRate; } else { assetsForecast -= plan.PlannedTransaction.Amount * plan.PlannedTransaction.CurrenciesRow.ExchangeRate; } } else { if (plan.PlannedTransaction.TransactionTypeRow.IsIncome) { debtsForecast -= plan.PlannedTransaction.Amount * plan.PlannedTransaction.CurrenciesRow.ExchangeRate; } else { debtsForecast += plan.PlannedTransaction.Amount * plan.PlannedTransaction.CurrenciesRow.ExchangeRate; } } entriesForecast.Add(new BalanceByDateEntry(plan.Date, assetsForecast, debtsForecast)); } entriesForecast.Add(new BalanceByDateEntry(EndDate.Date.AddDays(1), assetsForecast, debtsForecast)); Legend legend = new Legend(); form.Chart.ChartAreas[0].AxisY.ScaleBreakStyle.Enabled = true; form.Chart.ChartAreas[0].AxisY.ScaleBreakStyle.MaxNumberOfBreaks = 1; form.Chart.ChartAreas[0].AxisY.LabelStyle.Format = Consts.UI.NumericFormat; form.Chart.Legends.Add(legend); form.Chart.Series[0].ChartType = SeriesChartType.Line; form.Chart.Series[0].BorderWidth = 3; form.Chart.Series[0].XValueType = ChartValueType.Date; form.Chart.Series[0].YValueType = ChartValueType.Double; form.Chart.Series[0].YValuesPerPoint = 1; form.Chart.Series[0].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.AssetsPlannedTitle); form.Chart.Series[0].Color = Color.Blue; form.Chart.Series[0].Points.DataBind(entriesForecast, BalanceByDateEntry.DateTitle, BalanceByDateEntry.AssetsTitle, String.Empty); form.Chart.Series[0].Legend = legend.Name; form.Chart.Series[0].LegendText = Resources.Labels.AssetsPlannedTitle; form.Chart.Series.Add(new Series()); form.Chart.Series[1].ChartType = SeriesChartType.Line; form.Chart.Series[1].BorderWidth = 3; form.Chart.Series[1].XValueType = ChartValueType.DateTime; form.Chart.Series[1].YValueType = ChartValueType.Double; form.Chart.Series[1].YValuesPerPoint = 1; form.Chart.Series[1].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.AssetsTitle); form.Chart.Series[1].Color = Color.Green; form.Chart.Series[1].Points.DataBind(entries, BalanceByDateEntry.DateTitle, BalanceByDateEntry.AssetsTitle, String.Empty); form.Chart.Series[1].Legend = legend.Name; form.Chart.Series[1].LegendText = Resources.Labels.AssetsTitle; form.Chart.Series.Add(new Series()); form.Chart.Series[2].ChartType = SeriesChartType.Line; form.Chart.Series[2].BorderWidth = 3; form.Chart.Series[2].XValueType = ChartValueType.Date; form.Chart.Series[2].YValueType = ChartValueType.Double; form.Chart.Series[2].YValuesPerPoint = 1; form.Chart.Series[2].Points.DataBind(entriesForecast, BalanceByDateEntry.DateTitle, BalanceByDateEntry.DebtsTitle, String.Empty); form.Chart.Series[2].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.DebtsPlannedTitle); form.Chart.Series[2].Color = Color.Orange; form.Chart.Series[2].Legend = legend.Name; form.Chart.Series[2].LegendText = Resources.Labels.DebtsPlannedTitle; form.Chart.Series.Add(new Series()); form.Chart.Series[3].ChartType = SeriesChartType.Line; form.Chart.Series[3].BorderWidth = 3; form.Chart.Series[3].XValueType = ChartValueType.DateTime; form.Chart.Series[3].YValueType = ChartValueType.Double; form.Chart.Series[3].YValuesPerPoint = 1; form.Chart.Series[3].Points.DataBind(entries, BalanceByDateEntry.DateTitle, BalanceByDateEntry.DebtsTitle, String.Empty); form.Chart.Series[3].ToolTip = String.Format(Consts.UI.DefaultChartToolTipFormat, Resources.Labels.DebtsTitle); form.Chart.Series[3].Color = Color.Red; form.Chart.Series[3].Legend = legend.Name; form.Chart.Series[3].LegendText = Resources.Labels.DebtsTitle; form.Chart.DataBind(); return form; } } catch (Exception e) { Log.Write(e); } return null; }
public static Form SpendingStructureReport(Control parameters) { const String PieLabelStyle = "PieLabelStyle"; const String PieLabelStyleValue = "Outside"; try { DateOnlyControl pars = parameters as DateOnlyControl; DateTime StartDate = DateTime.Now; DateTime EndDate = DateTime.Now; if (pars != null) { MethodInvoker inv = delegate() { StartDate = pars.dtpStartDate.Value; EndDate = pars.dtpEndDate.Value; }; pars.Invoke(inv); ReportChartForm form = new ReportChartForm(); form.Text = String.Format(Resources.Labels.SpendingStructureFormTitleFormat, StartDate.ToShortDateString(), EndDate.ToShortDateString()); List<AmountByTransactionTypeEntry> entries = new List<AmountByTransactionTypeEntry>(); foreach (MoneyDataSet.TransactionTypesRow tt in MoneyDataKeeper.Instance.GetTransactionTypes(false)) { // excluding irrelevant transaction types if ((tt.ID.Equals(MoneyDataSet.IDs.TransactionTypes.Correction)) || (tt.ID.Equals(MoneyDataSet.IDs.TransactionTypes.TransferOut))) continue; double amount = 0; foreach (MoneyDataSet.TransactionsRow t in MoneyDataKeeper.Instance.Transactions.Where(tr => ((tr.IsActive) && (tr.TypeID == tt.ID) && (tr.TransactionTime >= StartDate.Date) && (tr.TransactionTime < EndDate.Date.AddDays(1))))) { amount += Math.Abs(t.Amount * t.AccountRow.CurrenciesRow.ExchangeRate); } if (amount > 0) { entries.Add(new AmountByTransactionTypeEntry(tt.Title, amount)); } } form.Chart.Series[0].ChartType = SeriesChartType.Doughnut; form.Chart.DataSource = entries; form.Chart.Series[0].XValueType = ChartValueType.String; form.Chart.Series[0].YValueType = ChartValueType.Double; form.Chart.Series[0].YValuesPerPoint = 1; form.Chart.Series[0].ShadowOffset = 1; form.Chart.Series[0].ToolTip = Consts.UI.ChartWithPercentageToolTip; form.Chart.Series[0].XValueMember = AmountByTransactionTypeEntry.TransactionTypeTitle; form.Chart.Series[0].YValueMembers = AmountByTransactionTypeEntry.AmountTitle; form.Chart.Series[0].Label = Consts.UI.ChartWithPercentageToolTip; form.Chart.Series[0].SmartLabelStyle.Enabled = true; form.Chart.Series[0].SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Underlined; form.Chart.Series[0].SmartLabelStyle.CalloutLineDashStyle = ChartDashStyle.Solid; form.Chart.Series[0].SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.Arrow; form.Chart.Series[0].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.Yes; form.Chart.Series[0].SmartLabelStyle.CalloutLineWidth = 1; form.Chart.Series[0][PieLabelStyle] = PieLabelStyleValue; form.Chart.ChartAreas[0].Area3DStyle.Enable3D = true; //form.Chart.ChartAreas[0].Area3DStyle.Rotation = 10; //form.Chart.Series[0].Palette = ChartColorPalette.Pastel; form.Chart.DataBind(); return form; } } catch (Exception e) { Log.Write(e); } return null; }