summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-16 05:05:23 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-16 05:05:23 -0400
commit41c33a244210e07e47fbbaa81aaf3b1630fbd1be (patch)
tree68b65a5aa49e60d17d5fbbe9e6119aeffc22ebb0
parent660c40a6d3f086d0904b755409bf84681f3034d6 (diff)
downloadfork-ledger-41c33a244210e07e47fbbaa81aaf3b1630fbd1be.tar.gz
fork-ledger-41c33a244210e07e47fbbaa81aaf3b1630fbd1be.tar.bz2
fork-ledger-41c33a244210e07e47fbbaa81aaf3b1630fbd1be.zip
Restored --cleared, --pending, --uncleared, -X and -Y.
-rw-r--r--src/entry.cc39
-rw-r--r--src/report.cc35
-rw-r--r--src/report.h23
-rw-r--r--src/xact.cc35
-rw-r--r--src/xact.h2
5 files changed, 112 insertions, 22 deletions
diff --git a/src/entry.cc b/src/entry.cc
index 4847e38c..fb90dfa9 100644
--- a/src/entry.cc
+++ b/src/entry.cc
@@ -356,7 +356,9 @@ bool entry_t::get_state(xact_t::state_t * state) const
bool hetero = false;
foreach (xact_t * xact, xacts) {
- if (first) {
+ if (first ||
+ xact->state == xact_t::CLEARED ||
+ (xact->state == xact_t::PENDING && *state == xact_t::UNCLEARED)) {
*state = xact->state;
first = false;
}
@@ -380,6 +382,22 @@ namespace {
return entry.date();
}
+ value_t get_status(entry_t& entry) {
+ xact_t::state_t status;
+ entry.get_state(&status);
+ return long(status);
+ }
+ value_t get_cleared(entry_t& entry) {
+ xact_t::state_t status;
+ entry.get_state(&status);
+ return status == xact_t::CLEARED;
+ }
+ value_t get_pending(entry_t& entry) {
+ xact_t::state_t status;
+ entry.get_state(&status);
+ return status == xact_t::PENDING;
+ }
+
value_t get_code(entry_t& entry) {
if (entry.code)
return string_value(*entry.code);
@@ -403,6 +421,8 @@ expr_t::ptr_op_t entry_t::lookup(const string& name)
case 'c':
if (name == "code")
return WRAP_FUNCTOR(get_wrapper<&get_code>);
+ else if (name == "cleared")
+ return WRAP_FUNCTOR(get_wrapper<&get_cleared>);
break;
case 'd':
@@ -424,6 +444,23 @@ expr_t::ptr_op_t entry_t::lookup(const string& name)
case 'p':
if (name[1] == '\0' || name == "payee")
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
+ else if (name == "pending")
+ return WRAP_FUNCTOR(get_wrapper<&get_pending>);
+ break;
+
+ case 'u':
+ if (name == "uncleared")
+ return expr_t::op_t::wrap_value(1L);
+ break;
+
+ case 'X':
+ if (name[1] == '\0')
+ return WRAP_FUNCTOR(get_wrapper<&get_cleared>);
+ break;
+
+ case 'Y':
+ if (name[1] == '\0')
+ return WRAP_FUNCTOR(get_wrapper<&get_pending>);
break;
}
diff --git a/src/report.cc b/src/report.cc
index db5dd04c..f706ea78 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -320,8 +320,12 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break;
case 'c':
- if (std::strcmp(p, "collapse") == 0)
+ if (! *(p + 1) || std::strcmp(p, "current") == 0)
+ return MAKE_FUNCTOR(report_t::option_current);
+ else if (std::strcmp(p, "collapse") == 0)
return MAKE_FUNCTOR(report_t::option_collapse);
+ else if (std::strcmp(p, "cleared") == 0)
+ return MAKE_FUNCTOR(report_t::option_cleared);
else if (std::strcmp(p, "comm-as-payee") == 0)
return MAKE_FUNCTOR(report_t::option_comm_as_payee);
else if (std::strcmp(p, "code-as-payee") == 0)
@@ -361,7 +365,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break;
case 'j':
- if (! (*p + 1))
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_amount_data);
break;
@@ -423,6 +427,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_tail_);
break;
+ case 'u':
+ if (std::strcmp(p, "uncleared") == 0)
+ return MAKE_FUNCTOR(report_t::option_uncleared);
+ break;
+
case 'w':
if (std::strcmp(p, "weekly") == 0)
return MAKE_FUNCTOR(report_t::option_weekly);
@@ -440,8 +449,13 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_date_format_);
break;
+ case 'C':
+ if (! *(p + 1))
+ return MAKE_FUNCTOR(report_t::option_cleared);
+ break;
+
case 'E':
- if (std::strcmp(p, "E") == 0)
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_empty);
break;
@@ -451,17 +465,17 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
break;
case 'J':
- if (! (*p + 1))
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_total_data);
break;
case 'M':
- if (std::strcmp(p, "M") == 0)
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_monthly);
break;
case 'P':
- if (std::strcmp(p, "P") == 0)
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_by_payee);
break;
@@ -475,13 +489,18 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
return MAKE_FUNCTOR(report_t::option_total_);
break;
+ case 'U':
+ if (! *(p + 1))
+ return MAKE_FUNCTOR(report_t::option_uncleared);
+ break;
+
case 'W':
- if (std::strcmp(p, "W") == 0)
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_weekly);
break;
case 'Y':
- if (std::strcmp(p, "Y") == 0)
+ if (! *(p + 1))
return MAKE_FUNCTOR(report_t::option_yearly);
break;
}
diff --git a/src/report.h b/src/report.h
index 9c483c76..6c1049bb 100644
--- a/src/report.h
+++ b/src/report.h
@@ -294,25 +294,28 @@ public:
return true;
}
-#if 0
value_t option_current(call_scope_t& args) { // c
- if (! report->predicate.empty())
- report->predicate += "&";
- report->predicate += "d<=m";
+ if (! predicate.empty())
+ predicate += "&";
+ predicate += "date<=now";
+ return true;
}
value_t option_cleared(call_scope_t& args) { // C
- if (! report->predicate.empty())
- report->predicate += "&";
- report->predicate += "X";
+ if (! predicate.empty())
+ predicate += "&";
+ predicate += "cleared";
+ return true;
}
value_t option_uncleared(call_scope_t& args) { // U
- if (! report->predicate.empty())
- report->predicate += "&";
- report->predicate += "!X";
+ if (! predicate.empty())
+ predicate += "&";
+ predicate += "!cleared";
+ return true;
}
+#if 0
value_t option_real(call_scope_t& args) { // R
if (! report->predicate.empty())
report->predicate += "&";
diff --git a/src/xact.cc b/src/xact.cc
index efb33444..2357de8e 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -85,6 +85,22 @@ namespace {
return string_value(empty_string);
}
+ value_t get_status(xact_t& xact) {
+ xact_t::state_t status;
+ xact.entry->get_state(&status);
+ return long(status);
+ }
+ value_t get_cleared(xact_t& xact) {
+ xact_t::state_t status;
+ xact.entry->get_state(&status);
+ return status == xact_t::CLEARED;
+ }
+ value_t get_pending(xact_t& xact) {
+ xact_t::state_t status;
+ xact.entry->get_state(&status);
+ return status == xact_t::PENDING;
+ }
+
value_t get_payee(xact_t& xact) {
return string_value(xact.entry->payee);
}
@@ -173,7 +189,7 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
case 'c':
if (name == "cleared")
- return expr_t::op_t::wrap_value(0L);
+ return WRAP_FUNCTOR(get_wrapper<&get_cleared>);
else if (name == "code")
return WRAP_FUNCTOR(get_wrapper<&get_code>);
break;
@@ -198,11 +214,16 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
case 'p':
if (name == "pending")
- return expr_t::op_t::wrap_value(2L);
+ return WRAP_FUNCTOR(get_wrapper<&get_pending>);
else if (name == "payee")
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
break;
+ case 's':
+ if (name == "status")
+ return WRAP_FUNCTOR(get_wrapper<&get_status>);
+ break;
+
case 't':
if (name[1] == '\0' || name == "total")
return WRAP_FUNCTOR(get_wrapper<&get_total>);
@@ -212,6 +233,16 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
if (name == "uncleared")
return expr_t::op_t::wrap_value(1L);
break;
+
+ case 'X':
+ if (name[1] == '\0')
+ return WRAP_FUNCTOR(get_wrapper<&get_cleared>);
+ break;
+
+ case 'Y':
+ if (name[1] == '\0')
+ return WRAP_FUNCTOR(get_wrapper<&get_pending>);
+ break;
}
return entry->lookup(name);
}
diff --git a/src/xact.h b/src/xact.h
index 70d411ed..91630481 100644
--- a/src/xact.h
+++ b/src/xact.h
@@ -55,7 +55,7 @@ public:
#define XACT_GENERATED 0x0020 // transaction was not found in a journal
#define XACT_TEMP 0x0040 // transaction is a temporary object
- enum state_t { UNCLEARED, CLEARED, PENDING };
+ enum state_t { UNCLEARED = 0, CLEARED, PENDING };
entry_t * entry;
account_t * account;