Option --count sums payees, account, commodities
This commit is contained in:
parent
de3803d027
commit
02e7825516
4 changed files with 39 additions and 18 deletions
|
|
@ -236,38 +236,51 @@ void report_accounts::flush()
|
|||
{
|
||||
std::ostream& out(report.output_stream);
|
||||
|
||||
foreach (accounts_pair& entry, accounts)
|
||||
foreach (accounts_pair& entry, accounts) {
|
||||
if (report.HANDLED(count))
|
||||
out << entry.second << ' ';
|
||||
out << *entry.first << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void report_accounts::operator()(post_t& post)
|
||||
{
|
||||
std::map<account_t *, bool>::iterator i = accounts.find(post.account);
|
||||
std::map<account_t *, std::size_t>::iterator i = accounts.find(post.account);
|
||||
if (i == accounts.end())
|
||||
accounts.insert(accounts_pair(post.account, true));
|
||||
accounts.insert(accounts_pair(post.account, 1));
|
||||
else
|
||||
(*i).second++;
|
||||
}
|
||||
|
||||
void report_payees::flush()
|
||||
{
|
||||
std::ostream& out(report.output_stream);
|
||||
|
||||
foreach (payees_pair& entry, payees)
|
||||
foreach (payees_pair& entry, payees) {
|
||||
if (report.HANDLED(count))
|
||||
out << entry.second << ' ';
|
||||
out << entry.first << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void report_payees::operator()(post_t& post)
|
||||
{
|
||||
std::map<string, bool>::iterator i = payees.find(post.xact->payee);
|
||||
std::map<string, std::size_t>::iterator i = payees.find(post.xact->payee);
|
||||
if (i == payees.end())
|
||||
payees.insert(payees_pair(post.xact->payee, true));
|
||||
payees.insert(payees_pair(post.xact->payee, 1));
|
||||
else
|
||||
(*i).second++;
|
||||
}
|
||||
|
||||
void report_commodities::flush()
|
||||
{
|
||||
std::ostream& out(report.output_stream);
|
||||
|
||||
foreach (commodities_pair& entry, commodities)
|
||||
foreach (commodities_pair& entry, commodities) {
|
||||
if (report.HANDLED(count))
|
||||
out << entry.second << ' ';
|
||||
out << *entry.first << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void report_commodities::operator()(post_t& post)
|
||||
|
|
@ -275,18 +288,22 @@ 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);
|
||||
std::map<commodity_t *, std::size_t>::iterator i = commodities.find(&comm);
|
||||
if (i == commodities.end())
|
||||
commodities.insert(commodities_pair(&comm, true));
|
||||
commodities.insert(commodities_pair(&comm, 1));
|
||||
else
|
||||
(*i).second++;
|
||||
|
||||
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 =
|
||||
std::map<commodity_t *, std::size_t>::iterator i =
|
||||
commodities.find(&ann_comm.details.price->commodity());
|
||||
if (i == commodities.end())
|
||||
commodities.insert
|
||||
(commodities_pair(&ann_comm.details.price->commodity(), true));
|
||||
(commodities_pair(&ann_comm.details.price->commodity(), 1));
|
||||
else
|
||||
(*i).second++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +311,9 @@ void report_commodities::operator()(post_t& post)
|
|||
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));
|
||||
commodities.insert(commodities_pair(&temp_cost.commodity(), 1));
|
||||
else
|
||||
(*i).second++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
12
src/output.h
12
src/output.h
|
|
@ -108,9 +108,9 @@ class report_accounts : public item_handler<post_t>
|
|||
protected:
|
||||
report_t& report;
|
||||
|
||||
std::map<account_t *, bool> accounts;
|
||||
std::map<account_t *, std::size_t> accounts;
|
||||
|
||||
typedef std::map<account_t *, bool>::value_type accounts_pair;
|
||||
typedef std::map<account_t *, std::size_t>::value_type accounts_pair;
|
||||
|
||||
public:
|
||||
report_accounts(report_t& _report) : report(_report) {
|
||||
|
|
@ -129,9 +129,9 @@ class report_payees : public item_handler<post_t>
|
|||
protected:
|
||||
report_t& report;
|
||||
|
||||
std::map<string, bool> payees;
|
||||
std::map<string, std::size_t> payees;
|
||||
|
||||
typedef std::map<string, bool>::value_type payees_pair;
|
||||
typedef std::map<string, std::size_t>::value_type payees_pair;
|
||||
|
||||
public:
|
||||
report_payees(report_t& _report) : report(_report) {
|
||||
|
|
@ -150,9 +150,9 @@ class report_commodities : public item_handler<post_t>
|
|||
protected:
|
||||
report_t& report;
|
||||
|
||||
std::map<commodity_t *, bool> commodities;
|
||||
std::map<commodity_t *, std::size_t> commodities;
|
||||
|
||||
typedef std::map<commodity_t *, bool>::value_type commodities_pair;
|
||||
typedef std::map<commodity_t *, std::size_t>::value_type commodities_pair;
|
||||
|
||||
public:
|
||||
report_commodities(report_t& _report) : report(_report) {
|
||||
|
|
|
|||
|
|
@ -853,6 +853,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
|||
else OPT(columns_);
|
||||
else OPT_ALT(basis, cost);
|
||||
else OPT_(current);
|
||||
else OPT(count);
|
||||
break;
|
||||
case 'd':
|
||||
OPT(daily);
|
||||
|
|
|
|||
|
|
@ -454,6 +454,7 @@ public:
|
|||
});
|
||||
|
||||
OPTION(report_t, columns_);
|
||||
OPTION(report_t, count);
|
||||
|
||||
OPTION__(report_t, csv_format_, CTOR(report_t, csv_format_) {
|
||||
on(none,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue