summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-05-07 01:53:53 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-05-07 01:53:53 -0500
commitc0fa144ca586bfc3d48d7f2512bb90ebdde148df (patch)
tree98e03564cf1e4297723edf5d7576290baa12df2b
parent6a0daf634fa76ba61ea79e55e4d3f213aa27e306 (diff)
downloadfork-ledger-c0fa144ca586bfc3d48d7f2512bb90ebdde148df.tar.gz
fork-ledger-c0fa144ca586bfc3d48d7f2512bb90ebdde148df.tar.bz2
fork-ledger-c0fa144ca586bfc3d48d7f2512bb90ebdde148df.zip
Added "last_checkout_cleared" valexpr variable
-rw-r--r--src/account.cc10
-rw-r--r--src/account.h1
-rw-r--r--src/textual.cc8
-rw-r--r--src/timelog.cc2
-rw-r--r--src/timelog.h15
5 files changed, 24 insertions, 12 deletions
diff --git a/src/account.cc b/src/account.cc
index 206e2350..1ea13330 100644
--- a/src/account.cc
+++ b/src/account.cc
@@ -309,6 +309,10 @@ namespace {
return (! account.self_details().latest_checkout.is_not_a_date_time() ?
value_t(account.self_details().latest_checkout) : NULL_VALUE);
}
+ value_t get_latest_checkout_cleared(account_t& account)
+ {
+ return account.self_details().latest_checkout_cleared;
+ }
template <value_t (*Func)(account_t&)>
value_t get_wrapper(call_scope_t& args) {
@@ -405,6 +409,8 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
return WRAP_FUNCTOR(get_wrapper<&get_latest>);
else if (fn_name == "latest_checkout")
return WRAP_FUNCTOR(get_wrapper<&get_latest_checkout>);
+ else if (fn_name == "latest_checkout_cleared")
+ return WRAP_FUNCTOR(get_wrapper<&get_latest_checkout_cleared>);
break;
case 'n':
@@ -662,8 +668,10 @@ void account_t::xdata_t::details_t::update(post_t& post,
earliest_checkin = *post.checkin;
if (post.checkout && (latest_checkout.is_not_a_date_time() ||
- *post.checkout > latest_checkout))
+ *post.checkout > latest_checkout)) {
latest_checkout = *post.checkout;
+ latest_checkout_cleared = post.state() == item_t::CLEARED;
+ }
if (post.state() == item_t::CLEARED) {
posts_cleared_count++;
diff --git a/src/account.h b/src/account.h
index 2aa3f2eb..b751cb0b 100644
--- a/src/account.h
+++ b/src/account.h
@@ -183,6 +183,7 @@ public:
datetime_t earliest_checkin;
datetime_t latest_checkout;
+ bool latest_checkout_cleared;
std::set<path> filenames;
std::set<string> accounts_referenced;
diff --git a/src/textual.cc b/src/textual.cc
index d0e4dad2..011e45b7 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -431,7 +431,7 @@ void instance_t::read_next_directive(bool& error_flag)
#if defined(TIMELOG_SUPPORT)
-void instance_t::clock_in_directive(char * line, bool /*capitalized*/)
+void instance_t::clock_in_directive(char * line, bool capitalized)
{
string datetime(line, 2, 19);
@@ -452,7 +452,7 @@ void instance_t::clock_in_directive(char * line, bool /*capitalized*/)
position.end_line = context.linenum;
position.sequence = context.sequence++;
- time_xact_t event(position, parse_datetime(datetime),
+ time_xact_t event(position, parse_datetime(datetime), capitalized,
p ? top_account()->find_account(p) : NULL,
n ? n : "",
end ? end : "");
@@ -460,7 +460,7 @@ void instance_t::clock_in_directive(char * line, bool /*capitalized*/)
timelog.clock_in(event);
}
-void instance_t::clock_out_directive(char * line, bool /*capitalized*/)
+void instance_t::clock_out_directive(char * line, bool capitalized)
{
string datetime(line, 2, 19);
@@ -481,7 +481,7 @@ void instance_t::clock_out_directive(char * line, bool /*capitalized*/)
position.end_line = context.linenum;
position.sequence = context.sequence++;
- time_xact_t event(position, parse_datetime(datetime),
+ time_xact_t event(position, parse_datetime(datetime), capitalized,
p ? top_account()->find_account(p) : NULL,
n ? n : "",
end ? end : "");
diff --git a/src/timelog.cc b/src/timelog.cc
index e84e4188..9516ba17 100644
--- a/src/timelog.cc
+++ b/src/timelog.cc
@@ -62,7 +62,7 @@ namespace {
VERIFY(amt.valid());
post_t * post = new post_t(in_event.account, amt, POST_VIRTUAL);
- post->set_state(item_t::CLEARED);
+ post->set_state(out_event.completed ? item_t::CLEARED : item_t::UNCLEARED);
post->pos = in_event.position;
post->checkin = in_event.checkin;
post->checkout = out_event.checkin;
diff --git a/src/timelog.h b/src/timelog.h
index 857952ff..a902c084 100644
--- a/src/timelog.h
+++ b/src/timelog.h
@@ -56,6 +56,7 @@ class time_xact_t
{
public:
datetime_t checkin;
+ bool completed;
account_t * account;
string desc;
string note;
@@ -66,16 +67,18 @@ public:
}
time_xact_t(const optional<position_t>& _position,
const datetime_t& _checkin,
- account_t * _account = NULL,
- const string& _desc = "",
- const string& _note = "")
- : checkin(_checkin), account(_account), desc(_desc), note(_note),
+ const bool _completed = false,
+ account_t * _account = NULL,
+ const string& _desc = "",
+ const string& _note = "")
+ : checkin(_checkin), completed(_completed), account(_account),
+ desc(_desc), note(_note),
position(_position ? *_position : position_t()) {
TRACE_CTOR(time_xact_t,
- "position_t, datetime_t, account_t *, string, string");
+ "position_t, datetime_t, bool, account_t *, string, string");
}
time_xact_t(const time_xact_t& xact)
- : checkin(xact.checkin), account(xact.account),
+ : checkin(xact.checkin), completed(xact.completed), account(xact.account),
desc(xact.desc), note(xact.note), position(xact.position) {
TRACE_CTOR(time_xact_t, "copy");
}