Timeclock entries can now have notes
Example of a tagged entry: i 2009/11/01 12:00:00 Account Payee ; :Foo: o 2009/11/01 13:00:00 Two spaces or a tab must separate account from payee, and payee from note.
This commit is contained in:
parent
b62b03335f
commit
eb772893b0
3 changed files with 47 additions and 18 deletions
|
|
@ -413,11 +413,18 @@ void instance_t::clock_in_directive(char * line,
|
||||||
{
|
{
|
||||||
string datetime(line, 2, 19);
|
string datetime(line, 2, 19);
|
||||||
|
|
||||||
char * p = skip_ws(line + 22);
|
char * p = skip_ws(line + 22);
|
||||||
char * n = next_element(p, true);
|
char * n = next_element(p, true);
|
||||||
|
char * end = n ? next_element(n, true) : NULL;
|
||||||
|
|
||||||
|
if (end && *end == ';')
|
||||||
|
end = skip_ws(end + 1);
|
||||||
|
else
|
||||||
|
end = NULL;
|
||||||
|
|
||||||
timelog.clock_in(parse_datetime(datetime, current_year),
|
timelog.clock_in(parse_datetime(datetime, current_year),
|
||||||
account_stack.front()->find_account(p), n ? n : "");
|
account_stack.front()->find_account(p),
|
||||||
|
n ? n : "", end ? end : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void instance_t::clock_out_directive(char * line,
|
void instance_t::clock_out_directive(char * line,
|
||||||
|
|
@ -427,9 +434,16 @@ void instance_t::clock_out_directive(char * line,
|
||||||
|
|
||||||
char * p = skip_ws(line + 22);
|
char * p = skip_ws(line + 22);
|
||||||
char * n = next_element(p, true);
|
char * n = next_element(p, true);
|
||||||
|
char * end = n ? next_element(n, true) : NULL;
|
||||||
|
|
||||||
|
if (end && *end == ';')
|
||||||
|
end = skip_ws(end + 1);
|
||||||
|
else
|
||||||
|
end = NULL;
|
||||||
|
|
||||||
timelog.clock_out(parse_datetime(datetime, current_year),
|
timelog.clock_out(parse_datetime(datetime, current_year),
|
||||||
p ? account_stack.front()->find_account(p) : NULL, n ? n : "");
|
p ? account_stack.front()->find_account(p) : NULL,
|
||||||
|
n ? n : "", end ? end : "");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ namespace {
|
||||||
const datetime_t& when,
|
const datetime_t& when,
|
||||||
account_t * account,
|
account_t * account,
|
||||||
const char * desc,
|
const char * desc,
|
||||||
|
const char * note,
|
||||||
journal_t& journal)
|
journal_t& journal)
|
||||||
{
|
{
|
||||||
time_xact_t event;
|
time_xact_t event;
|
||||||
|
|
@ -82,11 +83,19 @@ namespace {
|
||||||
desc = NULL;
|
desc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (note && event.note.empty()) {
|
||||||
|
event.note = note;
|
||||||
|
note = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
std::auto_ptr<xact_t> curr(new xact_t);
|
std::auto_ptr<xact_t> curr(new xact_t);
|
||||||
curr->_date = when.date();
|
curr->_date = when.date();
|
||||||
curr->code = desc ? desc : "";
|
curr->code = desc ? desc : "";
|
||||||
curr->payee = event.desc;
|
curr->payee = event.desc;
|
||||||
|
|
||||||
|
if (! event.note.empty())
|
||||||
|
curr->append_note(event.note.c_str());
|
||||||
|
|
||||||
if (when < event.checkin)
|
if (when < event.checkin)
|
||||||
throw parse_error
|
throw parse_error
|
||||||
(_("Timelog check-out date less than corresponding check-in"));
|
(_("Timelog check-out date less than corresponding check-in"));
|
||||||
|
|
@ -119,8 +128,8 @@ time_log_t::~time_log_t()
|
||||||
accounts.push_back(time_xact.account);
|
accounts.push_back(time_xact.account);
|
||||||
|
|
||||||
foreach (account_t * account, accounts)
|
foreach (account_t * account, accounts)
|
||||||
clock_out_from_timelog(time_xacts, CURRENT_TIME(), account, NULL,
|
clock_out_from_timelog(time_xacts, CURRENT_TIME(), account,
|
||||||
journal);
|
NULL, NULL, journal);
|
||||||
|
|
||||||
assert(time_xacts.empty());
|
assert(time_xacts.empty());
|
||||||
}
|
}
|
||||||
|
|
@ -128,9 +137,10 @@ time_log_t::~time_log_t()
|
||||||
|
|
||||||
void time_log_t::clock_in(const datetime_t& checkin,
|
void time_log_t::clock_in(const datetime_t& checkin,
|
||||||
account_t * account,
|
account_t * account,
|
||||||
const string& desc)
|
const string& desc,
|
||||||
|
const string& note)
|
||||||
{
|
{
|
||||||
time_xact_t event(checkin, account, desc);
|
time_xact_t event(checkin, account, desc, note);
|
||||||
|
|
||||||
if (! time_xacts.empty()) {
|
if (! time_xacts.empty()) {
|
||||||
foreach (time_xact_t& time_xact, time_xacts) {
|
foreach (time_xact_t& time_xact, time_xacts) {
|
||||||
|
|
@ -144,13 +154,14 @@ void time_log_t::clock_in(const datetime_t& checkin,
|
||||||
|
|
||||||
void time_log_t::clock_out(const datetime_t& checkin,
|
void time_log_t::clock_out(const datetime_t& checkin,
|
||||||
account_t * account,
|
account_t * account,
|
||||||
const string& desc)
|
const string& desc,
|
||||||
|
const string& note)
|
||||||
{
|
{
|
||||||
if (time_xacts.empty())
|
if (time_xacts.empty())
|
||||||
throw std::logic_error(_("Timelog check-out event without a check-in"));
|
throw std::logic_error(_("Timelog check-out event without a check-in"));
|
||||||
|
|
||||||
clock_out_from_timelog(time_xacts, checkin, account, desc.c_str(),
|
clock_out_from_timelog(time_xacts, checkin, account, desc.c_str(),
|
||||||
journal);
|
note.c_str(), journal);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
|
|
@ -56,19 +56,21 @@ public:
|
||||||
datetime_t checkin;
|
datetime_t checkin;
|
||||||
account_t * account;
|
account_t * account;
|
||||||
string desc;
|
string desc;
|
||||||
|
string note;
|
||||||
|
|
||||||
time_xact_t() : account(NULL) {
|
time_xact_t() : account(NULL) {
|
||||||
TRACE_CTOR(time_xact_t, "");
|
TRACE_CTOR(time_xact_t, "");
|
||||||
}
|
}
|
||||||
time_xact_t(const datetime_t& _checkin,
|
time_xact_t(const datetime_t& _checkin,
|
||||||
account_t * _account = NULL,
|
account_t * _account = NULL,
|
||||||
const string& _desc = "")
|
const string& _desc = "",
|
||||||
: checkin(_checkin), account(_account), desc(_desc) {
|
const string& _note = "")
|
||||||
TRACE_CTOR(time_xact_t, "const datetime_t&, account_t *, const string&");
|
: checkin(_checkin), account(_account), desc(_desc), note(_note) {
|
||||||
|
TRACE_CTOR(time_xact_t, "const datetime_t&, account_t *, string, string");
|
||||||
}
|
}
|
||||||
time_xact_t(const time_xact_t& xact)
|
time_xact_t(const time_xact_t& xact)
|
||||||
: checkin(xact.checkin), account(xact.account),
|
: checkin(xact.checkin), account(xact.account),
|
||||||
desc(xact.desc) {
|
desc(xact.desc), note(xact.note) {
|
||||||
TRACE_CTOR(time_xact_t, "copy");
|
TRACE_CTOR(time_xact_t, "copy");
|
||||||
}
|
}
|
||||||
~time_xact_t() throw() {
|
~time_xact_t() throw() {
|
||||||
|
|
@ -79,7 +81,7 @@ public:
|
||||||
class time_log_t
|
class time_log_t
|
||||||
{
|
{
|
||||||
std::list<time_xact_t> time_xacts;
|
std::list<time_xact_t> time_xacts;
|
||||||
journal_t& journal;
|
journal_t& journal;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
time_log_t(journal_t& _journal) : journal(_journal) {
|
time_log_t(journal_t& _journal) : journal(_journal) {
|
||||||
|
|
@ -89,11 +91,13 @@ public:
|
||||||
|
|
||||||
void clock_in(const datetime_t& checkin,
|
void clock_in(const datetime_t& checkin,
|
||||||
account_t * account = NULL,
|
account_t * account = NULL,
|
||||||
const string& desc = "");
|
const string& desc = "",
|
||||||
|
const string& note = "");
|
||||||
|
|
||||||
void clock_out(const datetime_t& checkin,
|
void clock_out(const datetime_t& checkin,
|
||||||
account_t * account = NULL,
|
account_t * account = NULL,
|
||||||
const string& desc = "");
|
const string& desc = "",
|
||||||
|
const string& note = "");
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue