summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-24 15:06:43 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-24 15:06:43 -0400
commit1ecf62ce25e01def8a0df0a7c59047148c2cd734 (patch)
tree01afd48f7403482cc6be320a28c3b3ad3707fdf2
parentc4207a79d7250f95d259678d0e4077a2a39b1d32 (diff)
downloadfork-ledger-1ecf62ce25e01def8a0df0a7c59047148c2cd734.tar.gz
fork-ledger-1ecf62ce25e01def8a0df0a7c59047148c2cd734.tar.bz2
fork-ledger-1ecf62ce25e01def8a0df0a7c59047148c2cd734.zip
Output "@ AMOUNT" cost in the print report
-rw-r--r--src/post.cc35
-rw-r--r--src/report.h2
2 files changed, 26 insertions, 11 deletions
diff --git a/src/post.cc b/src/post.cc
index 366af008..5c188a6e 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -122,6 +122,10 @@ namespace {
return post.has_flags(POST_CALCULATED);
}
+ value_t get_is_priced(post_t& post) {
+ return post.has_flags(POST_PRICED);
+ }
+
value_t get_virtual(post_t& post) {
return post.has_flags(POST_VIRTUAL);
}
@@ -162,16 +166,18 @@ namespace {
return post.amount.commodity().has_flags(COMMODITY_PRIMARY);
}
+ value_t get_has_cost(post_t& post) {
+ return post.cost ? true : false;
+ }
+
value_t get_cost(post_t& post) {
- if (post.has_xdata() &&
- post.xdata().has_flags(POST_EXT_COMPOUND)) {
+ if (post.cost)
+ return *post.cost;
+ else if (post.has_xdata() &&
+ post.xdata().has_flags(POST_EXT_COMPOUND))
return post.xdata().value;
- } else {
- if (post.cost)
- return *post.cost;
- else
- return post.amount;
- }
+ else
+ return post.amount;
}
value_t get_total(post_t& post) {
@@ -250,9 +256,9 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
return WRAP_FUNCTOR(get_wrapper<&get_account_depth>);
break;
- case 'r':
- if (name == "real")
- return WRAP_FUNCTOR(get_wrapper<&get_real>);
+ case 'h':
+ if (name == "has_cost")
+ return WRAP_FUNCTOR(get_wrapper<&get_has_cost>);
break;
case 'p':
@@ -262,6 +268,13 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
else if (name == "primary")
return WRAP_FUNCTOR(get_wrapper<&get_commodity_is_primary>);
+ else if (name == "priced")
+ return WRAP_FUNCTOR(get_wrapper<&get_is_priced>);
+ break;
+
+ case 'r':
+ if (name == "real")
+ return WRAP_FUNCTOR(get_wrapper<&get_real>);
break;
case 't':
diff --git a/src/report.h b/src/report.h
index 84f120df..7585493f 100644
--- a/src/report.h
+++ b/src/report.h
@@ -504,10 +504,12 @@ public:
" %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")"
"%-34(account)"
" %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))"
+ "%(has_cost & !priced ? \" @ \" + justify(scrub(cost / amount), 0) : \"\")"
"%(comment | \"\")\n%/"
" %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")"
"%-34(account)"
" %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))"
+ "%(has_cost & !priced ? \" @ \" + justify(scrub(cost / amount), 0) : \"\")"
"%(comment | \"\")\n%/\n");
});