summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
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();
}