Output "@ AMOUNT" cost in the print report

This commit is contained in:
John Wiegley 2009-02-24 15:06:43 -04:00
parent c4207a79d7
commit 1ecf62ce25
2 changed files with 26 additions and 11 deletions

View file

@ -122,6 +122,10 @@ namespace {
return post.has_flags(POST_CALCULATED); 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) { value_t get_virtual(post_t& post) {
return post.has_flags(POST_VIRTUAL); return post.has_flags(POST_VIRTUAL);
} }
@ -162,17 +166,19 @@ namespace {
return post.amount.commodity().has_flags(COMMODITY_PRIMARY); 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) { value_t get_cost(post_t& post) {
if (post.has_xdata() &&
post.xdata().has_flags(POST_EXT_COMPOUND)) {
return post.xdata().value;
} else {
if (post.cost) if (post.cost)
return *post.cost; return *post.cost;
else if (post.has_xdata() &&
post.xdata().has_flags(POST_EXT_COMPOUND))
return post.xdata().value;
else else
return post.amount; return post.amount;
} }
}
value_t get_total(post_t& post) { value_t get_total(post_t& post) {
if (post.xdata_ && ! post.xdata_->total.is_null()) if (post.xdata_ && ! post.xdata_->total.is_null())
@ -250,9 +256,9 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
return WRAP_FUNCTOR(get_wrapper<&get_account_depth>); return WRAP_FUNCTOR(get_wrapper<&get_account_depth>);
break; break;
case 'r': case 'h':
if (name == "real") if (name == "has_cost")
return WRAP_FUNCTOR(get_wrapper<&get_real>); return WRAP_FUNCTOR(get_wrapper<&get_has_cost>);
break; break;
case 'p': case 'p':
@ -262,6 +268,13 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
return WRAP_FUNCTOR(get_wrapper<&get_payee>); return WRAP_FUNCTOR(get_wrapper<&get_payee>);
else if (name == "primary") else if (name == "primary")
return WRAP_FUNCTOR(get_wrapper<&get_commodity_is_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; break;
case 't': case 't':

View file

@ -504,10 +504,12 @@ public:
" %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")" " %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")"
"%-34(account)" "%-34(account)"
" %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))" " %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))"
"%(has_cost & !priced ? \" @ \" + justify(scrub(cost / amount), 0) : \"\")"
"%(comment | \"\")\n%/" "%(comment | \"\")\n%/"
" %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")" " %(xact.uncleared ? (cleared ? \"* \" : (pending ? \"! \" : \"\")) : \"\")"
"%-34(account)" "%-34(account)"
" %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))" " %12(calculated ? \"\" : justify(scrub(amount), 12, -1, true))"
"%(has_cost & !priced ? \" @ \" + justify(scrub(cost / amount), 0) : \"\")"
"%(comment | \"\")\n%/\n"); "%(comment | \"\")\n%/\n");
}); });