summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-25 05:39:33 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-25 05:39:33 -0400
commit555c2d855fd6d80a418d772b19c46da91be5b0f6 (patch)
tree833c1f85e8dfce66d645f64c637bca1313e62155
parenta4d96f79bfd0d3f1faffcd46c223f63c12a00eb4 (diff)
downloadfork-ledger-555c2d855fd6d80a418d772b19c46da91be5b0f6.tar.gz
fork-ledger-555c2d855fd6d80a418d772b19c46da91be5b0f6.tar.bz2
fork-ledger-555c2d855fd6d80a418d772b19c46da91be5b0f6.zip
a couple of fixes to collapsed and subtotal reports
-rw-r--r--config.cc14
-rw-r--r--walk.cc30
2 files changed, 20 insertions, 24 deletions
diff --git a/config.cc b/config.cc
index 7150bc84..5a273b3d 100644
--- a/config.cc
+++ b/config.cc
@@ -582,24 +582,20 @@ OPT_BEGIN(gain, "G") {
} OPT_END(gain);
OPT_BEGIN(average, "A") {
- config.amount_expr = "a";
- config.total_expr = "MO";
+ config.total_expr = std::string("M") + config.total_expr;
} OPT_END(average);
OPT_BEGIN(deviation, "D") {
- config.amount_expr = "a";
- config.total_expr = "DMO";
+ config.total_expr = std::string("DM") + config.total_expr;
} OPT_END(deviation);
OPT_BEGIN(trend, "X") {
- config.amount_expr = "a";
- config.total_expr = "MDMO";
+ config.total_expr = std::string("MDM") + config.total_expr;
} OPT_END(trend);
OPT_BEGIN(weighted_trend, "Z") {
- config.amount_expr = "a";
- config.total_expr
- = "MD(MO/(1+(((m-d)/(30*86400))<0?0:((m-d)/(30*86400)))))";
+ config.total_expr = (std::string("MD(M(") + config.total_expr +
+ ")/(1+(((m-d)/(30*86400))<0?0:((m-d)/(30*86400)))))");
} OPT_END(weighted_trend);
} // namespace ledger
diff --git a/walk.cc b/walk.cc
index fa27d6bc..4469ac67 100644
--- a/walk.cc
+++ b/walk.cc
@@ -73,13 +73,13 @@ static void handle_value(const value_t& value,
xact.entry = entry;
switch (value.type) {
case value_t::BOOLEAN:
- xact.amount = *((bool *) value.data);
+ xact.amount = *((bool *) value.data);
break;
case value_t::INTEGER:
- xact.amount = *((unsigned int *) value.data);
+ xact.amount = *((unsigned int *) value.data);
break;
case value_t::AMOUNT:
- xact.amount = *((amount_t *) value.data);
+ xact.amount = *((amount_t *) value.data);
break;
default:
assert(0);
@@ -123,6 +123,15 @@ static void handle_value(const value_t& value,
}
}
+void determine_amount(value_t& result, balance_pair_t& bal_pair)
+{
+ account_xdata_t xdata;
+ xdata.value = bal_pair;
+ account_t temp_account;
+ temp_account.data = &xdata;
+ format_t::compute_amount(result, details_t(temp_account));
+}
+
void collapse_transactions::report_cumulative_subtotal()
{
if (count == 1) {
@@ -130,11 +139,8 @@ void collapse_transactions::report_cumulative_subtotal()
} else {
assert(count > 1);
- account_xdata_t xdata;
- xdata.total = subtotal;
value_t result;
- totals_account.data = &xdata;
- format_t::compute_total(result, details_t(totals_account));
+ determine_amount(result, subtotal);
handle_value(result, &totals_account, last_entry, 0, xact_temps, handler);
}
@@ -210,14 +216,8 @@ void subtotal_transactions::flush(const char * spec_fmt)
i != balances.end();
i++) {
entry.date = finish;
- {
- transaction_xdata_t xact_data;
- xact_data.total = (*i).second;
- transaction_t temp((*i).first);
- temp.entry = &entry;
- temp.data = &xact_data;
- format_t::compute_total(result, details_t(temp));
- }
+ value_t result;
+ determine_amount(result, (*i).second);
entry.date = start;
handle_value(result, (*i).first, &entry, 0, xact_temps, handler);