Beispiel #1
0
        private void GenerateGroup(IReportWriter writer, Dictionary <Category, CashFlowColumns> columns, CashFlowColumns columnTotals, string groupName, Func <Category, bool> inGroup)
        {
            List <Category> rootCategories = new List <Category>(columns.Keys);

            rootCategories.Sort(new Comparison <Category>((a, b) =>
            {
                return(string.Compare(GetCategoryCaption(a), GetCategoryCaption(b)));
            }));

            // start the group
            writer.StartExpandableRowGroup();

            CashFlowColumns groupTotals = new CashFlowColumns();

            // compute group totals;
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    foreach (string columnName in this.columns)
                    {
                        CashFlowColumns cc     = columns[c];
                        decimal         amount = cc.GetValue(columnName);
                        columnTotals.AddValue(columnName, null, amount);
                        groupTotals.AddValue(columnName, null, amount);
                    }
                }
            }

            WriteRow(writer, true, false, groupName, FormatValues(groupTotals.GetOrderedValues(this.columns)).ToArray());

            // now add the detail rows of the group
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    List <CashFlowCell> cells = new List <CashFlowCell>();
                    CashFlowColumns     cc    = columns[c];

                    foreach (string columnName in this.columns)
                    {
                        CashFlowCell cell = cc.GetCell(columnName);
                        cells.Add(cell);
                    }

                    WriteRow(writer, false, false, GetCategoryCaption(c), cells);
                }
            }

            writer.EndExpandableRowGroup();
        }
Beispiel #2
0
        private void GenerateCsvGroup(StreamWriter writer, Dictionary <Category, CashFlowColumns> byCategory, string groupTitle, Func <Category, bool> inGroup, Func <decimal, decimal> scaleFunc)
        {
            writer.Write(groupTitle);
            foreach (string columnName in this.columns)
            {
                writer.Write(",");
                writer.Write(columnName);
            }
            writer.WriteLine();

            List <Category> rootCategories = new List <Category>(byCategory.Keys);

            rootCategories.Sort(new Comparison <Category>((a, b) =>
            {
                return(string.Compare(GetCategoryCaption(a), GetCategoryCaption(b)));
            }));

            // now add the detail rows of the group
            foreach (Category c in rootCategories)
            {
                if (inGroup(c))
                {
                    List <CashFlowCell> cells = new List <CashFlowCell>();
                    CashFlowColumns     cc    = byCategory[c];

                    foreach (string columnName in this.columns)
                    {
                        CashFlowCell cell = cc.GetCell(columnName);
                        cells.Add(cell);
                    }

                    writer.Write(GetCategoryCaption(c));

                    foreach (CashFlowCell cell in cells)
                    {
                        writer.Write(",");
                        writer.Write(scaleFunc(cell.Value));
                    }
                    writer.WriteLine();
                }
            }
            writer.WriteLine();
        }
Beispiel #3
0
 private void TallyCategory(Transaction t, Category c, Transaction data, string columnName, decimal amount)
 {
     // let the category bubble up as high as it can go while not flipping from income to expense.
     // For example: the category "Investments" might contain sub-categories of type income (Investments:Dividends)
     // and expenses (like Investments:Fees).
     if (c.ParentCategory == null || (c.Type != CategoryType.None && c.Type != c.ParentCategory.Type))
     {
         CashFlowColumns columns = null;
         byCategory.TryGetValue(c, out columns);
         if (columns == null)
         {
             columns       = new CashFlowColumns();
             byCategory[c] = columns;
         }
         columns.AddValue(columnName, data, t.CurrencyNormalizedAmount(amount));
     }
     else
     {
         TallyCategory(t, c.ParentCategory, data, columnName, amount);
     }
 }
Beispiel #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);
        }
Beispiel #5
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);
        }