From 31e8ed7587f6c7dc54e9623dd6a4e09ad5b6b017 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 17 Jun 2010 23:42:23 -0400 Subject: Individual postings may each have their own payee If a posting has the metadata field "Payee" set to a string, that will be used as the payee name for that posting. This affects the register report, the payees report, and the --by-payee option. This is useful because sometimes I send, say, 4 checks at a time to my bank. So on my bank statement, this is all just one amount: 2010-06-17 Sample Assets:Bank $400.00 Income:Check1 $-100.00 Income:Check2 $-100.00 Income:Check3 $-100.00 Income:Check4 $-100.00 Though it's important that the Assets:Bank posting be a single posting of $400 value, I'd like for income reports to show whom each check came from. Now I can say: 2010-06-17 Sample Assets:Bank $400.00 Income:Check1 $-100.00 ; Payee: Person One Income:Check2 $-100.00 ; Payee: Person Two Income:Check3 $-100.00 ; Payee: Person Three Income:Check4 $-100.00 ; Payee: Person Four When I report this, it appears as: 10-Jun-17 Sample Assets:Bank $400.00 $400.00 Person One Income:Check1 $-100.00 $300.00 Person Two Income:Check2 $-100.00 $200.00 Person Three Income:Check3 $-100.00 $100.00 Person Four Income:Check4 $-100.00 0 This shows that they are all in the same transaction (which is why the date is not repeated), but they have different payees. --- src/post.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/post.cc') diff --git a/src/post.cc b/src/post.cc index 675749fc..7c42e3c5 100644 --- a/src/post.cc +++ b/src/post.cc @@ -123,6 +123,14 @@ optional post_t::effective_date() const return date; } +string post_t::payee() const +{ + if (optional post_payee = get_tag(_("Payee"))) + return post_payee->as_string(); + else + return xact->payee; +} + namespace { value_t get_this(post_t& post) { return scope_value(&post); @@ -160,7 +168,7 @@ namespace { } value_t get_payee(post_t& post) { - return string_value(post.xact->payee); + return string_value(post.payee()); } value_t get_note(post_t& post) { -- cgit v1.2.3 From b80be82b8d4a3aaf226b00e7c12520318346ccea Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 18 Jun 2010 02:19:39 -0400 Subject: has_tag and get_tag now take an 'inherit' parameter --- src/item.cc | 9 +++++---- src/item.h | 18 +++++++++++------- src/post.cc | 18 ++++++++++-------- src/post.h | 18 +++++++++++------- 4 files changed, 37 insertions(+), 26 deletions(-) (limited to 'src/post.cc') diff --git a/src/item.cc b/src/item.cc index 4e9c7702..3845e4cb 100644 --- a/src/item.cc +++ b/src/item.cc @@ -37,7 +37,7 @@ namespace ledger { bool item_t::use_effective_date = false; -bool item_t::has_tag(const string& tag) const +bool item_t::has_tag(const string& tag, bool) const { DEBUG("item.meta", "Checking if item has tag: " << tag); if (! metadata) { @@ -57,7 +57,7 @@ bool item_t::has_tag(const string& tag) const } bool item_t::has_tag(const mask_t& tag_mask, - const optional& value_mask) const + const optional& value_mask, bool) const { if (metadata) { foreach (const string_map::value_type& data, *metadata) { @@ -72,7 +72,7 @@ bool item_t::has_tag(const mask_t& tag_mask, return false; } -optional item_t::get_tag(const string& tag) const + optional item_t::get_tag(const string& tag, bool) const { DEBUG("item.meta", "Getting item tag: " << tag); if (metadata) { @@ -87,7 +87,8 @@ optional item_t::get_tag(const string& tag) const } optional item_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const + const optional& value_mask, + bool) const { if (metadata) { foreach (const string_map::value_type& data, *metadata) { diff --git a/src/item.h b/src/item.h index 8018db9a..b7dde35f 100644 --- a/src/item.h +++ b/src/item.h @@ -149,13 +149,17 @@ public: return ! (*this == xact); } - virtual bool has_tag(const string& tag) const; - virtual bool has_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; - - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual bool has_tag(const string& tag, + bool inherit = true) const; + virtual bool has_tag(const mask_t& tag_mask, + const optional& value_mask = none, + bool inherit = true) const; + + virtual optional get_tag(const string& tag, + bool inherit = true) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none, + bool inherit = true) const; virtual string_map::iterator set_tag(const string& tag, diff --git a/src/post.cc b/src/post.cc index 7c42e3c5..4fc34892 100644 --- a/src/post.cc +++ b/src/post.cc @@ -39,40 +39,42 @@ namespace ledger { -bool post_t::has_tag(const string& tag) const +bool post_t::has_tag(const string& tag, bool inherit) const { if (item_t::has_tag(tag)) return true; - if (xact) + if (inherit && xact) return xact->has_tag(tag); return false; } bool post_t::has_tag(const mask_t& tag_mask, - const optional& value_mask) const + const optional& value_mask, + bool inherit) const { if (item_t::has_tag(tag_mask, value_mask)) return true; - if (xact) + if (inherit && xact) return xact->has_tag(tag_mask, value_mask); return false; } -optional post_t::get_tag(const string& tag) const +optional post_t::get_tag(const string& tag, bool inherit) const { if (optional value = item_t::get_tag(tag)) return value; - if (xact) + if (inherit && xact) return xact->get_tag(tag); return none; } optional post_t::get_tag(const mask_t& tag_mask, - const optional& value_mask) const + const optional& value_mask, + bool inherit) const { if (optional value = item_t::get_tag(tag_mask, value_mask)) return value; - if (xact) + if (inherit && xact) return xact->get_tag(tag_mask, value_mask); return none; } diff --git a/src/post.h b/src/post.h index 7111ddef..e1535a46 100644 --- a/src/post.h +++ b/src/post.h @@ -99,13 +99,17 @@ public: TRACE_DTOR(post_t); } - virtual bool has_tag(const string& tag) const; - virtual bool has_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; - - virtual optional get_tag(const string& tag) const; - virtual optional get_tag(const mask_t& tag_mask, - const optional& value_mask = none) const; + virtual bool has_tag(const string& tag, + bool inherit = true) const; + virtual bool has_tag(const mask_t& tag_mask, + const optional& value_mask = none, + bool inherit = true) const; + + virtual optional get_tag(const string& tag, + bool inherit = true) const; + virtual optional get_tag(const mask_t& tag_mask, + const optional& value_mask = none, + bool inherit = true) const; virtual date_t value_date() const; virtual date_t date() const; -- cgit v1.2.3