summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-07 22:09:14 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-07 22:09:14 -0400
commit84fe84bbd2185d3bd997a3ebac99417f99376cfb (patch)
tree1060009564c8f08788bc28d665846189c8e03181
parent3bedc69b762dcf6e813eff51667d5c2dd62bc58b (diff)
downloadfork-ledger-84fe84bbd2185d3bd997a3ebac99417f99376cfb.tar.gz
fork-ledger-84fe84bbd2185d3bd997a3ebac99417f99376cfb.tar.bz2
fork-ledger-84fe84bbd2185d3bd997a3ebac99417f99376cfb.zip
equity reports are restored
-rw-r--r--format.h44
-rw-r--r--main.cc51
2 files changed, 89 insertions, 6 deletions
diff --git a/format.h b/format.h
index 649bb190..3077b739 100644
--- a/format.h
+++ b/format.h
@@ -207,6 +207,50 @@ class format_account
const bool report_top = false) const;
};
+
+class format_equity
+{
+ std::ostream& output_stream;
+ const format_t& first_line_format;
+ const format_t& next_lines_format;
+
+ item_predicate<account_t> disp_pred_functor;
+
+ mutable balance_t total;
+
+ public:
+ format_equity(std::ostream& _output_stream,
+ const format_t& _first_line_format,
+ const format_t& _next_lines_format,
+ const node_t * display_predicate = NULL)
+ : output_stream(_output_stream),
+ first_line_format(_first_line_format),
+ next_lines_format(_next_lines_format),
+ disp_pred_functor(display_predicate) {
+ entry_t header_entry;
+ header_entry.payee = "Opening Balances";
+ header_entry.date = std::time(NULL);
+ first_line_format.format_elements(output_stream, details_t(&header_entry));
+ }
+
+ ~format_equity() {
+ account_t summary(NULL, "Equity:Opening Balances");
+ summary.value = - total;
+ next_lines_format.format_elements(output_stream, details_t(&summary));
+ }
+
+ void operator()(account_t * account,
+ const unsigned int max_depth = 1,
+ const bool report_top = false) const {
+ if ((report_top || account->parent != NULL) &&
+ disp_pred_functor(account)) {
+ next_lines_format.format_elements(output_stream, details_t(account));
+ account->flags |= ACCOUNT_DISPLAYED;
+ total += account->value.quantity;
+ }
+ }
+};
+
} // namespace ledger
#endif // _REPORT_H
diff --git a/main.cc b/main.cc
index 73248450..5a8cd8b9 100644
--- a/main.cc
+++ b/main.cc
@@ -20,6 +20,9 @@ static const std::string reg_fmt
static const std::string print_fmt
= "\n%10d %X%C%p\n %-34N %12o\n%/ %-34N %12o\n";
+static const std::string equity_fmt
+ = "\n%10d %X%C%p\n%/ %-34N %12t\n";
+
void set_price_conversion(const std::string& setting)
{
@@ -575,8 +578,12 @@ int main(int argc, char * argv[])
predicate.reset(parse_expr(predicate_string));
}
- if (display_predicate_string.empty() && command == "b" && ! show_empty)
- display_predicate_string = "T";
+ if (! show_empty && display_predicate_string.empty()) {
+ if (command == "b")
+ display_predicate_string = "T";
+ else if (command == "E")
+ display_predicate_string = "a";
+ }
if (! display_predicate_string.empty()) {
#ifdef DEBUG
@@ -601,10 +608,13 @@ int main(int argc, char * argv[])
unsigned int xact_display_flags = MATCHING_TRANSACTIONS;
- if (command == "p" || command == "e" || command == "E") {
+ if (command == "p" || command == "e") {
xact_display_flags |= OTHER_TRANSACTIONS;
show_expanded = true;
}
+ else if (command == "E") {
+ show_expanded = true;
+ }
else if (show_related) {
if (command == "r") {
xact_display_flags = OTHER_TRANSACTIONS;
@@ -621,6 +631,8 @@ int main(int argc, char * argv[])
f = bal_fmt.c_str();
else if (command == "r")
f = reg_fmt.c_str();
+ else if (command == "E")
+ f = equity_fmt.c_str();
else
f = print_fmt.c_str();
@@ -638,7 +650,27 @@ int main(int argc, char * argv[])
format_account(std::cout, format)(journal->master, true,
display_predicate.get());
}
- } else {
+ }
+ else if (command == "E") {
+ std::string first_line_format;
+ std::string next_lines_format;
+
+ if (const char * p = std::strstr(f, "%/")) {
+ first_line_format = std::string(f, 0, p - f);
+ next_lines_format = std::string(p + 2);
+ } else {
+ first_line_format = next_lines_format = f;
+ }
+
+ format_t format(first_line_format);
+ format_t nformat(next_lines_format);
+
+ format_equity formatter(std::cout, format, nformat,
+ display_predicate.get());
+ walk_accounts(journal->master, formatter, predicate.get(),
+ xact_display_flags, true, 0, sort_order.get());
+ }
+ else {
std::string first_line_format;
std::string next_lines_format;
@@ -675,8 +707,15 @@ int main(int argc, char * argv[])
xact_display_flags);
std::stable_sort(transactions_pool.begin(), transactions_pool.end(),
compare_items<transaction_t>(sort_order.get()));
- walk_transactions(transactions_pool.begin(), transactions_pool.end(),
- formatter);
+ if (show_commodities_revalued) {
+ changed_value_filter<format_transaction>
+ filtered_formatter(formatter);
+ walk_transactions(transactions_pool.begin(), transactions_pool.end(),
+ filtered_formatter);
+ } else {
+ walk_transactions(transactions_pool.begin(), transactions_pool.end(),
+ formatter);
+ }
}
}