예제 #1
0
        private void WriteRow(IReportWriter writer, bool header, bool addExpanderCell, string name, IEnumerable <CashFlowCell> cells)
        {
            if (header)
            {
                writer.StartHeaderRow();
            }
            else
            {
                writer.StartRow();
            }

            if (addExpanderCell)
            {
                writer.StartCell();
                writer.EndCell();
            }

            writer.StartCell();
            writer.WriteParagraph(name);
            writer.EndCell();

            foreach (CashFlowCell cell in cells)
            {
                writer.StartCell();

                if (cell.Value != 0)
                {
                    writer.WriteNumber(cell.Value.ToString("N0"));

                    if (cell.Data.Count > 0)
                    {
                        FlowDocumentReportWriter fw = (FlowDocumentReportWriter)writer;
                        Paragraph p = fw.CurrentParagraph;
                        p.Tag = cell;
                        p.PreviewMouseLeftButtonDown += OnReportCellMouseDown;
                        p.Cursor = Cursors.Arrow;
                        //p.TextDecorations.Add(TextDecorations.Underline);
                        //p.Foreground = Brushes.DarkSlateBlue;
                        p.SetResourceReference(Paragraph.ForegroundProperty, "HyperlinkForeground");
                    }
                }

                writer.EndCell();
            }

            writer.EndRow();
        }
예제 #2
0
        public void Generate(IReportWriter writer)
        {
            flowwriter = writer as FlowDocumentReportWriter;

            calc = new CostBasisCalculator(this.myMoney, this.reportDate);

            string heading = "Investment Portfolio Summary";

            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();

            foreach (double minWidth in new double[] { 300, 100, 100 })
            {
                writer.WriteColumnDefinition("Auto", minWidth, double.MaxValue);
            }
            writer.EndColumnDefinitions();
            writer.StartHeaderRow();
            writer.StartCell();
            writer.WriteParagraph("Security Type");
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber("Market Value");
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber("Gain/Loss");
            writer.EndCell();
            writer.EndRow();

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

            decimal cash = this.myMoney.GetInvestmentCashBalance(account);

            if (cash > 0)
            {
                writer.StartRow();
                writer.StartCell();
                writer.WriteParagraph("Cash");
                writer.EndCell();
                writer.StartCell();
                writer.WriteNumber(cash.ToString("C"));
                writer.EndCell();
                writer.EndRow();

                data.Add(new SecurityPieData()
                {
                    Total = RoundToNearestCent(cash),
                    Name  = "Cash"
                });
            }

            totalMarketValue += cash;

            if (account == null)
            {
                WriteSummary(writer, data, "Tax Deferred ", new Predicate <Account>((a) => { return(a.IsTaxDeferred); }));
                WriteSummary(writer, data, "", new Predicate <Account>((a) => { return(!a.IsTaxDeferred); }));
            }
            else
            {
                WriteSummary(writer, data, "", new Predicate <Account>((a) => { return(a == account); }));
            }

            writer.StartHeaderRow();
            writer.StartCell();
            writer.WriteParagraph("Total");
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber(totalMarketValue.ToString("C"));
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber(totalGainLoss.ToString("C"));
            writer.EndCell();
            writer.EndRow();
            writer.EndTable();

            writer.EndCell();
            // pie chart
            Chart chart = new Chart();

            chart.MinWidth            = 400;
            chart.MinHeight           = 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;

            PieSeries series = new PieSeries();

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

            writer.StartCell();
            writer.WriteElement(chart);
            writer.EndCell();

            // end the outer table.
            writer.EndTable();

            totalMarketValue = 0;
            totalGainLoss    = 0;

            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 Deferred ", new Predicate <Account>((a) => { return(a.IsTaxDeferred); }));
                WriteDetails(writer, "", new Predicate <Account>((a) => { return(!a.IsTaxDeferred); }));
            }
            else
            {
                WriteDetails(writer, "", new Predicate <Account>((a) => { return(a == account); }));
            }
        }
