public void Generate(IReportWriter writer) { flowwriter = writer as FlowDocumentReportWriter; calc = new CostBasisCalculator(this.myMoney, this.reportDate); string heading = "Investment Portfolio Summary"; if (this.selectedGroup != null) { heading = "Investment Portfolio - " + this.selectedGroup.Type; } if (this.account != null) { heading += " for " + account.Name + " (" + account.AccountId + ")"; } writer.WriteHeading(heading); if (reportDate.Date != DateTime.Today) { writer.WriteSubHeading("As of " + reportDate.Date.AddDays(-1).ToLongDateString()); } totalMarketValue = 0; totalGainLoss = 0; // outer table contains 2 columns, left is the summary table, right is the pie chart. writer.StartTable(); writer.StartColumnDefinitions(); writer.WriteColumnDefinition("Auto", 100, double.MaxValue); writer.WriteColumnDefinition("Auto", 100, double.MaxValue); writer.EndColumnDefinitions(); writer.StartRow(); writer.StartCell(); writer.StartTable(); writer.StartColumnDefinitions(); writer.WriteColumnDefinition("30", 30, 30); foreach (double minWidth in new double[] { 300, 100, 100 }) { writer.WriteColumnDefinition("Auto", minWidth, double.MaxValue); } writer.EndColumnDefinitions(); var series = new ChartDataSeries() { Name = "Portfolio" }; IList <ChartDataValue> data = series.Values; if (account == null) { if (this.selectedGroup != null) { WriteSummary(writer, data, TaxStatus.Taxable, null, null, false); } else { WriteSummary(writer, data, TaxStatus.TaxFree, "Tax Free ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxFree && IsInvestmentAccount(a)); }), true); WriteSummary(writer, data, TaxStatus.TaxDeferred, "Tax Deferred ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && IsInvestmentAccount(a)); }), true); WriteSummary(writer, data, TaxStatus.Taxable, "Taxable ", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxDeferred && !a.IsTaxFree && IsInvestmentAccount(a)); }), true); } } else { WriteSummary(writer, data, account.TaxStatus, "", new Predicate <Account>((a) => { return(a == account); }), false); } WriteHeaderRow(writer, "Total", totalMarketValue.ToString("C"), totalGainLoss.ToString("C")); writer.EndTable(); writer.EndCell(); // pie chart AnimatingPieChart chart = new AnimatingPieChart(); chart.Width = 400; chart.Height = 300; chart.BorderThickness = new Thickness(0); chart.Padding = new Thickness(0); chart.Margin = new Thickness(0, 00, 0, 0); chart.VerticalAlignment = VerticalAlignment.Top; chart.HorizontalAlignment = HorizontalAlignment.Left; chart.Series = series; chart.ToolTipGenerator = OnGenerateToolTip; chart.PieSliceClicked += OnPieSliceClicked; writer.StartCell(); writer.WriteElement(chart); writer.EndCell(); // end the outer table. writer.EndTable(); totalMarketValue = 0; totalGainLoss = 0; if (this.selectedGroup != null) { WriteDetails(writer, "", this.selectedGroup); } else { List <SecuritySale> errors = new List <SecuritySale>(calc.GetPendingSales(new Predicate <Account>((a) => { return(a == account); }))); if (errors.Count > 0) { writer.WriteSubHeading("Pending Sales"); foreach (var sp in errors) { writer.WriteParagraph(string.Format("Pending sale of {1} units of '{2}' from account '{0}' recorded on {3}", sp.Account.Name, sp.UnitsSold, sp.Security.Name, sp.DateSold.ToShortDateString())); } } if (account == null) { WriteDetails(writer, "Tax Free ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxFree && IsInvestmentAccount(a)); })); WriteDetails(writer, "Tax Deferred ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && IsInvestmentAccount(a)); })); WriteDetails(writer, "Taxable ", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxFree && !a.IsTaxDeferred && IsInvestmentAccount(a)); })); } else { WriteDetails(writer, "", new Predicate <Account>((a) => { return(a == account); })); } } }
public void Generate(IReportWriter writer) { writer.WriteHeading("Net Worth Statement"); var series = new ChartDataSeries() { Name = "Net Worth" }; IList <ChartDataValue> data = series.Values; // outer table contains 2 columns, left is the summary table, right is the pie chart. writer.StartTable(); writer.StartColumnDefinitions(); writer.WriteColumnDefinition("450", 450, 450); writer.WriteColumnDefinition("620", 620, 620); writer.EndColumnDefinitions(); writer.StartRow(); writer.StartCell(); // inner table contains the "data" writer.StartTable(); writer.StartColumnDefinitions(); writer.WriteColumnDefinition("30", 30, 30); writer.WriteColumnDefinition("300", 300, 300); writer.WriteColumnDefinition("Auto", 100, double.MaxValue); writer.EndColumnDefinitions(); WriteHeader(writer, "Cash"); decimal totalBalance = 0; decimal balance = 0; bool hasTaxDeferred = false; bool hasTaxFree = false; Transactions transactions = myMoney.Transactions; foreach (Account a in this.myMoney.Accounts.GetAccounts(true)) { if (a.IsTaxDeferred) { hasTaxDeferred = true; } if (a.IsTaxFree) { hasTaxFree = true; } if (a.Type == AccountType.Credit || a.Type == AccountType.Asset || a.Type == AccountType.Brokerage || a.Type == AccountType.Retirement || a.Type == AccountType.CategoryFund || a.Type == AccountType.Loan) { continue; } balance += a.BalanceNormalized; } // Non-investment Cash var color = GetRandomColor(); if (balance > 0) { data.Add(new ChartDataValue() { Label = "Cash", Value = (double)balance, Color = color }); } WriteRow(writer, color, "Cash", balance); totalBalance += balance; // Investment Cash balance = this.myMoney.GetInvestmentCashBalanceNormalized(new Predicate <Account>((a) => { return(!a.IsClosed && IsInvestmentAccount(a)); })); color = GetRandomColor(); data.Add(new ChartDataValue() { Label = "Investment Cash", Value = (double)balance, Color = color }); WriteRow(writer, color, "Investment Cash", balance); totalBalance += balance; bool hasNoneTypeTaxDeferred = false; if (hasTaxDeferred) { WriteHeader(writer, "Tax Deferred Assets"); totalBalance += WriteSecurities(writer, data, "Tax Deferred ", new Predicate <Account>((a) => { return(a.IsTaxDeferred); }), out hasNoneTypeTaxDeferred); } bool hasNoneTypeTaxFree = false; if (hasTaxFree) { WriteHeader(writer, "Tax Free Assets"); totalBalance += WriteSecurities(writer, data, "Tax Free ", new Predicate <Account>((a) => { return(a.IsTaxFree); }), out hasNoneTypeTaxFree); } balance = 0; WriteHeader(writer, "Other Assets"); foreach (Account a in this.myMoney.Accounts.GetAccounts(true)) { if ((a.Type == AccountType.Loan || a.Type == AccountType.Asset) && a.Balance > 0) // then this is a loan out to someone else... { color = GetRandomColor(); if (a.BalanceNormalized > 0) { data.Add(new ChartDataValue() { Label = a.Name, Value = (double)a.BalanceNormalized, Color = color }); } WriteRow(writer, color, a.Name, a.BalanceNormalized); totalBalance += a.BalanceNormalized; } } bool hasNoneType = false; totalBalance += WriteSecurities(writer, data, "", new Predicate <Account>((a) => { return(IsInvestmentAccount(a) && !a.IsTaxDeferred && !a.IsTaxFree); }), out hasNoneType); balance = 0; WriteHeader(writer, "Liabilities"); foreach (Account a in this.myMoney.Accounts.GetAccounts(true)) { if (a.Type != AccountType.Credit) { continue; } balance += a.BalanceNormalized; } totalBalance += balance; color = GetRandomColor(); if (balance > 0) { data.Add(new ChartDataValue() { Label = "Credit", Value = (double)balance, Color = color }); } WriteRow(writer, color, "Credit", balance); balance = 0; foreach (Account a in this.myMoney.Accounts.GetAccounts(true)) { if (a.Type == AccountType.Loan && a.BalanceNormalized < 0) { balance += a.BalanceNormalized; color = GetRandomColor(); if (a.BalanceNormalized > 0) { data.Add(new ChartDataValue() { Label = a.Name, Value = (double)a.BalanceNormalized, Color = color }); } WriteRow(writer, color, a.Name, a.BalanceNormalized); } } totalBalance += balance; writer.StartFooterRow(); writer.StartCell(1, 2); writer.WriteParagraph("Total"); writer.EndCell(); writer.StartCell(); writer.WriteNumber(totalBalance.ToString("C")); writer.EndCell(); writer.EndRow(); writer.EndTable(); writer.EndCell(); writer.StartCell(); // pie chart AnimatingPieChart chart = new AnimatingPieChart(); chart.Width = 600; chart.Height = 400; chart.BorderThickness = new Thickness(0); chart.VerticalAlignment = VerticalAlignment.Top; chart.Series = series; chart.ToolTipGenerator = OnGenerateToolTip; chart.PieSliceClicked += OnPieSliceClicked; writer.WriteElement(chart); writer.EndCell(); writer.EndRow(); writer.EndTable(); if (hasNoneTypeTaxDeferred || hasNoneTypeTaxFree || hasNoneType) { writer.WriteParagraph("(*) One ore more of your securities has no SecurityType, you can fix this using View/Securities", System.Windows.FontStyles.Italic, System.Windows.FontWeights.Normal, System.Windows.Media.Brushes.Maroon); } writer.WriteParagraph("Generated on " + DateTime.Today.ToLongDateString(), System.Windows.FontStyles.Italic, System.Windows.FontWeights.Normal, System.Windows.Media.Brushes.Gray); }