diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-22 15:40:38 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-22 21:35:02 -0400 |
commit | de3803d0277353520116f05c7b2357196a8cfe48 (patch) | |
tree | 4648465cf73f1879d3d191924bdf905f96148924 /src/output.cc | |
parent | e3ba0117a39a3665743df5a1d5ca3b77ca2f00ec (diff) | |
download | fork-ledger-de3803d0277353520116f05c7b2357196a8cfe48.tar.gz fork-ledger-de3803d0277353520116f05c7b2357196a8cfe48.tar.bz2 fork-ledger-de3803d0277353520116f05c7b2357196a8cfe48.zip |
Added new commands: acounts, payees, commodities
These three reports simply dump an unordered list (with the exception of
payees) shows all accounts, payees, and commodities represented in a
given report. This can be used to easily generate per-entity report,
for example:
ledger payees | \
while read payee; do \
echo ; echo $payee ; \
ledger reg payee "$payee" ; \
done
Diffstat (limited to 'src/output.cc')
-rw-r--r-- | src/output.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/output.cc b/src/output.cc index 30775310..e3aa9f4a 100644 --- a/src/output.cc +++ b/src/output.cc @@ -232,4 +232,70 @@ void format_accounts::operator()(account_t& account) posted_accounts.push_back(&account); } +void report_accounts::flush() +{ + std::ostream& out(report.output_stream); + + foreach (accounts_pair& entry, accounts) + out << *entry.first << '\n'; +} + +void report_accounts::operator()(post_t& post) +{ + std::map<account_t *, bool>::iterator i = accounts.find(post.account); + if (i == accounts.end()) + accounts.insert(accounts_pair(post.account, true)); +} + +void report_payees::flush() +{ + std::ostream& out(report.output_stream); + + foreach (payees_pair& entry, payees) + out << entry.first << '\n'; +} + +void report_payees::operator()(post_t& post) +{ + std::map<string, bool>::iterator i = payees.find(post.xact->payee); + if (i == payees.end()) + payees.insert(payees_pair(post.xact->payee, true)); +} + +void report_commodities::flush() +{ + std::ostream& out(report.output_stream); + + foreach (commodities_pair& entry, commodities) + out << *entry.first << '\n'; +} + +void report_commodities::operator()(post_t& post) +{ + amount_t temp(post.amount.strip_annotations(report.what_to_keep())); + commodity_t& comm(temp.commodity()); + + std::map<commodity_t *, bool>::iterator i = commodities.find(&comm); + if (i == commodities.end()) + commodities.insert(commodities_pair(&comm, true)); + + if (comm.has_annotation()) { + annotated_commodity_t& ann_comm(as_annotated_commodity(comm)); + if (ann_comm.details.price) { + std::map<commodity_t *, bool>::iterator i = + commodities.find(&ann_comm.details.price->commodity()); + if (i == commodities.end()) + commodities.insert + (commodities_pair(&ann_comm.details.price->commodity(), true)); + } + } + + if (post.cost) { + amount_t temp_cost(post.cost->strip_annotations(report.what_to_keep())); + i = commodities.find(&temp_cost.commodity()); + if (i == commodities.end()) + commodities.insert(commodities_pair(&temp_cost.commodity(), true)); + } +} + } // namespace ledger |