Ejemplo n.º 1
0
 public W2Report(FlowDocumentView view, MyMoney money, IServiceProvider sp)
 {
     this.myMoney                   = money;
     this.year                      = DateTime.Now.Year;
     this.view                      = view;
     this.serviceProvider           = sp;
     view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
     this.taxCategories             = new TaxCategoryCollection();
 }
Ejemplo n.º 2
0
 public W2Report(FlowDocumentView view, MyMoney money, IServiceProvider sp, int fiscalYearStart)
 {
     this.myMoney         = money;
     this.fiscalYearStart = fiscalYearStart;
     SetStartDate(DateTime.Now.Year);
     this.view                      = view;
     this.serviceProvider           = sp;
     view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
     this.taxCategories             = new TaxCategoryCollection();
 }
Ejemplo n.º 3
0
        private void GenerateCategories(IReportWriter writer)
        {
            TaxCategoryCollection taxCategories = new TaxCategoryCollection();
            List <TaxCategory>    list          = taxCategories.GenerateGroups(money, year);

            if (list == null)
            {
                writer.WriteParagraph("You have not associated any categories with tax categories.");
                writer.WriteParagraph("Please use the Category Properties dialog to associate tax categories then try again.");
                return;
            }

            writer.WriteHeading("Tax Categories");
            writer.StartTable();

            writer.StartColumnDefinitions();
            writer.WriteColumnDefinition("auto", 100, double.MaxValue);
            writer.WriteColumnDefinition("auto", 100, double.MaxValue);
            writer.EndColumnDefinitions();
            writer.StartHeaderRow();
            writer.StartCell();
            writer.WriteParagraph("Category");
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber("Amount");
            writer.EndCell();
            writer.EndRow();

            decimal tax = GetSalesTax();

            writer.StartRow();
            writer.StartCell();
            writer.WriteParagraph("Sales Tax");
            writer.EndCell();
            writer.StartCell();
            writer.WriteNumber(tax.ToString("C"), FontStyles.Normal, FontWeights.Bold, null);
            writer.EndCell();
            writer.EndRow();

            foreach (TaxCategory tc in list)
            {
                writer.StartHeaderRow();
                writer.StartCell();
                writer.WriteParagraph(tc.Name);
                writer.EndCell();
                writer.StartCell();
                writer.EndCell();
                writer.EndRow();

                decimal sum = 0;
                IDictionary <string, List <Transaction> > groups = tc.Groups;
                foreach (KeyValuePair <string, List <Transaction> > subtotal in groups)
                {
                    writer.StartRow();
                    writer.StartCell();
                    writer.WriteParagraph(subtotal.Key);
                    writer.EndCell();
                    writer.StartCell();

                    decimal value = (from t in subtotal.Value select t.Amount).Sum();

                    if (tc.DefaultSign < 0)
                    {
                        value = value * -1;
                    }

                    writer.WriteNumber(value.ToString("C"));
                    writer.EndCell();
                    writer.EndRow();
                    sum += value;
                }

                writer.StartRow();
                writer.StartCell();
                writer.EndCell();
                writer.StartCell();
                writer.WriteNumber(sum.ToString("C"), FontStyles.Normal, FontWeights.Bold, null);
                writer.EndCell();
                writer.EndRow();
            }

            writer.EndTable();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Populate the "Groups" property on the tax categories that are in use in the given year.
        /// </summary>
        public List <TaxCategory> GenerateGroups(MyMoney money, int year)
        {
            List <TaxCategory>    result                   = new List <TaxCategory>();
            TaxCategoryCollection taxCategories            = new TaxCategoryCollection();
            Dictionary <TaxCategory, List <Category> > map = new Dictionary <TaxCategory, List <Category> >();

            // find out if we have any tax related categories...
            foreach (Category c in money.Categories.GetCategories())
            {
                if (c.TaxRefNum != 0)
                {
                    TaxCategory tc = taxCategories.Find(c.TaxRefNum);
                    if (tc != null)
                    {
                        List <Category> list = null;
                        if (!map.TryGetValue(tc, out list))
                        {
                            map[tc] = list = new List <Category>();
                        }
                        list.Add(c);
                    }
                }
            }

            if (map.Count == 0)
            {
                return(null);
            }

            foreach (KeyValuePair <TaxCategory, List <Category> > pair in map)
            {
                TaxCategory     tc   = pair.Key;
                List <Category> list = pair.Value;

                SortedDictionary <string, List <Transaction> > groups = new SortedDictionary <string, List <Transaction> >();

                foreach (Category c in list)
                {
                    // don't allow child categories, require exact category match.
                    var rows = money.Transactions.GetTransactionsByCategory(c, null, (cat) => { return(c == cat); });
                    foreach (Transaction t in rows)
                    {
                        if (t.Date.Year != year)
                        {
                            continue;
                        }
                        if (t.Account.IsTaxDeferred)
                        {
                            continue;
                        }

                        string group = null;

                        switch (tc.SortOrder)
                        {
                        case SortOrder.SortByAsset:
                            group = t.Account.Name;
                            break;

                        case SortOrder.SortByCategory:
                            group = c.Name;
                            break;

                        case SortOrder.None:
                        case SortOrder.SortByPayee:
                            group = t.PayeeName;
                            break;
                        }

                        if (!string.IsNullOrEmpty(group))
                        {
                            List <Transaction> tlist = null;
                            if (!groups.TryGetValue(group, out tlist))
                            {
                                groups[group] = tlist = new List <Transaction>();
                            }
                            tlist.Add(t);
                        }
                    }
                }

                if (groups.Count > 0)
                {
                    tc.Groups = groups;
                    result.Add(tc);
                }
            }

            return(result);
        }