Added several new reporting options
To help with gathering specific reports: - --payee-as-account copies the entry's payee field to the account, allowing the subtotal report to show unique payees for each period. - --comm-as-account copies the transaction's amount's commodity to the account. - --code-as-account copies the entry's code to the account Also created aliases for some of these options, for conistency's sake: - --commodity-as-payee is now an alias for --comm-as-payee - --commodity-as-account is now an alias for --comm-as-account
This commit is contained in:
parent
053ecc9366
commit
15bfeb3cb1
5 changed files with 144 additions and 56 deletions
|
|
@ -199,6 +199,12 @@ xact_handler_ptr chain_xact_handlers(report_t& report,
|
|||
handler.reset(new set_comm_as_payee(handler));
|
||||
else if (report.HANDLED(code_as_payee))
|
||||
handler.reset(new set_code_as_payee(handler));
|
||||
else if (report.HANDLED(payee_as_account))
|
||||
handler.reset(new set_payee_as_account(handler, report.session.master.get()));
|
||||
else if (report.HANDLED(comm_as_account))
|
||||
handler.reset(new set_comm_as_account(handler, report.session.master.get()));
|
||||
else if (report.HANDLED(code_as_account))
|
||||
handler.reset(new set_code_as_account(handler, report.session.master.get()));
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -560,49 +560,20 @@ void by_payee_xacts::operator()(xact_t& xact)
|
|||
(*(*i).second)(xact);
|
||||
}
|
||||
|
||||
void set_comm_as_payee::operator()(xact_t& xact)
|
||||
void transfer_details::operator()(xact_t& xact)
|
||||
{
|
||||
entry_temps.push_back(*xact.entry);
|
||||
entry_t& entry = entry_temps.back();
|
||||
entry._date = xact._date;
|
||||
entry._date_eff = xact._date_eff;
|
||||
entry.code = xact.entry->code;
|
||||
|
||||
if (xact.amount.commodity())
|
||||
entry.payee = xact.amount.commodity().symbol();
|
||||
else
|
||||
entry.payee = "<none>";
|
||||
entry._date = xact.reported_date();
|
||||
|
||||
xact_temps.push_back(xact);
|
||||
xact_t& temp = xact_temps.back();
|
||||
temp.entry = &entry;
|
||||
temp.set_state(xact.state());
|
||||
temp.add_flags(ITEM_TEMP);
|
||||
|
||||
entry.add_xact(&temp);
|
||||
|
||||
item_handler<xact_t>::operator()(temp);
|
||||
}
|
||||
|
||||
void set_code_as_payee::operator()(xact_t& xact)
|
||||
{
|
||||
entry_temps.push_back(*xact.entry);
|
||||
entry_t& entry = entry_temps.back();
|
||||
entry._date = xact._date;
|
||||
entry._date_eff = xact._date_eff;
|
||||
|
||||
if (xact.entry->code)
|
||||
entry.payee = *xact.entry->code;
|
||||
else
|
||||
entry.payee = "<none>";
|
||||
|
||||
xact_temps.push_back(xact);
|
||||
xact_t& temp = xact_temps.back();
|
||||
temp.entry = &entry;
|
||||
temp.set_state(xact.state());
|
||||
temp.add_flags(ITEM_TEMP);
|
||||
|
||||
entry.add_xact(&temp);
|
||||
set_details(entry, temp);
|
||||
|
||||
item_handler<xact_t>::operator()(temp);
|
||||
}
|
||||
|
|
|
|||
149
src/filters.h
149
src/filters.h
|
|
@ -298,6 +298,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
inline void clear_entries_xacts(std::list<entry_t>& entries_list) {
|
||||
foreach (entry_t& entry, entries_list)
|
||||
entry.xacts.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
|
|
@ -319,6 +324,7 @@ public:
|
|||
}
|
||||
virtual ~anonymize_xacts() {
|
||||
TRACE_DTOR(anonymize_xacts);
|
||||
clear_entries_xacts(entry_temps);
|
||||
}
|
||||
|
||||
virtual void operator()(xact_t& xact);
|
||||
|
|
@ -366,11 +372,6 @@ public:
|
|||
virtual void operator()(xact_t& xact);
|
||||
};
|
||||
|
||||
inline void clear_entries_xacts(std::list<entry_t>& entries_list) {
|
||||
foreach (entry_t& entry, entries_list)
|
||||
entry.xacts.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
|
|
@ -570,11 +571,8 @@ class interval_xacts : public subtotal_xacts
|
|||
{
|
||||
interval_t interval;
|
||||
xact_t * last_xact;
|
||||
|
||||
std::list<entry_t> entry_temps;
|
||||
std::list<xact_t> xact_temps;
|
||||
account_t empty_account;
|
||||
bool generate_empty_xacts;
|
||||
account_t empty_account;
|
||||
bool generate_empty_xacts;
|
||||
|
||||
interval_xacts();
|
||||
|
||||
|
|
@ -637,23 +635,25 @@ class by_payee_xacts : public item_handler<xact_t>
|
|||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_comm_as_payee : public item_handler<xact_t>
|
||||
class transfer_details : public item_handler<xact_t>
|
||||
{
|
||||
std::list<entry_t> entry_temps;
|
||||
std::list<xact_t> xact_temps;
|
||||
|
||||
set_comm_as_payee();
|
||||
transfer_details();
|
||||
|
||||
public:
|
||||
set_comm_as_payee(xact_handler_ptr handler)
|
||||
transfer_details(xact_handler_ptr handler)
|
||||
: item_handler<xact_t>(handler) {
|
||||
TRACE_CTOR(set_comm_as_payee, "xact_handler_ptr");
|
||||
TRACE_CTOR(transfer_details, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_comm_as_payee() {
|
||||
TRACE_DTOR(set_comm_as_payee);
|
||||
virtual ~transfer_details() {
|
||||
TRACE_DTOR(transfer_details);
|
||||
clear_entries_xacts(entry_temps);
|
||||
}
|
||||
|
||||
virtual void set_details(entry_t& entry, xact_t& xact) = 0;
|
||||
|
||||
virtual void operator()(xact_t& xact);
|
||||
};
|
||||
|
||||
|
|
@ -662,24 +662,129 @@ public:
|
|||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_code_as_payee : public item_handler<xact_t>
|
||||
class set_comm_as_payee : public transfer_details
|
||||
{
|
||||
std::list<entry_t> entry_temps;
|
||||
std::list<xact_t> xact_temps;
|
||||
set_comm_as_payee();
|
||||
|
||||
public:
|
||||
set_comm_as_payee(xact_handler_ptr handler)
|
||||
: transfer_details(handler) {
|
||||
TRACE_CTOR(set_comm_as_payee, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_comm_as_payee() {
|
||||
TRACE_DTOR(set_comm_as_payee);
|
||||
}
|
||||
|
||||
virtual void set_details(entry_t& entry, xact_t& xact) {
|
||||
if (xact.amount.commodity())
|
||||
entry.payee = xact.amount.commodity().symbol();
|
||||
else
|
||||
entry.payee = "<none>";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_code_as_payee : public transfer_details
|
||||
{
|
||||
set_code_as_payee();
|
||||
|
||||
public:
|
||||
set_code_as_payee(xact_handler_ptr handler)
|
||||
: item_handler<xact_t>(handler) {
|
||||
: transfer_details(handler) {
|
||||
TRACE_CTOR(set_code_as_payee, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_code_as_payee() {
|
||||
TRACE_DTOR(set_code_as_payee);
|
||||
clear_entries_xacts(entry_temps);
|
||||
}
|
||||
|
||||
virtual void operator()(xact_t& xact);
|
||||
virtual void set_details(entry_t& entry, xact_t& xact) {
|
||||
if (xact.entry->code)
|
||||
entry.payee = *xact.entry->code;
|
||||
else
|
||||
entry.payee = "<none>";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_payee_as_account : public transfer_details
|
||||
{
|
||||
account_t * master;
|
||||
|
||||
set_payee_as_account();
|
||||
|
||||
public:
|
||||
set_payee_as_account(xact_handler_ptr handler,
|
||||
account_t * _master)
|
||||
: transfer_details(handler), master(_master) {
|
||||
TRACE_CTOR(set_payee_as_account, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_payee_as_account() {
|
||||
TRACE_DTOR(set_payee_as_account);
|
||||
}
|
||||
|
||||
virtual void set_details(entry_t& entry, xact_t& xact) {
|
||||
xact.account = master->find_account(entry.payee);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_comm_as_account : public transfer_details
|
||||
{
|
||||
account_t * master;
|
||||
|
||||
set_comm_as_account();
|
||||
|
||||
public:
|
||||
set_comm_as_account(xact_handler_ptr handler,
|
||||
account_t * _master)
|
||||
: transfer_details(handler), master(_master) {
|
||||
TRACE_CTOR(set_comm_as_account, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_comm_as_account() {
|
||||
TRACE_DTOR(set_comm_as_account);
|
||||
}
|
||||
|
||||
virtual void set_details(entry_t&, xact_t& xact) {
|
||||
xact.account = master->find_account(xact.amount.commodity().symbol());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
* Long.
|
||||
*/
|
||||
class set_code_as_account : public transfer_details
|
||||
{
|
||||
account_t * master;
|
||||
|
||||
set_code_as_account();
|
||||
|
||||
public:
|
||||
set_code_as_account(xact_handler_ptr handler,
|
||||
account_t * _master)
|
||||
: transfer_details(handler), master(_master) {
|
||||
TRACE_CTOR(set_code_as_account, "xact_handler_ptr");
|
||||
}
|
||||
virtual ~set_code_as_account() {
|
||||
TRACE_DTOR(set_code_as_account);
|
||||
}
|
||||
|
||||
virtual void set_details(entry_t& entry, xact_t& xact) {
|
||||
xact.account = master->find_account(entry.code ? *entry.code : "<none>");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -381,9 +381,11 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
|||
else OPT(csv_format_);
|
||||
else OPT(cleared);
|
||||
else OPT(code_as_payee);
|
||||
else OPT_ALT(comm_as_payee, commodity_as_payee);
|
||||
else OPT(code_as_account);
|
||||
else OPT_ALT(comm_as_account, commodity_as_account);
|
||||
else OPT(collapse);
|
||||
else OPT(collapse_if_zero);
|
||||
else OPT(comm_as_payee);
|
||||
else OPT(cost);
|
||||
else OPT_(current);
|
||||
break;
|
||||
|
|
@ -441,6 +443,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
|||
break;
|
||||
case 'p':
|
||||
OPT(pager_);
|
||||
else OPT(payee_as_account);
|
||||
else OPT(pending);
|
||||
else OPT(percentage);
|
||||
else OPT(performance);
|
||||
|
|
|
|||
|
|
@ -248,6 +248,9 @@ public:
|
|||
});
|
||||
|
||||
OPTION(report_t, code_as_payee);
|
||||
OPTION(report_t, comm_as_payee); // -x
|
||||
OPTION(report_t, code_as_account);
|
||||
OPTION(report_t, comm_as_account);
|
||||
|
||||
OPTION_(report_t, collapse, DO() { // -n
|
||||
// Make sure that balance reports are collapsed too, but only apply it
|
||||
|
|
@ -259,7 +262,6 @@ public:
|
|||
parent->HANDLER(collapse).on();
|
||||
});
|
||||
|
||||
OPTION(report_t, comm_as_payee); // -x
|
||||
OPTION(report_t, cost);
|
||||
OPTION(report_t, csv_format_);
|
||||
OPTION(report_t, current); // -c
|
||||
|
|
@ -381,6 +383,7 @@ public:
|
|||
|
||||
OPTION(report_t, output_); // -o
|
||||
OPTION(report_t, pager_);
|
||||
OPTION(report_t, payee_as_account);
|
||||
|
||||
OPTION_(report_t, pending, DO() { // -C
|
||||
parent->HANDLER(limit_).append("pending");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue