summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-06 15:35:16 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-06 15:35:16 -0500
commitf03d386013f220e5b88a056c514c20319c83e9e7 (patch)
tree107234c2ca0947fac84be819611ff5c0c610dac6 /src/xact.cc
parent312d4c5f5339c61253e86cd9ce825370eb4be053 (diff)
parent205639669981f1ab9dc355d07c60c123c4da0ca0 (diff)
downloadfork-ledger-f03d386013f220e5b88a056c514c20319c83e9e7.tar.gz
fork-ledger-f03d386013f220e5b88a056c514c20319c83e9e7.tar.bz2
fork-ledger-f03d386013f220e5b88a056c514c20319c83e9e7.zip
Merge branch 'next'
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/xact.cc b/src/xact.cc
index 9e5f504e..67dad155 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -83,6 +83,20 @@ void xact_base_t::clear_xdata()
post->clear_xdata();
}
+value_t xact_base_t::magnitude() const
+{
+ value_t halfbal = 0L;
+ foreach (const post_t * post, posts) {
+ if (post->amount.sign() > 0) {
+ if (post->cost)
+ halfbal += *post->cost;
+ else
+ halfbal += post->amount;
+ }
+ }
+ return halfbal;
+}
+
bool xact_base_t::finalize()
{
// Scan through and compute the total balance for the xact. This is used
@@ -321,6 +335,8 @@ bool xact_base_t::finalize()
add_error_context(item_context(*this, _("While balancing transaction")));
add_error_context(_("Unbalanced remainder is:"));
add_error_context(value_context(balance));
+ add_error_context(_("Amount to balance against:"));
+ add_error_context(value_context(magnitude()));
throw_(balance_error, _("Transaction does not balance"));
}
@@ -368,26 +384,12 @@ void xact_t::add_post(post_t * post)
xact_base_t::add_post(post);
}
-value_t xact_t::magnitude() const
-{
- value_t halfbal = 0L;
- foreach (const post_t * post, posts) {
- if (post->amount.sign() > 0) {
- if (post->cost)
- halfbal += post->cost->number();
- else
- halfbal += post->amount.number();
- }
- }
- return halfbal;
-}
-
string xact_t::idstring() const
{
std::ostringstream buf;
buf << format_date(*_date, FMT_WRITTEN);
buf << payee;
- magnitude().print(buf);
+ magnitude().number().print(buf);
return buf.str();
}