示例#1
0
        private void WriteDetails(IReportWriter writer, string prefix, SecurityGroup securityTypeGroup)
        {
            decimal      marketValue            = 0;
            decimal      costBasis              = 0;
            decimal      gainLoss               = 0;
            bool         foundSecuritiesInGroup = false;
            SecurityType st = securityTypeGroup.Type;

            string caption = prefix + Security.GetSecurityTypeCaption(st);

            IList <SecurityGroup> groups = calc.RegroupBySecurity(securityTypeGroup);

            foreach (SecurityGroup g in groups)
            {
                foreach (var i in g.Purchases)
                {
                    // only report the security group header if it has some units left in it.
                    if (i.UnitsRemaining > 0)
                    {
                        if (!foundSecuritiesInGroup)
                        {
                            foundSecuritiesInGroup = true;

                            // create the security type group and subtable for these securities.
                            writer.WriteSubHeading(caption);
                            writer.StartTable();
                            writer.StartColumnDefinitions();

                            foreach (var minwidth in new double[] { 20,  //Expander
                                                                    80,  // Date Acquired
                                                                    300, // Description
                                                                    100, // Quantity
                                                                    100, // Price
                                                                    100, // Market Value
                                                                    100, // Unit Cost
                                                                    100, // Cost Basis
                                                                    100, // Gain/Loss
                                                                    50,  // %
                                     })
                            {
                                writer.WriteColumnDefinition("Auto", minwidth, double.MaxValue);
                            }
                            writer.EndColumnDefinitions();
                            WriteRowHeaders(writer);
                            break;
                        }
                    }
                }
                if (foundSecuritiesInGroup)
                {
                    WriteSecurities(writer, g.Purchases, ref marketValue, ref costBasis, ref gainLoss);
                }
            }

            writer.StartFooterRow();
            WriteRow(writer, true, true, FontWeights.Bold, null, "Total", null, null, null, marketValue, null, costBasis, gainLoss);
            // only close the table
            writer.EndTable();
        }
示例#2
0
        private void WriteDetails(IReportWriter writer, string prefix, Predicate <Account> filter)
        {
            // compute summary
            foreach (var securityTypeGroup in calc.GetHoldingsBySecurityType(filter))
            {
                decimal marketValue = 0;
                decimal costBasis   = 0;
                decimal gainLoss    = 0;

                SecurityType st = securityTypeGroup.Key;

                string caption = prefix + Security.GetSecurityTypeCaption(st);

                bool     foundSecuritiesInGroup = false;
                Security current = null;
                List <SecurityPurchase> bySecurity = new List <SecurityPurchase>();

                foreach (SecurityPurchase i in securityTypeGroup.Value)
                {
                    if (current != null && current != i.Security)
                    {
                        WriteSecurities(writer, bySecurity, ref marketValue, ref costBasis, ref gainLoss);
                        bySecurity.Clear();
                    }
                    current = i.Security;

                    // only report the security group header if it has some units left in it.
                    if (i.UnitsRemaining > 0)
                    {
                        if (!foundSecuritiesInGroup)
                        {
                            foundSecuritiesInGroup = true;

                            // create the security type group and subtable for these securities.
                            writer.WriteSubHeading(caption);
                            writer.StartTable();
                            writer.StartColumnDefinitions();

                            foreach (var minwidth in new double[] { 20,  //Expander
                                                                    80,  // Date Acquired
                                                                    300, // Description
                                                                    100, // Quantity
                                                                    100, // Price
                                                                    100, // Market Value
                                                                    100, // Unit Cost
                                                                    100, // Cost Basis
                                                                    100, // Gain/Loss
                                                                    50,  // %
                                     })
                            {
                                writer.WriteColumnDefinition("Auto", minwidth, double.MaxValue);
                            }
                            writer.EndColumnDefinitions();
                            WriteRowHeaders(writer);
                        }
                        bySecurity.Add(i);
                    }
                }

                if (foundSecuritiesInGroup)
                {
                    // write the final group of securities.
                    WriteSecurities(writer, bySecurity, ref marketValue, ref costBasis, ref gainLoss);

                    writer.StartFooterRow();

                    WriteRow(writer, true, true, FontWeights.Bold, null, "Total", null, null, null, marketValue, null, costBasis, gainLoss);

                    // only close the table
                    writer.EndTable();
                }
            }
        }
