From 0a6b5726ec3bf402a953ea8a03b98ecbf4b90b0c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 19 Apr 2007 20:31:46 +0000 Subject: Made the amount/balance/value interface a bit more rational; added back a useless version of the register command (just to prove the command sequence); and added smart XML semantics to the XPath implementation so that nodes can be coerced to values. --- journal.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'journal.cc') diff --git a/journal.cc b/journal.cc index 0b9f3909..1bf31dd6 100644 --- a/journal.cc +++ b/journal.cc @@ -124,7 +124,7 @@ bool entry_base_t::finalize() ann_comm(static_cast ((*x)->amount.commodity())); if (ann_comm.price) - balance += ann_comm.price * (*x)->amount - *((*x)->cost); + balance += ann_comm.price * (*x)->amount.number() - *((*x)->cost); } } else { saw_null = true; @@ -165,7 +165,7 @@ bool entry_base_t::finalize() other_bal++; amount_t per_unit_cost = - amount_t((*other_bal).second / (*this_bal).second).unround(); + amount_t((*other_bal).second / (*this_bal).second.number()).unround(); for (; x != transactions.end(); x++) { if ((*x)->cost || ((*x)->flags & TRANSACTION_VIRTUAL) || @@ -180,11 +180,11 @@ bool entry_base_t::finalize() if ((*x)->amount.commodity() && ! (*x)->amount.commodity().annotated) (*x)->amount.annotate_commodity - (abs(per_unit_cost), + (per_unit_cost.abs(), entry ? entry->actual_date() : ptime(), entry ? entry->code : ""); - (*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount)); + (*x)->cost = new amount_t(- (per_unit_cost * (*x)->amount.number())); balance += *(*x)->cost; } } @@ -228,8 +228,7 @@ bool entry_base_t::finalize() for (amounts_map::const_iterator i = bal->amounts.begin(); i != bal->amounts.end(); i++) { - amount_t amt = (*i).second; - amt.negate(); + amount_t amt = (*i).second.negate(); if (first) { (*x)->amount = amt; @@ -248,8 +247,7 @@ bool entry_base_t::finalize() // fall through... case value_t::AMOUNT: - (*x)->amount = *((amount_t *) balance.data); - (*x)->amount.negate(); + (*x)->amount = ((amount_t *) balance.data)->negate(); (*x)->flags |= TRANSACTION_CALCULATED; balance += (*x)->amount; @@ -552,7 +550,7 @@ bool journal_t::add_entry(entry_t * entry) i++) if ((*i)->cost && (*i)->amount) (*i)->amount.commodity().add_price(entry->date(), - *(*i)->cost / (*i)->amount); + *(*i)->cost / (*i)->amount.number()); return true; } -- cgit v1.2.3