diff options
author | John Wiegley <johnw@newartisans.com> | 2004-06-30 02:09:42 -0400 |
---|---|---|
committer | johnw <johnw@newartisans.com> | 2004-06-30 02:09:42 -0400 |
commit | f9c4f85870a03722953e950ef27f01a44a911c4d (patch) | |
tree | a91816410bbbc746df5eef6f88ca118f0aa7dda1 | |
parent | 1a5390243edf87b21e7bba0568150d50e3f10d5a (diff) | |
download | fork-ledger-f9c4f85870a03722953e950ef27f01a44a911c4d.tar.gz fork-ledger-f9c4f85870a03722953e950ef27f01a44a911c4d.tar.bz2 fork-ledger-f9c4f85870a03722953e950ef27f01a44a911c4d.zip |
fixes
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | ledger.cc | 26 | ||||
-rw-r--r-- | ledger.h | 17 | ||||
-rw-r--r-- | reports.cc | 47 |
5 files changed, 60 insertions, 43 deletions
@@ -2,9 +2,9 @@ CODE = amount.cc ledger.cc parse.cc reports.cc OBJS = $(patsubst %.cc,%.o,$(CODE)) #CXX = cc CXX = g++ -CFLAGS = #-Wall -ansi -pedantic -DFLAGS = -O3 -fomit-frame-pointer -#DFLAGS = -g -DDEBUG=1 +CFLAGS = -Wall -ansi -pedantic +#DFLAGS = -O3 -fomit-frame-pointer +DFLAGS = -g -DDEBUG=1 INCS = -I/sw/include -I/usr/include/gcc/darwin/3.3/c++ -I/usr/include/gcc/darwin/3.3/c++/ppc-darwin LIBS = -L/sw/lib -lgmpxx -lgmp -lpcre @@ -1,3 +1,10 @@ +1.7 + + Pricing histories are now supported, so that ledger remembers + historical prices of all commodities (if this information is + provided), and can give register reports based on past and present + market values, as well as original cost basis. + 1.6 Can now parse timeclock files. These are simple timelogs that track @@ -447,21 +447,37 @@ void totals::print(std::ostream& out, int width) const } } -void totals::print_street(std::ostream& out, int width, std::time_t * when, - bool use_history, bool download) const +totals * totals::value() const +{ + totals * cost_basis = new totals; + + for (const_iterator i = amounts.begin(); i != amounts.end(); i++) { + if ((*i).second->is_zero()) + continue; + + amount * value = (*i).second->value(); + cost_basis->credit(value); + delete value; + } + + return cost_basis; +} + +totals * totals::street(std::time_t * when, bool use_history, + bool download) const { - totals street_balance; + totals * street_balance = new totals; for (const_iterator i = amounts.begin(); i != amounts.end(); i++) { if ((*i).second->is_zero()) continue; amount * street = (*i).second->street(when, use_history, download); - street_balance.credit(street); + street_balance->credit(street); delete street; } - street_balance.print(out, width); + return street_balance; } account::~account() @@ -228,17 +228,18 @@ class totals totals() {} ~totals(); - void credit(const amount * val); - void credit(const totals& other); + void credit(const amount * val); + void credit(const totals& other); - void negate(); + void negate(); - bool is_zero() const; - bool is_negative() const; + bool is_zero() const; + bool is_negative() const; - void print(std::ostream& out, int width) const; - void print_street(std::ostream& out, int width, - std::time_t * when = NULL, + void print(std::ostream& out, int width) const; + + totals * value() const; + totals * street(std::time_t * when = NULL, bool use_history = false, bool download = false) const; }; @@ -134,12 +134,15 @@ static inline void print_resolved_balance(std::ostream& out, totals& balance, bool added_base_value = false) { - if (! added_base_value || ! use_history || cost_basis) + if (! added_base_value || ! use_history || cost_basis) { balance.print(out, 12); - else - balance.print_street(out, 12, - when ? when : (have_ending ? &end_date : NULL), - use_history, get_quotes); + } else { + totals * street = balance.street(when ? when : (have_ending ? + &end_date : NULL), + use_history, get_quotes); + street->print(out, 12); + delete street; + } } ////////////////////////////////////////////////////////////////////// @@ -409,22 +412,6 @@ enum periodicity_t { PERIOD_WEEKLY_MON }; -static totals * compute_street_balance(totals& balance, std::time_t * date) -{ - totals * prev_street_balance = new totals; - - for (totals::const_iterator i = balance.amounts.begin(); - i != balance.amounts.end(); - i++) - if (! (*i).second->is_zero()) { - amount * street = (*i).second->street(date, use_history, get_quotes); - prev_street_balance->credit(street); - delete street; - } - - return prev_street_balance; -} - static totals * prev_balance = NULL; static std::time_t prev_date; @@ -435,9 +422,9 @@ static void report_change_in_asset_value(std::ostream& out, std::time_t date, account * acct, totals& balance) { totals * prev_street_balance = - compute_street_balance(*prev_balance, &prev_date); + prev_balance->street(&prev_date, use_history, get_quotes); totals * curr_street_balance = - compute_street_balance(*prev_balance, &date); + prev_balance->street(&date, use_history, get_quotes); delete prev_balance; prev_balance = NULL; @@ -634,8 +621,7 @@ void print_register(std::ostream& out, const std::string& acct_name, if (period_sum && period == PERIOD_MONTHLY && last_mon != -1 && entry_mon != last_mon) { assert(last_acct); - print_register_period(out, last_date, last_acct, - *period_sum, balance); + print_register_period(out, last_date, last_acct, *period_sum, balance); delete period_sum; period_sum = NULL; } @@ -650,8 +636,8 @@ void print_register(std::ostream& out, const std::string& acct_name, if (period == PERIOD_NONE) { print_register_transaction(out, *i, *x, balance); } else { - amount * street = resolve_amount((*x)->cost, &(*i)->date, - &balance, true); + amount * street = resolve_amount((*x)->cost, &(*i)->date, &balance, + true); if (period_sum) { period_sum->credit(street); delete street; @@ -1131,6 +1117,13 @@ int main(int argc, char * argv[]) int name_index = index; if (command == "register" || command == "reg") { + if (net_gain) { + std::cerr << ("Reporting the asset gain makes " + "no sense for the register report.") + << std::endl; + return 1; + } + if (name_index == argc) { std::cerr << ("Error: Must specify an account name " "after the 'register' command.") << std::endl; |