diff options
-rw-r--r-- | src/chain.cc | 6 | ||||
-rw-r--r-- | src/filters.cc | 35 | ||||
-rw-r--r-- | src/filters.h | 147 | ||||
-rw-r--r-- | src/report.cc | 5 | ||||
-rw-r--r-- | src/report.h | 5 |
5 files changed, 143 insertions, 55 deletions
diff --git a/src/chain.cc b/src/chain.cc index aa5ef0ab..64881c6f 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -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; } diff --git a/src/filters.cc b/src/filters.cc index 9fa97330..65fa92db 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -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); } diff --git a/src/filters.h b/src/filters.h index 2343ed8b..7335d817 100644 --- a/src/filters.h +++ b/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,24 +635,52 @@ 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; + transfer_details(); + +public: + transfer_details(xact_handler_ptr handler) + : item_handler<xact_t>(handler) { + TRACE_CTOR(transfer_details, "xact_handler_ptr"); + } + 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); +}; + +/** + * @brief Brief + * + * Long. + */ +class set_comm_as_payee : public transfer_details +{ set_comm_as_payee(); public: set_comm_as_payee(xact_handler_ptr handler) - : item_handler<xact_t>(handler) { + : transfer_details(handler) { TRACE_CTOR(set_comm_as_payee, "xact_handler_ptr"); } virtual ~set_comm_as_payee() { TRACE_DTOR(set_comm_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.amount.commodity()) + entry.payee = xact.amount.commodity().symbol(); + else + entry.payee = "<none>"; + } }; /** @@ -662,24 +688,103 @@ public: * * Long. */ -class set_code_as_payee : public item_handler<xact_t> +class set_code_as_payee : public transfer_details { - std::list<entry_t> entry_temps; - std::list<xact_t> xact_temps; - 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>"); + } }; /** diff --git a/src/report.cc b/src/report.cc index 917c98f6..59286a91 100644 --- a/src/report.cc +++ b/src/report.cc @@ -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); diff --git a/src/report.h b/src/report.h index 63c92ebe..fc3afd3c 100644 --- a/src/report.h +++ b/src/report.h @@ -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"); |