예제 #3
0
        private void WriteRow(IReportWriter writer, bool expandable, bool header, FontWeight weight, DateTime?aquired, string description, string descriptionUrl, decimal?quantity, decimal?price, decimal marketValue, decimal?unitCost, decimal costBasis, decimal gainLoss)
        {
            if (header)
            {
                writer.StartHeaderRow();
            }
            else
            {
                writer.StartRow();
            }

            if (expandable)
            {
                writer.StartCell();
                writer.EndCell();
            }

            writer.StartCell();
            if (aquired.HasValue)
            {
                writer.WriteParagraph(aquired.Value.ToShortDateString(), FontStyles.Normal, weight, null);
            }
            writer.EndCell();

            writer.StartCell();
            writer.WriteParagraph(description, FontStyles.Normal, weight, null);
            if (!string.IsNullOrEmpty(descriptionUrl))
            {
                FlowDocumentReportWriter fw = (FlowDocumentReportWriter)writer;
                Paragraph p = fw.CurrentParagraph;
                p.Tag = descriptionUrl;
                p.PreviewMouseLeftButtonDown += OnReportCellMouseDown;
                p.Cursor = Cursors.Arrow;
                //p.TextDecorations.Add(TextDecorations.Underline);
                p.SetResourceReference(Paragraph.ForegroundProperty, "HyperlinkForeground");
            }
            writer.EndCell();

            writer.StartCell();
            if (quantity.HasValue)
            {
                writer.WriteNumber(quantity.Value.ToString("N2"));
            }
            writer.EndCell();

            writer.StartCell();
            if (price.HasValue)
            {
                writer.WriteNumber(price.Value.ToString("N2"));
            }
            writer.EndCell();

            writer.StartCell();
            writer.WriteNumber(marketValue.ToString("N2"));
            writer.EndCell();

            writer.StartCell();
            if (unitCost.HasValue)
            {
                writer.WriteNumber(unitCost.Value.ToString("N2"));
            }
            writer.EndCell();

            writer.StartCell();
            writer.WriteNumber(costBasis.ToString("N2"));
            writer.EndCell();

            writer.StartCell();
            writer.WriteNumber(gainLoss.ToString("N2"));
            writer.EndCell();

            writer.StartCell();
            decimal percent = costBasis == 0 ? 0 : (gainLoss / costBasis) * 100;

            writer.WriteNumber(percent.ToString("N0"));
            writer.EndCell();

            writer.EndRow();
        }
예제 #4
0
        public override void Generate(IReportWriter writer)
        {
            byCategory = new Dictionary <Category, CashFlowColumns>();

            FlowDocumentReportWriter fwriter = (FlowDocumentReportWriter)writer;

            writer.WriteHeading("Cash Flow Report ");

            ICollection <Transaction> transactions = this.myMoney.Transactions.GetAllTransactionsByDate();

            int startYear = year;
            int lastYear  = year;

            Transaction first = transactions.FirstOrDefault();

            if (first != null)
            {
                startYear = first.Date.Year;
            }
            Transaction last = transactions.LastOrDefault();

            if (last != null)
            {
                lastYear = last.Date.Year;
            }

            columns = new List <string>();

            DateTime date = new DateTime(year, month, 1);

            for (int i = columnCount - 1; i >= 0; i--)
            {
                if (byYear)
                {
                    int    y          = year - i;
                    string columnName = y.ToString();
                    columns.Add(columnName);
                    GenerateColumn(writer, columnName, transactions, 0, y);
                }
                else
                {
                    int      m          = month - i;
                    DateTime md         = date.AddMonths(-i);
                    string   columnName = md.ToString("MM/yyyy");
                    columns.Add(columnName);
                    GenerateColumn(writer, columnName, transactions, md.Month, md.Year);
                }
            }


            Paragraph heading = fwriter.CurrentParagraph;

            monthMap = new Dictionary <string, int>();

            heading.Inlines.Add(" including ");

            ComboBox countCombo = new ComboBox();

            countCombo.Margin = new System.Windows.Thickness(5, 0, 0, 0);
            for (int i = 1; i <= 12; i++)
            {
                countCombo.Items.Add(i.ToString());
            }
            countCombo.SelectedIndex     = this.columnCount - 1;
            countCombo.SelectionChanged += OnColumnCountChanged;
            heading.Inlines.Add(new InlineUIContainer(countCombo));

            ComboBox byYearMonthCombo = new ComboBox();

            byYearMonthCombo.Margin = new System.Windows.Thickness(5, 0, 0, 0);
            byYearMonthCombo.Items.Add("Years");
            byYearMonthCombo.Items.Add("Months");

            byYearMonthCombo.SelectedIndex     = (byYear ? 0 : 1);
            byYearMonthCombo.SelectionChanged += OnByYearMonthChanged;

            heading.Inlines.Add(new InlineUIContainer(byYearMonthCombo));

            heading.Inlines.Add(new InlineUIContainer(CreateExportReportButton()));

            writer.StartTable();
            writer.StartColumnDefinitions();

            writer.WriteColumnDefinition("20", 20, 20); // expander column
            writer.WriteColumnDefinition("300", 300, 300);

            for (int i = 0; i < columns.Count; i++)
            {
                writer.WriteColumnDefinition("Auto", 100, double.MaxValue);
            }
            writer.EndColumnDefinitions();


            WriteRow(writer, true, true, "", this.columns.ToArray());

            CashFlowColumns columnTotals = new CashFlowColumns();

            GenerateGroup(writer, byCategory, columnTotals, "Income", (c) => { return(IsIncome(c)); });

            GenerateGroup(writer, byCategory, columnTotals, "Expenses", (c) => { return(IsExpense(c)); });

            GenerateGroup(writer, byCategory, columnTotals, "Investments", (c) => { return(IsInvestment(c)); });

            List <decimal> totals  = columnTotals.GetOrderedValues(this.columns);
            decimal        balance = (from d in totals select d).Sum();

            WriteRow(writer, true, true, "Total", FormatValues(totals).ToArray());

            writer.EndTable();

            writer.WriteParagraph("Net cash flow for this period is " + balance.ToString("C0"));

            writer.WriteParagraph("Generated on " + DateTime.Today.ToLongDateString(), System.Windows.FontStyles.Italic, System.Windows.FontWeights.Normal, System.Windows.Media.Brushes.Gray);
        }
예제 #5
0
        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); }));
                }
            }
        }
예제 #6
0
        public override void Generate(IReportWriter writer)
        {
            byCategory = new Dictionary <Category, CashFlowColumns>();

            FlowDocumentReportWriter fwriter = (FlowDocumentReportWriter)writer;

            writer.WriteHeading("Cash Flow Report ");

            ICollection <Transaction> transactions = this.myMoney.Transactions.GetAllTransactionsByDate();

            DateTime    firstTransactionDate = DateTime.Now;
            Transaction first = transactions.FirstOrDefault();

            if (first != null)
            {
                firstTransactionDate = first.Date;
            }

            columns = new List <string>();

            DateTime start = this.startDate;

            while (start < this.endDate)
            {
                DateTime end        = (byYear) ? start.AddYears(1) : start.AddMonths(1);
                string   columnName = start.ToString("MM/yyyy");
                if (byYear)
                {
                    columnName = (this.fiscalYearStart == 0) ? start.Year.ToString() : "FY" + end.Year.ToString();
                }
                columns.Add(columnName);
                GenerateColumn(writer, columnName, transactions, start, end);
                start = end;
            }

            Paragraph heading = fwriter.CurrentParagraph;

            monthMap = new Dictionary <string, int>();
            heading.Inlines.Add(" - from ");

            var previousButton = new Button();

            previousButton.Content    = "\uE100";
            previousButton.ToolTip    = "Previous year";
            previousButton.FontFamily = new FontFamily("Segoe UI Symbol");
            previousButton.Click     += OnPreviousClick;
            previousButton.Margin     = new System.Windows.Thickness(5, 0, 0, 0);
            heading.Inlines.Add(new InlineUIContainer(previousButton));

            DatePicker fromPicker = new DatePicker();

            fromPicker.DisplayDateStart     = firstTransactionDate;
            fromPicker.SelectedDate         = this.startDate;
            fromPicker.Margin               = new System.Windows.Thickness(5, 0, 0, 0);
            fromPicker.SelectedDateChanged += OnSelectedFromDateChanged;
            heading.Inlines.Add(new InlineUIContainer(fromPicker));

            heading.Inlines.Add(" to ");

            DatePicker toPicker = new DatePicker();

            toPicker.DisplayDateStart     = firstTransactionDate;
            toPicker.SelectedDate         = this.endDate;
            toPicker.Margin               = new System.Windows.Thickness(5, 0, 0, 0);
            toPicker.SelectedDateChanged += OnSelectedToDateChanged;;
            heading.Inlines.Add(new InlineUIContainer(toPicker));

            var nextButton = new Button();

            nextButton.Content    = "\uE101";
            nextButton.ToolTip    = "Next year";
            nextButton.FontFamily = new FontFamily("Segoe UI Symbol");
            nextButton.Margin     = new System.Windows.Thickness(5, 0, 0, 0);
            nextButton.Click     += OnNextClick;
            heading.Inlines.Add(new InlineUIContainer(nextButton));


            ComboBox byYearMonthCombo = new ComboBox();

            byYearMonthCombo.Margin = new System.Windows.Thickness(5, 0, 0, 0);
            byYearMonthCombo.Items.Add("by years");
            byYearMonthCombo.Items.Add("by month");
            byYearMonthCombo.SelectedIndex     = (byYear ? 0 : 1);
            byYearMonthCombo.SelectionChanged += OnByYearMonthChanged;

            heading.Inlines.Add(new InlineUIContainer(byYearMonthCombo));

            heading.Inlines.Add(new InlineUIContainer(CreateExportReportButton()));

            writer.StartTable();
            writer.StartColumnDefinitions();

            writer.WriteColumnDefinition("20", 20, 20); // expander column
            writer.WriteColumnDefinition("300", 300, 300);

            for (int i = 0; i < columns.Count; i++)
            {
                writer.WriteColumnDefinition("Auto", 100, double.MaxValue);
            }
            writer.EndColumnDefinitions();


            WriteRow(writer, true, true, "", this.columns.ToArray());

            CashFlowColumns columnTotals = new CashFlowColumns();

            GenerateGroup(writer, byCategory, columnTotals, "Income", (c) => { return(IsIncome(c)); });

            GenerateGroup(writer, byCategory, columnTotals, "Expenses", (c) => { return(IsExpense(c)); });

            GenerateGroup(writer, byCategory, columnTotals, "Investments", (c) => { return(IsInvestment(c)); });

            GenerateGroup(writer, byCategory, columnTotals, "Unknown", (c) => { return(IsUnknown(c)); });


            List <decimal> totals  = columnTotals.GetOrderedValues(this.columns);
            decimal        balance = (from d in totals select d).Sum();

            WriteRow(writer, true, true, "Total", FormatValues(totals).ToArray());

            writer.EndTable();

            writer.WriteParagraph("Net cash flow for this period is " + balance.ToString("C0"));

            writer.WriteParagraph("Generated on " + DateTime.Today.ToLongDateString(), System.Windows.FontStyles.Italic, System.Windows.FontWeights.Normal, System.Windows.Media.Brushes.Gray);
        }
예제 #7
0
        public void Generate(IReportWriter writer)
        {
            flowwriter = writer as FlowDocumentReportWriter;

            calc = new CostBasisCalculator(this.myMoney, this.reportDate);

            string heading = "Investment Portfolio Summary";

            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();

            foreach (double minWidth in new double[] { 300, 100, 100 })
            {
                writer.WriteColumnDefinition("Auto", minWidth, double.MaxValue);
            }
            writer.EndColumnDefinitions();



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

            if (account == null)
            {
                WriteSummary(writer, data, TaxableIncomeType.None, "Retirement Tax Free ", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxDeferred && a.Type == AccountType.Retirement); }), true);
                WriteSummary(writer, data, TaxableIncomeType.All, "Retirement ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && a.Type == AccountType.Retirement); }), true);
                WriteSummary(writer, data, TaxableIncomeType.All, "Tax Deferred ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && a.Type == AccountType.Brokerage); }), true);
                WriteSummary(writer, data, TaxableIncomeType.Gains, "", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxDeferred && a.Type == AccountType.Brokerage); }), true);
            }
            else
            {
                TaxableIncomeType taxableIncomeType;

                if (account.IsTaxDeferred)
                {
                    taxableIncomeType = TaxableIncomeType.All;
                }
                else
                {
                    if (account.Type == AccountType.Retirement)
                    {
                        // Currently treating this combination as tax free
                        taxableIncomeType = TaxableIncomeType.None;
                    }
                    else
                    {
                        taxableIncomeType = TaxableIncomeType.Gains;
                    }
                }

                WriteSummary(writer, data, taxableIncomeType, "", new Predicate <Account>((a) => { return(a == account); }), false);
            }

            WriteheaderRow(writer, "Total", totalMarketValue.ToString("C"), totalGainLoss.ToString("C"));
            writer.EndTable();

            writer.EndCell();
            // pie chart
            Chart chart = new Chart();

            chart.MinWidth            = 400;
            chart.MinHeight           = 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;

            PieSeries series = new PieSeries();

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

            writer.StartCell();
            writer.WriteElement(chart);
            writer.EndCell();

            // end the outer table.
            writer.EndTable();

            totalMarketValue = 0;
            totalGainLoss    = 0;

            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, "Retirement Tax Free ", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxDeferred && a.Type == AccountType.Retirement); }));
                WriteDetails(writer, "Retirement ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && a.Type == AccountType.Retirement); }));
                WriteDetails(writer, "Tax Deferred ", new Predicate <Account>((a) => { return(!a.IsClosed && a.IsTaxDeferred && a.Type == AccountType.Brokerage); }));
                WriteDetails(writer, "", new Predicate <Account>((a) => { return(!a.IsClosed && !a.IsTaxDeferred && a.Type == AccountType.Brokerage); }));
            }
            else
            {
                WriteDetails(writer, "", new Predicate <Account>((a) => { return(a == account); }));
            }
        }
예제 #8
0
        public override void Generate(IReportWriter writer)
        {
            FlowDocumentReportWriter fwriter = (FlowDocumentReportWriter)writer;

            writer.WriteHeading("Tax Report For ");

            int firstYear = DateTime.Now.Year;
            int lastYear  = DateTime.Now.Year;

            ICollection <Transaction> transactions = this.money.Transactions.GetAllTransactionsByDate();
            Transaction first = transactions.FirstOrDefault();

            if (first != null)
            {
                firstYear = first.Date.Year;
            }
            Transaction last = transactions.LastOrDefault();

            if (last != null)
            {
                lastYear = last.Date.Year;
                if (this.fiscalYearStart > 0 && last.Date.Month > this.fiscalYearStart + 1)
                {
                    lastYear++;
                }
                // don't show a report containing zero data.  Scroll back to the last year
                // of data and show that.
                if (this.fiscalYearStart > 0 && lastYear > this.endDate.Year)
                {
                    SetStartDate(lastYear);
                }
                else if (this.fiscalYearStart == 0 && this.startDate.Year > lastYear)
                {
                    SetStartDate(lastYear);
                }
            }
            Paragraph heading = fwriter.CurrentParagraph;

            ComboBox byYearCombo = new ComboBox();

            byYearCombo.Margin = new System.Windows.Thickness(5, 0, 0, 0);
            int selected = -1;
            int index    = 0;

            for (int i = firstYear; i <= lastYear; i++)
            {
                if (this.fiscalYearStart > 0 && i == this.endDate.Year)
                {
                    selected = index;
                }
                else if (this.fiscalYearStart == 0 && i == this.startDate.Year)
                {
                    selected = index;
                }
                if (this.fiscalYearStart > 0)
                {
                    byYearCombo.Items.Add("FY " + i);
                }
                else
                {
                    byYearCombo.Items.Add(i.ToString());
                }
                index++;
            }

            if (selected != -1)
            {
                byYearCombo.SelectedIndex = selected;
            }
            byYearCombo.SelectionChanged += OnYearChanged;
            byYearCombo.Margin            = new Thickness(10, 0, 0, 0);

            heading.Inlines.Add(new InlineUIContainer(byYearCombo));

            /*
             * <StackPanel Margin="10,5,10,5"  Grid.Row="2" Orientation="Horizontal">
             *  <TextBlock Text="Consolidate securities by: " Background="Transparent"/>
             *  <ComboBox x:Name="ConsolidateSecuritiesCombo" SelectedIndex="0">
             *      <ComboBoxItem>Date Acquired</ComboBoxItem>
             *      <ComboBoxItem>Date Sold</ComboBoxItem>
             *  </ComboBox>
             * </StackPanel>
             * <CheckBox Margin="10,5,10,5" x:Name="CapitalGainsOnlyCheckBox" Grid.Row="3">Capital Gains Only</CheckBox>
             */

            ComboBox consolidateCombo = new ComboBox();

            consolidateCombo.Items.Add("Date Acquired");
            consolidateCombo.Items.Add("Date Sold");
            consolidateCombo.SelectedIndex     = this.consolidateOnDateSold ? 1 : 0;
            consolidateCombo.SelectionChanged += OnConsolidateComboSelectionChanged;

            writer.WriteParagraph("Consolidate securities by: ");
            Paragraph prompt = fwriter.CurrentParagraph;

            prompt.Margin = new Thickness(0, 0, 0, 4);
            prompt.Inlines.Add(new InlineUIContainer(consolidateCombo));

            CheckBox checkBox = new CheckBox();

            checkBox.Content    = "Capital Gains Only";
            checkBox.IsChecked  = this.capitalGainsOnly;
            checkBox.Checked   += OnCapitalGainsOnlyChanged;
            checkBox.Unchecked += OnCapitalGainsOnlyChanged;
            writer.WriteParagraph("");
            Paragraph checkBoxParagraph = fwriter.CurrentParagraph;

            checkBoxParagraph.Inlines.Add(new InlineUIContainer(checkBox));

            if (!capitalGainsOnly)
            {
                // find all tax related categories and summarize accordingly.
                GenerateCategories(writer);
            }
            GenerateCapitalGains(writer);

            FlowDocument document = view.DocumentViewer.Document;

            document.Blocks.InsertAfter(document.Blocks.FirstBlock, new BlockUIContainer(CreateExportTxfButton()));
        }
