fixes
This commit is contained in:
parent
1a5390243e
commit
f9c4f85870
5 changed files with 60 additions and 43 deletions
6
Makefile
6
Makefile
|
|
@ -2,9 +2,9 @@ CODE = amount.cc ledger.cc parse.cc reports.cc
|
||||||
OBJS = $(patsubst %.cc,%.o,$(CODE))
|
OBJS = $(patsubst %.cc,%.o,$(CODE))
|
||||||
#CXX = cc
|
#CXX = cc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
CFLAGS = #-Wall -ansi -pedantic
|
CFLAGS = -Wall -ansi -pedantic
|
||||||
DFLAGS = -O3 -fomit-frame-pointer
|
#DFLAGS = -O3 -fomit-frame-pointer
|
||||||
#DFLAGS = -g -DDEBUG=1
|
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
|
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
|
LIBS = -L/sw/lib -lgmpxx -lgmp -lpcre
|
||||||
|
|
||||||
|
|
|
||||||
7
NEWS
7
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
|
1.6
|
||||||
|
|
||||||
Can now parse timeclock files. These are simple timelogs that track
|
Can now parse timeclock files. These are simple timelogs that track
|
||||||
|
|
|
||||||
26
ledger.cc
26
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,
|
totals * totals::value() const
|
||||||
bool use_history, bool download) 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++) {
|
for (const_iterator i = amounts.begin(); i != amounts.end(); i++) {
|
||||||
if ((*i).second->is_zero())
|
if ((*i).second->is_zero())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
amount * street = (*i).second->street(when, use_history, download);
|
amount * street = (*i).second->street(when, use_history, download);
|
||||||
street_balance.credit(street);
|
street_balance->credit(street);
|
||||||
delete street;
|
delete street;
|
||||||
}
|
}
|
||||||
|
|
||||||
street_balance.print(out, width);
|
return street_balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
account::~account()
|
account::~account()
|
||||||
|
|
|
||||||
17
ledger.h
17
ledger.h
|
|
@ -228,17 +228,18 @@ class totals
|
||||||
totals() {}
|
totals() {}
|
||||||
~totals();
|
~totals();
|
||||||
|
|
||||||
void credit(const amount * val);
|
void credit(const amount * val);
|
||||||
void credit(const totals& other);
|
void credit(const totals& other);
|
||||||
|
|
||||||
void negate();
|
void negate();
|
||||||
|
|
||||||
bool is_zero() const;
|
bool is_zero() const;
|
||||||
bool is_negative() const;
|
bool is_negative() const;
|
||||||
|
|
||||||
void print(std::ostream& out, int width) 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 use_history = false,
|
||||||
bool download = false) const;
|
bool download = false) const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
47
reports.cc
47
reports.cc
|
|
@ -134,12 +134,15 @@ static inline void print_resolved_balance(std::ostream& out,
|
||||||
totals& balance,
|
totals& balance,
|
||||||
bool added_base_value = false)
|
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);
|
balance.print(out, 12);
|
||||||
else
|
} else {
|
||||||
balance.print_street(out, 12,
|
totals * street = balance.street(when ? when : (have_ending ?
|
||||||
when ? when : (have_ending ? &end_date : NULL),
|
&end_date : NULL),
|
||||||
use_history, get_quotes);
|
use_history, get_quotes);
|
||||||
|
street->print(out, 12);
|
||||||
|
delete street;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -409,22 +412,6 @@ enum periodicity_t {
|
||||||
PERIOD_WEEKLY_MON
|
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 totals * prev_balance = NULL;
|
||||||
static std::time_t prev_date;
|
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)
|
account * acct, totals& balance)
|
||||||
{
|
{
|
||||||
totals * prev_street_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 =
|
totals * curr_street_balance =
|
||||||
compute_street_balance(*prev_balance, &date);
|
prev_balance->street(&date, use_history, get_quotes);
|
||||||
|
|
||||||
delete prev_balance;
|
delete prev_balance;
|
||||||
prev_balance = NULL;
|
prev_balance = NULL;
|
||||||
|
|
@ -634,8 +621,7 @@ void print_register(std::ostream& out, const std::string& acct_name,
|
||||||
if (period_sum && period == PERIOD_MONTHLY &&
|
if (period_sum && period == PERIOD_MONTHLY &&
|
||||||
last_mon != -1 && entry_mon != last_mon) {
|
last_mon != -1 && entry_mon != last_mon) {
|
||||||
assert(last_acct);
|
assert(last_acct);
|
||||||
print_register_period(out, last_date, last_acct,
|
print_register_period(out, last_date, last_acct, *period_sum, balance);
|
||||||
*period_sum, balance);
|
|
||||||
delete period_sum;
|
delete period_sum;
|
||||||
period_sum = NULL;
|
period_sum = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -650,8 +636,8 @@ void print_register(std::ostream& out, const std::string& acct_name,
|
||||||
if (period == PERIOD_NONE) {
|
if (period == PERIOD_NONE) {
|
||||||
print_register_transaction(out, *i, *x, balance);
|
print_register_transaction(out, *i, *x, balance);
|
||||||
} else {
|
} else {
|
||||||
amount * street = resolve_amount((*x)->cost, &(*i)->date,
|
amount * street = resolve_amount((*x)->cost, &(*i)->date, &balance,
|
||||||
&balance, true);
|
true);
|
||||||
if (period_sum) {
|
if (period_sum) {
|
||||||
period_sum->credit(street);
|
period_sum->credit(street);
|
||||||
delete street;
|
delete street;
|
||||||
|
|
@ -1131,6 +1117,13 @@ int main(int argc, char * argv[])
|
||||||
|
|
||||||
int name_index = index;
|
int name_index = index;
|
||||||
if (command == "register" || command == "reg") {
|
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) {
|
if (name_index == argc) {
|
||||||
std::cerr << ("Error: Must specify an account name "
|
std::cerr << ("Error: Must specify an account name "
|
||||||
"after the 'register' command.") << std::endl;
|
"after the 'register' command.") << std::endl;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue