示例#1
0
        protected override void ProcessAccount(GncAccount acct, int depth)
        {
            var intervalTotal = new GncMultiAmount();
            int intervalDays = 0, intervalCount = 0;
            var earliest = acct.Book.EarliestDate;
            var latest = acct.Book.LatestDate;
            foreach (var interval in EnumIntervals())
            {
                var tot = ConvertTo == null ? acct.GetTotalWithSubaccounts(interval) : acct.GetTotalConverted(interval, true, ConvertTo);
                if (Negate)
                    tot.NegateInplace();
                // Count only the full months for the purpose of averaging
                if (interval.Start >= earliest && interval.End <= latest)
                {
                    intervalTotal.AddInplace(tot);
                    intervalCount++;
                    intervalDays += (int) (interval.End - interval.Start).TotalDays + 1;
                }

                SetReportAmount(Report, acct, interval, tot, ConvertTo != null, "/Trns?Acct={0}&Fr={1}&To={2}{3}".Fmt(
                            acct.Path(":").UrlEscape(),
                            interval.Start.Date.ToIsoStringOptimal(),
                            interval.End.Date.ToIsoStringOptimal(),
                            acct.EnumChildren().Any() ? "&SubAccts=true" : ""));
            }

            if (intervalCount > 1)
            {
                if (!Report.ContainsCol("average"))
                    Report.AddCol("average", Tr.PgMonthlyTotals.ColAverage, "aw-col-average");
                intervalTotal.MultiplyInplace(30.43m / intervalDays); // daily average * days in month
                SetReportAmount(Report, acct, "average", intervalTotal, ConvertTo != null);
            }
        }
示例#2
0
        public static object FormatCcys(GncMultiAmount amount, bool isConverted, bool whole)
        {
            string stringify(decimal amt, bool whole2)
            {
                if (!whole2)
                {
                    return($"{amt:#,0.00}");
                }

                if (amt > 0 && amt < 1m)
                {
                    amt = 1m;
                }
                else if (amt < 0 && amt > -1m)
                {
                    amt = -1m;
                }
                return($"{amt:#,0}");
            }

            if (isConverted)
            {
                return(stringify(amount.Single().Quantity, amount.Single().Commodity.Identifier == "UAH" ? true : whole));
            }

            var result = new List <object>();

            foreach (var amt in amount.Where(a => a.Quantity != 0).OrderByDescending(a => a.Commodity.Identifier)) // because they are typically right-aligned, so the main currency should be the rightmost one
            {
                string str;
                switch (amt.Commodity.Identifier)
                {
                case "GBP": str = "£" + stringify(amt.Quantity, whole); break;

                case "EUR": str = "€" + stringify(amt.Quantity, whole); break;

                case "USD": str = "$" + stringify(amt.Quantity, whole); break;

                case "UAH": str = stringify(amt.Quantity, true) + " грн"; break;

                default: str = amt.Commodity.Identifier + " " + stringify(amt.Quantity, whole); break;
                }
                result.Add(new SPAN(str)
                {
                    class_ = "ccy_" + amt.Commodity.Identifier.Replace(":", "_")
                });
            }
            return(result.InsertBetween(" "));
        }
示例#3
0
 public object FmtCcy(GncMultiAmount amount, bool whole = false, bool isConverted = false)
 {
     return(WebPage.FormatCcys(amount, isConverted, whole));
 }
示例#4
0
 protected static void SetReportAmount(ReportAccounts report, GncAccount acct, object colref, GncMultiAmount amount, bool isConverted, string url = null)
 {
     if (amount.Count == 0)
     {
         report.SetValue(acct, colref, "-", ReportTable.CssClassNumber(0));
     }
     else
     {
         var val = FormatCcys(amount, isConverted, whole: true);
         report.SetValue(acct, colref, url == null ? val : new A(val)
         {
             href = url
         },
                         isConverted ? ReportTable.CssClassNumber(amount.Single().Quantity) : "");
     }
 }