예제 #9
0
        public override void Generate(IReportWriter writer)
        {
            if (writer is FlowDocumentReportWriter)
            {
                FlowDocumentReportWriter fw = (FlowDocumentReportWriter)writer;
                var doc = fw.Document;
                if (doc != null)
                {
                    doc.Blocks.InsertAfter(doc.Blocks.FirstBlock, new BlockUIContainer(CreateExportReportButton()));
                }
            }
            writer.WriteHeading("Budget Report");

            this.rows = new Dictionary <string, BudgetRow>();

            this.columns = new Dictionary <DateTime, BudgetColumn>();

            foreach (Category rc in money.Categories.GetRootCategories())
            {
                if (rc.Type != CategoryType.Expense)
                {
                    continue;
                }
                string rowHeader = rc.Name;
                this.CategoryFilter = rc;


                // Add column for the budget itself.
                BudgetColumn budgetColumn;
                if (!columns.TryGetValue(DateTime.MinValue, out budgetColumn))
                {
                    budgetColumn = new BudgetColumn()
                    {
                        Name = BudgetColumnHeader,
                    };
                    columns[DateTime.MinValue] = budgetColumn;
                }
                budgetColumn.Total += rc.Budget;

                foreach (BudgetData b in this.Compute())
                {
                    BudgetRow row = null;
                    if (!rows.TryGetValue(rowHeader, out row))
                    {
                        row = new BudgetRow()
                        {
                            Name   = rowHeader,
                            Budget = rc.Budget
                        };
                        rows[rowHeader] = row;
                    }

                    DateTime budgetDate = new DateTime(b.BudgetDate.Year, b.BudgetDate.Month, 1);
                    row.Actuals.Add((decimal)b.Actual);
                    row.Headers.Add(b.Name);

                    // Add column for this BudgetData
                    BudgetColumn col;
                    if (!columns.TryGetValue(budgetDate, out col))
                    {
                        col = new BudgetColumn()
                        {
                            Date = budgetDate,
                            Name = b.Name
                        };
                        columns[budgetDate] = col;
                    }
                    col.Total += (decimal)b.Actual;
                }
            }

            writer.StartTable();

            writer.StartColumnDefinitions();
            writer.WriteColumnDefinition("300", 300, 300); // category names
            foreach (var pair in from p in columns orderby p.Key select p)
            {
                writer.WriteColumnDefinition("Auto", 100, double.MaxValue); // decimal values.
            }
            writer.WriteColumnDefinition("Auto", 100, double.MaxValue);     // total.
            writer.EndColumnDefinitions();

            // write table headers
            List <string> master = new List <string>();

            writer.StartHeaderRow();
            writer.StartCell();
            writer.EndCell();
            foreach (var pair in from p in columns orderby p.Key select p)
            {
                BudgetColumn c    = pair.Value;
                string       name = c.Name;
                if (name != BudgetColumnHeader)
                {
                    master.Add(name); // list of all columns we have found (not including "Budget" column)
                }
                writer.StartCell();
                writer.WriteNumber(name);
                writer.EndCell();
            }
            writer.StartCell();
            writer.WriteNumber("Balance");
            writer.EndCell();
            writer.EndRow();

            Brush   overBudgetBrush = Brushes.Red;
            decimal totalBalance    = 0;

            // Now write out the rows.
            foreach (BudgetRow row in from r in rows.Values orderby r.Name select r)
            {
                writer.StartRow();
                writer.StartCell();
                writer.WriteParagraph(row.Name);
                writer.EndCell();

                writer.StartCell();
                decimal budget = row.Budget;
                writer.WriteNumber(budget.ToString("C"));
                writer.EndCell();

                decimal balance = 0;

                foreach (string col in master)
                {
                    writer.StartCell();
                    int i = row.Headers.IndexOf(col);
                    if (i >= 0)
                    {
                        decimal actual = row.Actuals[i];
                        writer.WriteNumber(actual.ToString("C"), FontStyles.Normal, FontWeights.Normal,
                                           actual > budget ? overBudgetBrush : null);

                        balance += (row.Budget - actual);
                    }
                    writer.EndCell();
                }

                totalBalance += balance;

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

                writer.EndRow();
            }

            // Now write out the totals.
            writer.StartHeaderRow();
            writer.StartCell();
            writer.EndCell();
            foreach (var pair in from p in columns orderby p.Key select p)
            {
                BudgetColumn c = pair.Value;
                writer.StartCell();
                writer.WriteNumber(c.Total.ToString("C"));
                writer.EndCell();
            }
            writer.StartCell();
            writer.WriteNumber(totalBalance.ToString("C"));
            writer.EndCell();

            writer.EndRow();

            writer.EndTable();

            writer.WriteParagraph("Generated on " + DateTime.Today.ToLongDateString(), System.Windows.FontStyles.Italic, System.Windows.FontWeights.Normal, System.Windows.Media.Brushes.Gray);
        }