Restored the "prices" command.
This commit is contained in:
parent
c328b1b3b2
commit
8ee8af3bfb
6 changed files with 117 additions and 14 deletions
|
|
@ -276,7 +276,6 @@ public:
|
|||
base->larger = arg;
|
||||
}
|
||||
|
||||
protected:
|
||||
optional<varied_history_t&> varied_history() {
|
||||
if (base->varied_history)
|
||||
return *base->varied_history;
|
||||
|
|
|
|||
|
|
@ -72,6 +72,72 @@ xact_t * journal_xacts_iterator::operator()()
|
|||
return xact;
|
||||
}
|
||||
|
||||
void xacts_commodities_iterator::reset(journal_t& journal)
|
||||
{
|
||||
journal_xacts.reset(journal);
|
||||
|
||||
std::set<commodity_t *> commodities;
|
||||
|
||||
for (xact_t * xact = journal_xacts(); xact; xact = journal_xacts()) {
|
||||
commodity_t& comm(xact->amount.commodity());
|
||||
if (comm.flags() & COMMODITY_NOMARKET)
|
||||
continue;
|
||||
commodities.insert(&comm);
|
||||
}
|
||||
|
||||
foreach (commodity_t * comm, commodities) {
|
||||
optional<commodity_t::varied_history_t&> history = comm->varied_history();
|
||||
if (! history)
|
||||
continue;
|
||||
|
||||
entry_temps.push_back(new entry_t);
|
||||
entry_temps.back()->payee = comm->symbol();
|
||||
entry_temps.back()->_date = CURRENT_DATE();
|
||||
|
||||
foreach (commodity_t::base_t::history_by_commodity_map::value_type pair,
|
||||
history->histories) {
|
||||
commodity_t& price_comm(*pair.first);
|
||||
commodity_t::history_t& price_hist(pair.second);
|
||||
|
||||
acct_temps.push_back(account_t(NULL, price_comm.symbol()));
|
||||
|
||||
foreach (commodity_t::base_t::history_map::value_type hpair,
|
||||
price_hist.prices) {
|
||||
xact_temps.push_back(xact_t(&acct_temps.back()));
|
||||
xact_t& temp = xact_temps.back();
|
||||
temp._date = hpair.first.date();
|
||||
temp.entry = entry_temps.back();
|
||||
temp.amount = hpair.second;
|
||||
temp.set_flags(ITEM_GENERATED | ITEM_TEMP);
|
||||
|
||||
entry_temps.back()->add_xact(&temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entries.entries_i = entry_temps.begin();
|
||||
entries.entries_end = entry_temps.end();
|
||||
|
||||
entries.entries_uninitialized = false;
|
||||
|
||||
entry_t * entry = entries();
|
||||
if (entry != NULL)
|
||||
xacts.reset(*entry);
|
||||
}
|
||||
|
||||
xact_t * xacts_commodities_iterator::operator()()
|
||||
{
|
||||
xact_t * xact = xacts();
|
||||
if (xact == NULL) {
|
||||
entry_t * entry = entries();
|
||||
if (entry != NULL) {
|
||||
xacts.reset(*entry);
|
||||
xact = xacts();
|
||||
}
|
||||
}
|
||||
return xact;
|
||||
}
|
||||
|
||||
account_t * basic_accounts_iterator::operator()()
|
||||
{
|
||||
while (! accounts_i.empty() &&
|
||||
|
|
|
|||
|
|
@ -110,12 +110,12 @@ public:
|
|||
*/
|
||||
class entries_iterator : public noncopyable
|
||||
{
|
||||
public:
|
||||
entries_list::iterator entries_i;
|
||||
entries_list::iterator entries_end;
|
||||
|
||||
bool entries_uninitialized;
|
||||
|
||||
public:
|
||||
entries_iterator() : entries_uninitialized(true) {
|
||||
TRACE_CTOR(entries_iterator, "");
|
||||
}
|
||||
|
|
@ -159,6 +159,41 @@ public:
|
|||
virtual xact_t * operator()();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
* Long.
|
||||
*/
|
||||
class xacts_commodities_iterator : public xacts_iterator
|
||||
{
|
||||
protected:
|
||||
journal_xacts_iterator journal_xacts;
|
||||
entries_iterator entries;
|
||||
entry_xacts_iterator xacts;
|
||||
|
||||
std::list<xact_t> xact_temps;
|
||||
std::list<account_t> acct_temps;
|
||||
entries_list entry_temps;
|
||||
|
||||
public:
|
||||
xacts_commodities_iterator() {
|
||||
TRACE_CTOR(xacts_commodities_iterator, "");
|
||||
}
|
||||
xacts_commodities_iterator(journal_t& journal) {
|
||||
TRACE_CTOR(xacts_commodities_iterator, "journal_t&");
|
||||
reset(journal);
|
||||
}
|
||||
virtual ~xacts_commodities_iterator() throw() {
|
||||
TRACE_DTOR(xacts_commodities_iterator);
|
||||
foreach (entry_t * entry, entry_temps)
|
||||
checked_delete(entry);
|
||||
}
|
||||
|
||||
void reset(journal_t& journal);
|
||||
|
||||
virtual xact_t * operator()();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Brief
|
||||
*
|
||||
|
|
|
|||
|
|
@ -78,10 +78,9 @@ report_t::report_t(session_t& _session)
|
|||
HANDLER(plot_amount_format_).on("%D %(S(t))\n");
|
||||
HANDLER(plot_total_format_).on("%D %(S(T))\n");
|
||||
|
||||
HANDLER(write_hdr_format_).on("%d %Y%C%P\n");
|
||||
HANDLER(write_xact_format_).on(" %-34W %12o%n\n");
|
||||
|
||||
HANDLER(prices_format_).on("%[%Y/%m/%d %H:%M:%S %Z] %-10A %12t %12T\n");
|
||||
HANDLER(prices_format_).on(
|
||||
"%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n%/"
|
||||
"%21|%-.9(date) %-.10(payee) %-10(account) %12(strip(display_amount))\n");
|
||||
HANDLER(pricesdb_format_).on("P %[%Y/%m/%d %H:%M:%S] %A %t\n");
|
||||
|
||||
HANDLER(csv_format_).on(
|
||||
|
|
@ -140,8 +139,11 @@ void report_t::accounts_report(acct_handler_ptr handler)
|
|||
session.clean_accounts();
|
||||
}
|
||||
|
||||
void report_t::commodities_report(const string& format)
|
||||
void report_t::commodities_report(xact_handler_ptr handler)
|
||||
{
|
||||
xacts_commodities_iterator walker(*session.journal.get());
|
||||
pass_down_xacts(chain_xact_handlers(*this, handler), walker);
|
||||
session.clean_xacts();
|
||||
}
|
||||
|
||||
value_t report_t::fn_amount_expr(call_scope_t& scope)
|
||||
|
|
@ -474,8 +476,6 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
|||
OPT(weekly);
|
||||
else OPT_(wide);
|
||||
else OPT(wide_register_format_);
|
||||
else OPT(write_hdr_format_);
|
||||
else OPT(write_xact_format_);
|
||||
break;
|
||||
case 'x':
|
||||
OPT_CH(comm_as_payee);
|
||||
|
|
@ -536,9 +536,13 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
|
|||
(reporter<>(new format_xacts(*this, HANDLER(print_format_).str()),
|
||||
*this));
|
||||
else if (is_eq(p, "prices"))
|
||||
return NULL; // jww (2009-02-07): NYI
|
||||
return expr_t::op_t::wrap_functor
|
||||
(reporter<xact_t, xact_handler_ptr, &report_t::commodities_report>
|
||||
(new format_xacts(*this, HANDLER(prices_format_).str()), *this));
|
||||
else if (is_eq(p, "pricesdb"))
|
||||
return NULL; // jww (2009-02-07): NYI
|
||||
return expr_t::op_t::wrap_functor
|
||||
(reporter<xact_t, xact_handler_ptr, &report_t::commodities_report>
|
||||
(new format_xacts(*this, HANDLER(pricesdb_format_).str()), *this));
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public:
|
|||
void xacts_report(xact_handler_ptr handler);
|
||||
void entry_report(xact_handler_ptr handler, entry_t& entry);
|
||||
void accounts_report(acct_handler_ptr handler);
|
||||
void commodities_report(const string& format);
|
||||
void commodities_report(xact_handler_ptr handler);
|
||||
|
||||
void sum_all_accounts();
|
||||
|
||||
|
|
@ -394,8 +394,6 @@ public:
|
|||
OPTION(report_t, weekly); // -W
|
||||
OPTION(report_t, wide); // -w
|
||||
OPTION(report_t, wide_register_format_);
|
||||
OPTION(report_t, write_hdr_format_);
|
||||
OPTION(report_t, write_xact_format_);
|
||||
OPTION(report_t, yearly); // -Y
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue