Пример #1
0
        public TaxForm FindForm(string name)
        {
            TaxForm f = null;

            forms.TryGetValue(name, out f);
            return(f);
        }
Пример #2
0
        bool GenerateForm(TaxForm form, IReportWriter writer, ICollection <Transaction> transactions)
        {
            var byCategory = new Dictionary <Category, decimal>();

            // could be one to many mapping.
            Dictionary <TaxCategory, List <Category> > map = new Dictionary <TaxCategory, List <Category> >();

            // find our matching category
            foreach (TaxCategory tc in form.Categories)
            {
                foreach (Category c in this.myMoney.Categories.GetCategories())
                {
                    if (c.TaxRefNum == tc.RefNum)
                    {
                        byCategory[c] = 0M;

                        List <Category> list = null;
                        if (!map.TryGetValue(tc, out list))
                        {
                            list    = new List <Category>();
                            map[tc] = list;
                        }
                        list.Add(c);
                    }
                }
            }

            bool found = false;

            // summarize the year.
            foreach (Transaction t in transactions)
            {
                if (t.Date.Year == this.year)
                {
                    found |= Summarize(byCategory, t);
                }
            }

            if (!found)
            {
                return(false);
            }

            writer.WriteHeading("Form " + form.Name);


            writer.StartTable();
            writer.StartColumnDefinitions();
            writer.WriteColumnDefinition("20", 20, 20);    // expander column
            writer.WriteColumnDefinition("300", 300, 300); // row category name
            writer.WriteColumnDefinition("100", 100, 00);  // row value
            writer.EndColumnDefinitions();

            foreach (TaxCategory tc in form.Categories)
            {
                List <Category> list = null;
                if (map.TryGetValue(tc, out list))
                {
                    if (list.Count > 1)
                    {
                        decimal total = 0;
                        foreach (Category c in list)
                        {
                            total += byCategory[c];
                        }
                        if (total != 0)
                        {
                            writer.StartExpandableRowGroup();

                            // header row for the total.
                            writer.StartRow();
                            writer.StartCell();
                            writer.WriteParagraph(tc.Name);
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteNumber(total.ToString("N0"));
                            writer.EndCell();
                            writer.EndRow();

                            foreach (Category c in list)
                            {
                                decimal v = byCategory[c];
                                if (v != 0)
                                {
                                    writer.StartRow();
                                    writer.StartCell();
                                    writer.WriteParagraph("    " + c.GetFullName());
                                    writer.EndCell();
                                    writer.StartCell();
                                    writer.WriteNumber(v.ToString("N0"));
                                    AddHyperlink(c, writer);
                                    writer.EndCell();
                                    writer.EndRow();
                                }
                            }

                            writer.EndExpandableRowGroup();
                        }
                    }
                    else if (list.Count == 1)
                    {
                        Category c = list[0];
                        decimal  v = byCategory[c];
                        if (v != 0)
                        {
                            writer.StartRow();
                            writer.StartCell(); // null expander
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteParagraph(tc.Name);
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteNumber(v.ToString("N0"));
                            AddHyperlink(c, writer);
                            writer.EndCell();
                            writer.EndRow();
                        }
                    }
                }
            }
            writer.EndTable();

            return(true);
        }
Пример #3
0
        bool GenerateForm(TaxForm form, IReportWriter writer, ICollection <Transaction> transactions)
        {
            var byCategory = new Dictionary <Category, decimal>();

            // could be one to many mapping.
            Dictionary <TaxCategory, List <Category> > map = new Dictionary <TaxCategory, List <Category> >();

            // find our matching category
            foreach (TaxCategory tc in form.Categories)
            {
                foreach (Category c in this.myMoney.Categories.GetCategories())
                {
                    if (c.TaxRefNum == tc.RefNum)
                    {
                        byCategory[c] = 0M;

                        List <Category> list = null;
                        if (!map.TryGetValue(tc, out list))
                        {
                            list    = new List <Category>();
                            map[tc] = list;
                        }
                        list.Add(c);
                    }
                }
            }

            bool found = false;

            // summarize the year.
            foreach (Transaction t in transactions)
            {
                if (t.Transfer != null || t.IsDeleted || t.Status == TransactionStatus.Void)
                {
                    continue;
                }
                bool include = t.Date >= this.startDate && t.Date < this.endDate;
                var  extra   = myMoney.TransactionExtras.FindByTransaction(t.Id);
                if (extra != null && extra.TaxYear != -1)
                {
                    var taxYearStartDate = new DateTime(extra.TaxYear, fiscalYearStart + 1, 1);
                    if (fiscalYearStart > 0)
                    {
                        // Note: "FY2020" means July 2019 to July 2020, in other words
                        // it is the end date that represents the year.
                        taxYearStartDate = taxYearStartDate.AddYears(-1);
                    }
                    var taxYearEndDate = taxYearStartDate.AddYears(1);
                    include = taxYearStartDate >= this.startDate && taxYearEndDate <= this.endDate;
                }
                if (include)
                {
                    found |= Summarize(byCategory, t);
                }
            }

            if (!found)
            {
                return(false);
            }

            writer.WriteHeading("Form " + form.Name);


            writer.StartTable();
            writer.StartColumnDefinitions();
            writer.WriteColumnDefinition("20", 20, 20);    // expander column
            writer.WriteColumnDefinition("300", 300, 300); // row category name
            writer.WriteColumnDefinition("100", 100, 00);  // row value
            writer.EndColumnDefinitions();

            foreach (TaxCategory tc in form.Categories)
            {
                List <Category> list = null;
                if (map.TryGetValue(tc, out list))
                {
                    if (list.Count > 1)
                    {
                        decimal total = 0;
                        foreach (Category c in list)
                        {
                            total += byCategory[c];
                        }
                        if (total != 0)
                        {
                            writer.StartExpandableRowGroup();

                            // header row for the total.
                            writer.StartRow();
                            writer.StartCell();
                            writer.WriteParagraph(tc.Name);
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteNumber(total.ToString("N0"));
                            writer.EndCell();
                            writer.EndRow();

                            foreach (Category c in list)
                            {
                                decimal v = byCategory[c];
                                if (v != 0)
                                {
                                    writer.StartRow();
                                    writer.StartCell();
                                    writer.WriteParagraph("    " + c.GetFullName());
                                    writer.EndCell();
                                    writer.StartCell();
                                    writer.WriteNumber(v.ToString("N0"));
                                    AddHyperlink(c, writer);
                                    writer.EndCell();
                                    writer.EndRow();
                                }
                            }

                            writer.EndExpandableRowGroup();
                        }
                    }
                    else if (list.Count == 1)
                    {
                        Category c = list[0];
                        decimal  v = byCategory[c];
                        if (v != 0)
                        {
                            writer.StartRow();
                            writer.StartCell(); // null expander
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteParagraph(tc.Name);
                            writer.EndCell();
                            writer.StartCell();
                            writer.WriteNumber(v.ToString("N0"));
                            AddHyperlink(c, writer);
                            writer.EndCell();
                            writer.EndRow();
                        }
                    }
                }
            }
            writer.EndTable();

            return(true);
        }
Пример #4
0
        private void Load()
        {
            if (forms == null)
            {
                forms = new Dictionary <string, TaxForm>();
                byRef = new Dictionary <int, TaxCategory>();

                TaxForm form    = null;
                bool    started = false;
                string  spec    = ProcessHelper.GetEmbeddedResource("Walkabout.Taxes.TxfSpec.txt");
                using (StringReader reader = new StringReader(spec))
                {
                    int    linenumber = 0;
                    string line       = reader.ReadLine();
                    while (line != null)
                    {
                        linenumber++;
                        if (!started && line.StartsWith(TableStartMarker))
                        {
                            started = true;
                        }
                        else if (started && line.StartsWith(TableEndMarker))
                        {
                            break;
                        }
                        else if (started)
                        {
                            // ok, we have a line to parse.
                            TaxCategory c = TaxCategory.Parse(line);
                            if (c != null)
                            {
                                if (c.Level == 0)
                                {
                                    form = new TaxForm()
                                    {
                                        Name       = c.Name,
                                        Categories = new List <TaxCategory>()
                                    };
                                    forms[c.Name] = form;
                                }
                                else
                                {
                                    if (form != null)
                                    {
                                        c.Form = form;
                                        form.Categories.Add(c);
                                    }
                                    if (c.RefNum != 0)
                                    {
                                        byRef[c.RefNum] = c;
                                    }
                                }
                            }
                        }
                        line = reader.ReadLine();
                    }
                }
            }

            // now outside of this cache, we need to load the cached values into our collection.
            foreach (var tc in byRef.Values)
            {
                Add(tc);
            }
        }