From 50f434a5e341e69edadae2929b53414b2d4de9f2 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Feb 2009 05:55:09 -0400 Subject: Generate null transactions for empty periods For example, if one uses -M to generate a monthly report for an entire year, and there are no transaction in the month of February, ordinarily Ledger would report nothing for that month, even if -E were used. Now "null transactions" are generated for periods without any activity, in order to make certain reports -- such as running monthly averages -- more accurate. For example, instead of -MA being just a monthly running average of months with activity, it is now a true average among all months during the reported period. --- src/filters.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/filters.cc b/src/filters.cc index d5c8f177..ca6397a8 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -488,7 +488,23 @@ void interval_xacts::operator()(xact_t& xact) while (date >= (temp = interval.increment(quant))) { if (quant == temp) break; + interval.begin = quant; quant = temp; + + // Generate a null transaction, so the intervening periods can be seen + // when -E is used, or if the calculated amount ends up being non-zero + account_t empty_account(NULL, ""); + entry_t null_entry; + null_entry.add_flags(ITEM_TEMP); + null_entry._date = quant; + xact_t null_xact(&empty_account); + null_xact.add_flags(ITEM_TEMP); + null_xact.amount = 0L; + null_entry.add_xact(&null_xact); + + last_xact = &null_xact; + subtotal_xacts::operator()(null_xact); + report_subtotal(quant); } start = interval.begin = quant; } -- cgit v1.2.3