diff options
author | John Wiegley <johnw@newartisans.com> | 2008-09-14 19:38:44 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-09-14 19:38:44 -0400 |
commit | 7d1809cb15b1ebea4d96341ae0e5fc655487788a (patch) | |
tree | fa56bc87e3798b5529640075885271b8fa02f359 /src/textual.cc | |
parent | 0135c28049839c2db25351b8d8114f9f31649afc (diff) | |
download | ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.tar.gz ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.tar.bz2 ledger-7d1809cb15b1ebea4d96341ae0e5fc655487788a.zip |
Transactional assignments (i.e., confirmed balances) are working now.
Diffstat (limited to 'src/textual.cc')
-rw-r--r-- | src/textual.cc | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/textual.cc b/src/textual.cc index c3ca3895..cc941695 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -313,71 +313,78 @@ xact_t * parse_xact(char * line, account_t * account, entry_t * entry = NULL) DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Found a balance assignment indicator"); if (in.good() && ! in.eof()) { - amount_t amt; + xact->assigned_amount = amount_t(); try { istream_pos_type beg = in.tellg(); - optional<expr_t> total_expr = - parse_amount_expr(in, amt, xact.get(), EXPR_PARSE_NO_MIGRATE); + xact->assigned_amount_expr = + parse_amount_expr(in, *xact->assigned_amount, xact.get(), + EXPR_PARSE_NO_MIGRATE); - if (amt.is_null()) + if (xact->assigned_amount->is_null()) throw parse_error ("An assigned balance must evaluate to a constant value"); DEBUG("ledger.textual.parse", "line " << linenum << ": " << - "XACT assign: parsed amt = " << amt); + "XACT assign: parsed amt = " << *xact->assigned_amount); - if (total_expr) { + if (xact->assigned_amount_expr) { istream_pos_type end = in.tellg(); - total_expr->set_text(string("=") + - string(line, long(beg), long(end - beg))); + xact->assigned_amount_expr->set_text + (string("=") + string(line, long(beg), long(end - beg))); } - // jww (2008-08-02): Save total_expr somewhere! - account_t::xdata_t& xdata(xact->account->xdata()); + amount_t& amt(*xact->assigned_amount); - DEBUG("ledger.xact.assign", "account balance = " << xdata.value); - DEBUG("ledger.xact.assign", "xact amount = " << amt); + DEBUG("xact.assign", + "account balance = " << xdata.value.strip_annotations()); + DEBUG("xact.assign", + "xact amount = " << amt.strip_annotations()); amount_t diff; if (xdata.value.is_amount()) { diff = amt - xdata.value.as_amount(); } else if (xdata.value.is_balance()) { - optional<amount_t> comm_bal = - xdata.value.as_balance().commodity_amount(amt.commodity()); - diff = amt - (comm_bal ? *comm_bal : amount_t(0L)); + if (optional<amount_t> comm_bal = + xdata.value.as_balance().commodity_amount(amt.commodity())) + diff = amt - *comm_bal; + else + diff = amt; } else if (xdata.value.is_balance_pair()) { - optional<amount_t> comm_bal = - xdata.value.as_balance_pair().commodity_amount(amt.commodity()); - diff = amt - (comm_bal ? *comm_bal : amount_t(0L)); + if (optional<amount_t> comm_bal = + xdata.value.as_balance_pair().commodity_amount(amt.commodity())) + diff = amt - *comm_bal; + else + diff = amt; } else { diff = amt; } - DEBUG("ledger.xact.assign", "diff = " << diff); + DEBUG("xact.assign", "diff = " << diff.strip_annotations()); DEBUG("ledger.textual.parse", "line " << linenum << ": " << - "XACT assign: diff = " << diff); + "XACT assign: diff = " << diff.strip_annotations()); - if (! diff.is_realzero()) { + if (! diff.is_zero()) { if (! xact->amount.is_null()) { - xact_t * temp = - new xact_t(xact->account, diff, - XACT_GENERATED | XACT_CALCULATED); - entry->add_xact(temp); - - DEBUG("ledger.textual.parse", "line " << linenum << ": " << - "Created balancing transaction"); + diff -= xact->amount; + if (! diff.is_zero()) { + xact_t * temp = new xact_t(xact->account, diff, + XACT_GENERATED | XACT_CALCULATED); + entry->add_xact(temp); + + DEBUG("ledger.textual.parse", "line " << linenum << ": " << + "Created balancing transaction"); + } } else { xact->amount = diff; DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Overwrite null transaction"); } - xdata.value = amt; } } catch (const std::exception& err) { |