This commit is contained in:
John Wiegley 2004-06-30 02:09:42 -04:00 committed by johnw
parent 1a5390243e
commit f9c4f85870
5 changed files with 60 additions and 43 deletions

View file

@ -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

7
NEWS
View file

@ -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

View file

@ -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 street_balance;
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 = 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()

View file

@ -237,8 +237,9 @@ class totals
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,
totals * value() const;
totals * street(std::time_t * when = NULL,
bool use_history = false,
bool download = false) const;
};

View file

@ -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),
} 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;