From 47bfe58ab39aa8d7ed4dc804409f1f78f485a5a6 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 18 May 2010 17:37:27 -0400 Subject: Added account_id and xact_id valexpr vars for posts account_id is the "whicheth" number for that posting within its account. The xact_id is within its transaction. --- src/post.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/post.cc') diff --git a/src/post.cc b/src/post.cc index 183fb901..fb3281a7 100644 --- a/src/post.cc +++ b/src/post.cc @@ -142,6 +142,10 @@ namespace { return value_t(static_cast(post.xact)); } + value_t get_xact_id(post_t& post) { + return static_cast(post.xact_id()); + } + value_t get_code(post_t& post) { if (post.xact->code) return string_value(*post.xact->code); @@ -275,6 +279,10 @@ namespace { return string_value(name); } + value_t get_account_id(post_t& post) { + return static_cast(post.account_id()); + } + value_t get_account_base(post_t& post) { return string_value(post.reported_account()->name); } @@ -351,6 +359,8 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, return WRAP_FUNCTOR(get_account); else if (name == "account_base") return WRAP_FUNCTOR(get_wrapper<&get_account_base>); + else if (name == "account_id") + return WRAP_FUNCTOR(get_wrapper<&get_account_id>); else if (name == "any") return WRAP_FUNCTOR(&fn_any); else if (name == "all") @@ -444,6 +454,8 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, case 'x': if (name == "xact") return WRAP_FUNCTOR(get_wrapper<&get_xact>); + else if (name == "xact_id") + return WRAP_FUNCTOR(get_wrapper<&get_xact_id>); break; case 'N': @@ -479,6 +491,30 @@ amount_t post_t::resolve_expr(scope_t& scope, expr_t& expr) } } +std::size_t post_t::xact_id() const +{ + std::size_t id = 1; + foreach (post_t * p, xact->posts) { + if (p == this) + return id; + id++; + } + assert(! "Failed to find posting within its transaction"); + return 0; +} + +std::size_t post_t::account_id() const +{ + std::size_t id = 1; + foreach (post_t * p, account->posts) { + if (p == this) + return id; + id++; + } + assert(! "Failed to find posting within its transaction"); + return 0; +} + bool post_t::valid() const { if (! xact) { -- cgit v1.2.3 From 33aa0cc3a6ad9485198c0e5abe694822811483b4 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 22 May 2010 17:08:16 -0400 Subject: Changed the report generated by the csv command Fields are now: Date,Code,Payee,Account,Commodity,Total,State,Note Instead of outputting amounts potentially as $1,000.00 (which was an error anyway), the output is now: $,1000.00. This makes the commodity available in a separate field, and removes display of thousands markers. Also, european formatting is always off. --- src/post.cc | 14 ++++++++++++-- src/report.h | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/post.cc') diff --git a/src/post.cc b/src/post.cc index fb3281a7..18c566c4 100644 --- a/src/post.cc +++ b/src/post.cc @@ -187,11 +187,21 @@ namespace { } value_t get_commodity(post_t& post) { - return string_value(post.amount.commodity().symbol()); + if (post.has_xdata() && + post.xdata().has_flags(POST_EXT_COMPOUND)) + return string_value(post.xdata().compound_value.to_amount() + .commodity().symbol()); + else + return string_value(post.amount.commodity().symbol()); } value_t get_commodity_is_primary(post_t& post) { - return post.amount.commodity().has_flags(COMMODITY_PRIMARY); + if (post.has_xdata() && + post.xdata().has_flags(POST_EXT_COMPOUND)) + return post.xdata().compound_value.to_amount() + .commodity().has_flags(COMMODITY_PRIMARY); + else + return post.amount.commodity().has_flags(COMMODITY_PRIMARY); } value_t get_has_cost(post_t& post) { diff --git a/src/report.h b/src/report.h index 783f0026..df2f3469 100644 --- a/src/report.h +++ b/src/report.h @@ -459,11 +459,12 @@ public: OPTION__(report_t, csv_format_, CTOR(report_t, csv_format_) { on(none, "%(quoted(date))," + "%(quoted(code))," "%(quoted(payee))," "%(quoted(account))," - "%(quoted(scrub(display_amount)))," + "%(quoted(commodity))," + "%(quoted(quantity(scrub(display_amount))))," "%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\")))," - "%(quoted(code))," "%(quoted(join(note | xact.note)))\n"); }); -- cgit v1.2.3 From b5c9be4d29fab1388e195600d659602ae19b8f4e Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 22 May 2010 21:05:30 -0400 Subject: Created new valexpr variable display_account Where display_account might be '(Expenses:Food)', account will always be 'Expenses:Food'. account is now used by all matching and query operations, while display_account is used in the various report outputs (besides balance, which never distinguished virtual accounts). Fixes F2832452-4521-49A3-B854-F4E12CC4D82E --- src/post.cc | 32 ++++++++++++++++++++++++-------- src/report.h | 10 +++++----- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src/post.cc') diff --git a/src/post.cc b/src/post.cc index 18c566c4..f1f3e96a 100644 --- a/src/post.cc +++ b/src/post.cc @@ -236,7 +236,7 @@ namespace { return 1L; } - value_t get_account(call_scope_t& scope) + value_t account_name(call_scope_t& scope) { in_context_t env(scope, "&v"); @@ -279,14 +279,28 @@ namespace { } else { name = env->reported_account()->fullname(); } + return string_value(name); + } - if (env->has_flags(POST_VIRTUAL)) { - if (env->must_balance()) - name = string("[") + name + "]"; - else - name = string("(") + name + ")"; + value_t get_display_account(call_scope_t& scope) + { + in_context_t env(scope, "&v"); + + value_t acct = account_name(scope); + if (acct.is_string()) { + if (env->has_flags(POST_VIRTUAL)) { + if (env->must_balance()) + acct = string_value(string("[") + acct.as_string() + "]"); + else + acct = string_value(string("(") + acct.as_string() + ")"); + } } - return string_value(name); + return acct; + } + + value_t get_account(call_scope_t& scope) + { + return account_name(scope); } value_t get_account_id(post_t& post) { @@ -398,7 +412,9 @@ expr_t::ptr_op_t post_t::lookup(const symbol_t::kind_t kind, break; case 'd': - if (name == "depth") + if (name == "display_account") + return WRAP_FUNCTOR(get_display_account); + else if (name == "depth") return WRAP_FUNCTOR(get_wrapper<&get_account_depth>); else if (name == "datetime") return WRAP_FUNCTOR(get_wrapper<&get_datetime>); diff --git a/src/report.h b/src/report.h index 64c14858..aff4af91 100644 --- a/src/report.h +++ b/src/report.h @@ -463,7 +463,7 @@ public: "%(quoted(date))," "%(quoted(code))," "%(quoted(payee))," - "%(quoted(account))," + "%(quoted(display_account))," "%(quoted(commodity))," "%(quoted(quantity(scrub(display_amount))))," "%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\")))," @@ -752,13 +752,13 @@ public: OPTION__(report_t, prices_format_, CTOR(report_t, prices_format_) { on(none, - "%(date) %-8(account) %(justify(scrub(display_amount), 12, " + "%(date) %-8(display_account) %(justify(scrub(display_amount), 12, " " 2 + 9 + 8 + 12, true, color))\n"); }); OPTION__(report_t, pricedb_format_, CTOR(report_t, pricedb_format_) { on(none, - "P %(datetime) %(account) %(scrub(display_amount))\n"); + "P %(datetime) %(display_account) %(scrub(display_amount))\n"); }); OPTION(report_t, print_virtual); @@ -785,8 +785,8 @@ public: " if color & date > today))" " %(ansify_if(justify(truncated(payee, payee_width), payee_width), " " bold if color & !cleared & actual))" - " %(ansify_if(justify(truncated(account, account_width, abbrev_len), " - " account_width), blue if color))" + " %(ansify_if(justify(truncated(display_account, account_width, " + " abbrev_len), account_width), blue if color))" " %(justify(scrub(display_amount), amount_width, " " 3 + meta_width + date_width + payee_width + account_width" " + amount_width + prepend_width, true, color))" -- cgit v1.2.3 From 4f3b39e22c7a7743132ead79b1e092929679de44 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 30 May 2010 02:55:02 -0600 Subject: Empty notes and tags now return null values --- src/filters.cc | 84 +++++++++++++++++++----------------- src/item.cc | 9 ++-- src/post.cc | 12 ++++-- src/xact.cc | 2 +- test/baseline/opt-code-as-payee.test | 4 +- 5 files changed, 60 insertions(+), 51 deletions(-) (limited to 'src/post.cc') diff --git a/src/filters.cc b/src/filters.cc index 6915144d..6e4aeee3 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -69,14 +69,16 @@ void post_splitter::operator()(post_t& post) bind_scope_t bound_scope(report, post); value_t result(group_by_expr.calc(bound_scope)); - value_to_posts_map::iterator i = posts_map.find(result); - if (i != posts_map.end()) { - (*i).second.push_back(&post); - } else { - std::pair inserted - = posts_map.insert(value_to_posts_map::value_type(result, posts_list())); - assert(inserted.second); - (*inserted.first).second.push_back(&post); + if (! result.is_null()) { + value_to_posts_map::iterator i = posts_map.find(result); + if (i != posts_map.end()) { + (*i).second.push_back(&post); + } else { + std::pair inserted + = posts_map.insert(value_to_posts_map::value_type(result, posts_list())); + assert(inserted.second); + (*inserted.first).second.push_back(&post); + } } } @@ -837,41 +839,43 @@ void transfer_details::operator()(post_t& post) bind_scope_t bound_scope(scope, temp); value_t substitute(expr.calc(bound_scope)); - switch (which_element) { - case SET_DATE: - temp.xdata().date = substitute.to_date(); - break; - - case SET_ACCOUNT: { - string account_name = substitute.to_string(); - if (! account_name.empty() && - account_name[account_name.length() - 1] != ':') { - account_t * prev_account = temp.account; - temp.account->remove_post(&temp); - - account_name += ':'; - account_name += prev_account->fullname(); - - std::list account_names; - split_string(account_name, ':', account_names); - temp.account = create_temp_account_from_path(account_names, temps, - xact.journal->master); - temp.account->add_post(&temp); - - temp.account->add_flags(prev_account->flags()); - if (prev_account->has_xdata()) - temp.account->xdata().add_flags(prev_account->xdata().flags()); + if (! substitute.is_null()) { + switch (which_element) { + case SET_DATE: + temp.xdata().date = substitute.to_date(); + break; + + case SET_ACCOUNT: { + string account_name = substitute.to_string(); + if (! account_name.empty() && + account_name[account_name.length() - 1] != ':') { + account_t * prev_account = temp.account; + temp.account->remove_post(&temp); + + account_name += ':'; + account_name += prev_account->fullname(); + + std::list account_names; + split_string(account_name, ':', account_names); + temp.account = create_temp_account_from_path(account_names, temps, + xact.journal->master); + temp.account->add_post(&temp); + + temp.account->add_flags(prev_account->flags()); + if (prev_account->has_xdata()) + temp.account->xdata().add_flags(prev_account->xdata().flags()); + } + break; } - break; - } - case SET_PAYEE: - xact.payee = substitute.to_string(); - break; + case SET_PAYEE: + xact.payee = substitute.to_string(); + break; - default: - assert(false); - break; + default: + assert(false); + break; + } } item_handler::operator()(temp); diff --git a/src/item.cc b/src/item.cc index 14a0896f..0a22b260 100644 --- a/src/item.cc +++ b/src/item.cc @@ -227,7 +227,7 @@ namespace { return NULL_VALUE; } value_t get_note(item_t& item) { - return string_value(item.note ? *item.note : empty_string); + return item.note ? string_value(*item.note) : NULL_VALUE; } value_t has_tag(call_scope_t& args) { @@ -260,7 +260,8 @@ namespace { return false; } - value_t get_tag(call_scope_t& args) { + value_t get_tag(call_scope_t& args) + { item_t& item(find_scope(args)); optional str; @@ -292,14 +293,14 @@ namespace { if (str) return string_value(*str); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_pathname(item_t& item) { if (item.pos) return string_value(item.pos->pathname.string()); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_beg_pos(item_t& item) { diff --git a/src/post.cc b/src/post.cc index f1f3e96a..7dc15830 100644 --- a/src/post.cc +++ b/src/post.cc @@ -150,7 +150,7 @@ namespace { if (post.xact->code) return string_value(*post.xact->code); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_payee(post_t& post) { @@ -158,9 +158,13 @@ namespace { } value_t get_note(post_t& post) { - string note = post.note ? *post.note : empty_string; - note += post.xact->note ? *post.xact->note : empty_string; - return string_value(note); + if (post.note || post.xact->note) { + string note = post.note ? *post.note : empty_string; + note += post.xact->note ? *post.xact->note : empty_string; + return string_value(note); + } else { + return NULL_VALUE; + } } value_t get_magnitude(post_t& post) { diff --git a/src/xact.cc b/src/xact.cc index f63835c9..569e5869 100644 --- a/src/xact.cc +++ b/src/xact.cc @@ -468,7 +468,7 @@ namespace { if (xact.code) return string_value(*xact.code); else - return string_value(empty_string); + return NULL_VALUE; } value_t get_payee(xact_t& xact) { diff --git a/test/baseline/opt-code-as-payee.test b/test/baseline/opt-code-as-payee.test index c2988626..99aa182e 100644 --- a/test/baseline/opt-code-as-payee.test +++ b/test/baseline/opt-code-as-payee.test @@ -28,7 +28,7 @@ reg --payee=code 08-Feb-01 102 Assets:Cash $-20.00 0 08-Feb-28 103 Expenses:Books $20.00 $20.00 08-Feb-28 103 Assets:Cash $-20.00 0 -08-Mar-01 Expenses:Books $30.00 $30.00 -08-Mar-01 Assets:Cash $-30.00 0 +08-Mar-01 March Expenses:Books $30.00 $30.00 +08-Mar-01 March Assets:Cash $-30.00 0 >>>2 === 0 -- cgit v1.2.3