diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-11 02:01:34 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-11 02:01:34 -0500 |
commit | ed9209cc2794eeef2a363947ab9b89be83aefe6b (patch) | |
tree | 7a2834e89138a16e792400c20da1d11e1603cab1 /src/timelog.cc | |
parent | a4b1e7c5ab70fc846b0ec4762f2e9f8ee242ca11 (diff) | |
download | fork-ledger-ed9209cc2794eeef2a363947ab9b89be83aefe6b.tar.gz fork-ledger-ed9209cc2794eeef2a363947ab9b89be83aefe6b.tar.bz2 fork-ledger-ed9209cc2794eeef2a363947ab9b89be83aefe6b.zip |
Timeclock events now record their file position
Diffstat (limited to 'src/timelog.cc')
-rw-r--r-- | src/timelog.cc | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/src/timelog.cc b/src/timelog.cc index dc3d3496..b18c436b 100644 --- a/src/timelog.cc +++ b/src/timelog.cc @@ -41,11 +41,8 @@ namespace ledger { namespace { void clock_out_from_timelog(std::list<time_xact_t>& time_xacts, - const datetime_t& when, - account_t * account, - const char * desc, - const char * note, - journal_t& journal) + time_xact_t out_event, + journal_t& journal) { time_xact_t event; @@ -56,7 +53,7 @@ namespace { else if (time_xacts.empty()) { throw parse_error(_("Timelog check-out event without a check-in")); } - else if (! account) { + else if (! out_event.account) { throw parse_error (_("When multiple check-ins are active, checking out requires an account")); } @@ -66,7 +63,7 @@ namespace { for (std::list<time_xact_t>::iterator i = time_xacts.begin(); i != time_xacts.end(); i++) - if (account == (*i).account) { + if (out_event.account == (*i).account) { event = *i; found = true; time_xacts.erase(i); @@ -78,36 +75,37 @@ namespace { (_("Timelog check-out event does not match any current check-ins")); } - if (desc && event.desc.empty()) { - event.desc = desc; - desc = NULL; - } + if (out_event.checkin < event.checkin) + throw parse_error + (_("Timelog check-out date less than corresponding check-in")); - if (note && event.note.empty()) { - event.note = note; - note = NULL; + if (! out_event.desc.empty() && event.desc.empty()) { + event.desc = out_event.desc; + out_event.desc = empty_string; } + if (! out_event.note.empty() && event.note.empty()) + event.note = out_event.note; + std::auto_ptr<xact_t> curr(new xact_t); - curr->_date = when.date(); - curr->code = desc ? desc : ""; + curr->_date = out_event.checkin.date(); + curr->code = out_event.desc; // if it wasn't used above curr->payee = event.desc; + curr->pos = event.position; if (! event.note.empty()) curr->append_note(event.note.c_str()); - if (when < event.checkin) - throw parse_error - (_("Timelog check-out date less than corresponding check-in")); - char buf[32]; - std::sprintf(buf, "%lds", long((when - event.checkin).total_seconds())); + std::sprintf(buf, "%lds", long((out_event.checkin - event.checkin) + .total_seconds())); amount_t amt; amt.parse(buf); VERIFY(amt.valid()); post_t * post = new post_t(event.account, amt, POST_VIRTUAL); post->set_state(item_t::CLEARED); + post->pos = event.position; curr->add_post(post); if (! journal.add_xact(curr.get())) @@ -128,20 +126,16 @@ time_log_t::~time_log_t() accounts.push_back(time_xact.account); foreach (account_t * account, accounts) - clock_out_from_timelog(time_xacts, CURRENT_TIME(), account, - NULL, NULL, journal); + clock_out_from_timelog(time_xacts, + time_xact_t(none, CURRENT_TIME(), account), + journal); assert(time_xacts.empty()); } } -void time_log_t::clock_in(const datetime_t& checkin, - account_t * account, - const string& desc, - const string& note) +void time_log_t::clock_in(time_xact_t event) { - time_xact_t event(checkin, account, desc, note); - if (! time_xacts.empty()) { foreach (time_xact_t& time_xact, time_xacts) { if (event.account == time_xact.account) @@ -152,16 +146,12 @@ void time_log_t::clock_in(const datetime_t& checkin, time_xacts.push_back(event); } -void time_log_t::clock_out(const datetime_t& checkin, - account_t * account, - const string& desc, - const string& note) +void time_log_t::clock_out(time_xact_t event) { if (time_xacts.empty()) throw std::logic_error(_("Timelog check-out event without a check-in")); - clock_out_from_timelog(time_xacts, checkin, account, desc.c_str(), - note.c_str(), journal); + clock_out_from_timelog(time_xacts, event, journal); } } // namespace ledger |