示例#3
0
        public void Generate(IReportWriter writer)
        {
            writer.WriteHeading("Net Worth Statement");

            List <PieData> data = new List <PieData>();

            // outer table contains 2 columns, left is the summary table, right is the pie chart.
            writer.StartTable();
            writer.StartColumnDefinitions();
            writer.WriteColumnDefinition("420", 420, 420);
            writer.WriteColumnDefinition("620", 620, 620);
            writer.EndColumnDefinitions();
            writer.StartRow();
            writer.StartCell();

            // inner table contains the "data"
            writer.StartTable();
            writer.StartColumnDefinitions();
            foreach (double width in new double[] { 300, 100 })
            {
                writer.WriteColumnDefinition(width.ToString(), width, width);
            }
            writer.EndColumnDefinitions();

            WriteHeader(writer, "Liquid Assets");

            decimal totalBalance   = 0;
            decimal balance        = 0;
            bool    hasTaxDeferred = false;
            bool    hasRetirement  = false;

            Transactions transactions = myMoney.Transactions;

            foreach (Account a in this.myMoney.Accounts.GetAccounts(true))
            {
                if (a.Type == AccountType.Retirement)
                {
                    hasRetirement = true;
                    continue;
                }
                if (a.IsTaxDeferred)
                {
                    hasTaxDeferred = true;
                }
                if (a.Type == AccountType.Credit ||
                    a.Type == AccountType.Asset ||
                    a.Type == AccountType.Brokerage ||
                    a.Type == AccountType.CategoryFund ||
                    a.Type == AccountType.Loan)
                {
                    continue;
                }

                balance += a.BalanceNormalized;
            }

            if (balance > 0)
            {
                data.Add(new PieData()
                {
                    Name = "Cash", Total = balance
                });
            }
            WriteRow(writer, "Cash", balance);

            totalBalance += balance;
            balance       = this.myMoney.GetInvestmentCashBalance(new Predicate <Account>((a) => { return(!a.IsClosed && (a.Type == AccountType.Brokerage)); }));

            if (balance > 0)
            {
                data.Add(new PieData()
                {
                    Name = "Investment Cash", Total = balance
                });
            }
            WriteRow(writer, "Investment Cash", balance);
            totalBalance += balance;

            bool hasNoneRetirement = false;

            if (hasRetirement)
            {
                WriteHeader(writer, "Retirement Assets");
                balance = this.myMoney.GetInvestmentCashBalance(new Predicate <Account>((a) => { return(!a.IsClosed && a.Type == AccountType.Retirement); }));

                if (balance > 0)
                {
                    data.Add(new PieData()
                    {
                        Name = "Retirement Cash", Total = balance
                    });
                }
                WriteRow(writer, "Retirement Cash", balance);
                totalBalance += balance;

                totalBalance += WriteSecurities(writer, data, "Retirement ", new Predicate <Account>((a) => { return(a.Type == AccountType.Retirement); }), out hasNoneRetirement);
            }

            bool hasNoneTypeTaxDeferred = false;

            if (hasTaxDeferred)
            {
                WriteHeader(writer, "Tax Deferred Assets");
                totalBalance += WriteSecurities(writer, data, "Tax Deferred ", new Predicate <Account>((a) => { return(a.Type == AccountType.Brokerage && a.IsTaxDeferred); }), out hasNoneTypeTaxDeferred);
            }

            balance = 0;

            WriteHeader(writer, "Long Term 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...
                {
                    if (a.BalanceNormalized > 0)
                    {
                        data.Add(new PieData()
                        {
                            Name = a.Name, Total = a.BalanceNormalized
                        });
                    }
                    WriteRow(writer, a.Name, a.BalanceNormalized);
                    totalBalance += a.BalanceNormalized;
                }
            }

            bool hasNoneType = false;

            totalBalance += WriteSecurities(writer, data, "", new Predicate <Account>((a) => { return(a.Type == AccountType.Brokerage && !a.IsTaxDeferred); }), 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;

            if (balance > 0)
            {
                data.Add(new PieData()
                {
                    Name = "Credit", Total = balance
                });
            }
            WriteRow(writer, "Credit", balance);
            balance = 0;
            foreach (Account a in this.myMoney.Accounts.GetAccounts(true))
            {
                if (a.Type == AccountType.Loan && a.BalanceNormalized < 0)
                {
                    balance += a.BalanceNormalized;
                    if (a.BalanceNormalized > 0)
                    {
                        data.Add(new PieData()
                        {
                            Name = a.Name, Total = a.BalanceNormalized
                        });
                    }
                    WriteRow(writer, a.Name, a.BalanceNormalized);
                }
            }
            totalBalance += balance;

            writer.StartFooterRow();

            writer.StartCell();
            writer.WriteParagraph("Total");
            writer.EndCell();

            writer.StartCell();
            writer.WriteNumber(totalBalance.ToString("C"));
            writer.EndCell();

            writer.EndRow();
            writer.EndTable();

            writer.EndCell();
            writer.StartCell();


            // pie chart
            Chart chart = new Chart();

            chart.MinWidth          = 600;
            chart.MinHeight         = 400;
            chart.BorderThickness   = new Thickness(0);
            chart.VerticalAlignment = VerticalAlignment.Top;

            PieSeries series = new PieSeries();

            series.IndependentValueBinding = new Binding("Name");
            series.DependentValueBinding   = new Binding("Total");
            chart.Series.Add(series);
            series.ItemsSource = data;

            writer.WriteElement(chart);

            writer.EndCell();
            writer.EndRow();
            writer.EndTable();

            if (hasNoneRetirement || hasNoneTypeTaxDeferred || 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);
        }
示例#4
0
        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);
        }