summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-15 20:59:13 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-15 20:59:13 -0400
commitbfa6a643a1317515e10cca2170463f941e6d0f10 (patch)
treeefb252f89017778e84b0960be979528ad1a8a3ae /src
parent78e57ac4cfe60147051f0a04e82c19174a86f899 (diff)
downloadfork-ledger-bfa6a643a1317515e10cca2170463f941e6d0f10.tar.gz
fork-ledger-bfa6a643a1317515e10cca2170463f941e6d0f10.tar.bz2
fork-ledger-bfa6a643a1317515e10cca2170463f941e6d0f10.zip
Improved handling of --empty option
For example, in period reports null transactions are only generated for empty periods if --empty is used. Otherwise, the presence of such transactions can get confusing.
Diffstat (limited to 'src')
-rw-r--r--src/chain.cc3
-rw-r--r--src/filters.cc48
-rw-r--r--src/filters.h16
3 files changed, 36 insertions, 31 deletions
diff --git a/src/chain.cc b/src/chain.cc
index baf92f64..c8cbf673 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -113,7 +113,8 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
if (report.HANDLED(period_)) {
handler.reset(new interval_xacts(handler, expr,
report.HANDLER(period_).str(),
- report.session.master.get()));
+ report.session.master.get(),
+ report.HANDLED(empty)));
handler.reset(new sort_xacts(handler, "date"));
}
diff --git a/src/filters.cc b/src/filters.cc
index fc924065..118e8c5e 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -476,28 +476,29 @@ void interval_xacts::operator()(xact_t& xact)
(is_valid(interval.end) && date >= interval.end))
return;
- if (interval) {
- if (! started) {
- if (! is_valid(interval.begin))
- interval.set_start(date);
- start = interval.begin;
- started = true;
- }
+ if (! started) {
+ if (! is_valid(interval.begin))
+ interval.set_start(date);
+ start = interval.begin;
+ started = true;
+ }
- date_t quant = interval.increment(interval.begin);
- if (date >= quant) {
- if (last_xact)
- report_subtotal(quant);
+ date_t quant = interval.increment(interval.begin);
+ if (date >= quant) {
+ if (last_xact)
+ report_subtotal(quant);
- date_t temp;
- while (date >= (temp = interval.increment(quant))) {
- if (quant == temp)
- break;
- interval.begin = quant;
- quant = temp;
+ date_t temp;
+ 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
+ if (generate_empty_xacts) {
+ // 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
entry_temps.push_back(entry_t());
entry_t& null_entry = entry_temps.back();
null_entry.add_flags(ITEM_TEMP);
@@ -511,16 +512,15 @@ void interval_xacts::operator()(xact_t& xact)
last_xact = &null_xact;
subtotal_xacts::operator()(null_xact);
+
report_subtotal(quant);
}
- start = interval.begin = quant;
}
-
- subtotal_xacts::operator()(xact);
- } else {
- item_handler<xact_t>::operator()(xact);
+ start = interval.begin = quant;
}
+ subtotal_xacts::operator()(xact);
+
last_xact = &xact;
}
diff --git a/src/filters.h b/src/filters.h
index f58080e1..a16f5665 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -498,6 +498,9 @@ public:
*/
class subtotal_xacts : public item_handler<xact_t>
{
+ subtotal_xacts();
+
+protected:
class acct_value_t
{
acct_value_t();
@@ -524,8 +527,6 @@ class subtotal_xacts : public item_handler<xact_t>
typedef std::map<string, acct_value_t> values_map;
typedef std::pair<string, acct_value_t> values_pair;
- subtotal_xacts();
-
protected:
expr_t& amount_expr;
values_map values;
@@ -568,21 +569,24 @@ class interval_xacts : public subtotal_xacts
{
interval_t interval;
xact_t * last_xact;
- bool started;
+ bool started;
std::list<entry_t> entry_temps;
std::list<xact_t> xact_temps;
account_t empty_account;
+ bool generate_empty_xacts;
interval_xacts();
public:
interval_xacts(xact_handler_ptr _handler, expr_t& amount_expr,
- const interval_t& _interval, account_t * master = NULL)
+ const interval_t& _interval, account_t * master = NULL,
+ bool _generate_empty_xacts = false)
: subtotal_xacts(_handler, amount_expr), interval(_interval),
- last_xact(NULL), started(false), empty_account(master, "<Empty>") {
+ last_xact(NULL), started(false), empty_account(master, "<None>"),
+ generate_empty_xacts(_generate_empty_xacts) {
TRACE_CTOR(interval_xacts,
- "xact_handler_ptr, const interval_t&, bool");
+ "xact_handler_ptr, expr_t&, const interval_t&, account_t *, bool");
}
virtual ~interval_xacts() throw() {
TRACE_DTOR(interval_xacts);