summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--NEWS7
-rw-r--r--ledger.cc26
-rw-r--r--ledger.h17
-rw-r--r--reports.cc47
5 files changed, 60 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index fc432c46..cae7c23e 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/NEWS b/NEWS
index 1b5efebf..e0f5ce49 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/ledger.cc b/ledger.cc
index 5f5326a4..4985fba6 100644
--- a/ledger.cc
+++ b/ledger.cc
@@ -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()
diff --git a/ledger.h b/ledger.h
index d86c0107..6a98eb62 100644
--- a/ledger.h
+++ b/ledger.h
@@ -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;
};
diff --git a/reports.cc b/reports.cc
index c8738b84..e5ce610d 100644
--- a/reports.cc
+++ b/reports.cc
@@ -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;