summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--balance.cc34
-rw-r--r--main.cc16
-rw-r--r--register.cc14
-rwxr-xr-xreport4
4 files changed, 39 insertions, 29 deletions
diff --git a/balance.cc b/balance.cc
index e3b9e7ab..39b1e949 100644
--- a/balance.cc
+++ b/balance.cc
@@ -11,9 +11,10 @@ extern bool have_beginning;
extern std::time_t end_date;
extern bool have_ending;
-static bool show_children = false;
-static bool show_empty = false;
-static bool no_subtotals = false;
+static bool show_children;
+static bool show_empty;
+static bool no_subtotals;
+static bool full_names;
static void display_total(std::ostream& out, totals& total_balance,
const account * acct,
@@ -27,29 +28,30 @@ static void display_total(std::ostream& out, totals& total_balance,
if (balance && (show_empty || *balance)) {
bool match = true;
+ bool true_match = false;
if (! regexps.empty()) {
if (show_children) {
match = false;
for (const account * a = acct; a; a = a->parent) {
- if (matches(regexps, a->as_str())) {
- match = true;
+ if (matches(regexps, a->name)) {
+ match = true;
+ true_match = a == acct;
break;
}
}
} else {
- match = matches(regexps, acct->as_str());
+ match = matches(regexps, acct->as_str());
+ true_match = matches(regexps, acct->name);
}
}
if (match) {
out << *balance;
- // jww (2003-09-30): Don't check "! acct->parent", but simply
- // make sure this is the parent which matched the regexp.
- if (! show_children || ! acct->parent)
+ if (! acct->parent || true_match)
total_balance.credit(*balance);
- if (acct->parent && ! no_subtotals) {
+ if (acct->parent && ! no_subtotals && ! full_names) {
for (const account * a = acct; a; a = a->parent)
out << " ";
out << acct->name << std::endl;
@@ -75,13 +77,20 @@ static void display_total(std::ostream& out, totals& total_balance,
void report_balances(int argc, char **argv, std::ostream& out)
{
+ show_children = false;
+ show_empty = false;
+ no_subtotals = false;
+ full_names = false;
+
optind = 1;
+
int c;
- while (-1 != (c = getopt(argc, argv, "sSnG:"))) {
+ while (-1 != (c = getopt(argc, argv, "sSnFG:"))) {
switch (char(c)) {
case 's': show_children = true; break;
case 'S': show_empty = true; break;
case 'n': no_subtotals = true; break;
+ case 'F': full_names = true; break;
#ifdef HUQUQULLAH
case 'G': {
@@ -116,7 +125,8 @@ void report_balances(int argc, char **argv, std::ostream& out)
account * acct = (*x)->acct;
for (; acct; acct = no_subtotals ? NULL : acct->parent) {
- if (! show_children && acct->parent && regexps.empty())
+ if (! show_children && acct->parent &&
+ (regexps.empty() || ! matches(regexps, acct->name)))
continue;
totals * balance = NULL;
diff --git a/main.cc b/main.cc
index 2b1b086a..7f3aa748 100644
--- a/main.cc
+++ b/main.cc
@@ -142,7 +142,14 @@ int main(int argc, char *argv[])
commodity * usd = new commodity("$", true, false, true, false, 2);
main_ledger.commodities.insert(commodities_entry("USD", usd));
+ // Read the command word
+
+ const std::string command = argv[optind];
+
#ifdef HUQUQULLAH
+ if (command == "register")
+ compute_huquq = false;
+
if (compute_huquq) {
new commodity("H", true, true, true, false, 2);
new commodity("mithqal", false, true, true, false, 1);
@@ -154,15 +161,6 @@ int main(int argc, char *argv[])
}
#endif
- // Read the command word
-
- const std::string command = argv[optind];
-
-#ifdef HUQUQ_CATEGORIES
- if (command == "register")
- compute_huquq = false;
-#endif
-
// Parse the ledger
char buf[32];
diff --git a/register.cc b/register.cc
index 86e42d53..5b5ea1dd 100644
--- a/register.cc
+++ b/register.cc
@@ -66,13 +66,14 @@ void print_register(int argc, char **argv, std::ostream& out)
for (std::list<transaction *>::iterator x = (*i)->xacts.begin();
x != (*i)->xacts.end();
x++) {
- if ((*x)->acct == acct || ! show_cleared && (*i)->cleared)
+ if ((*x)->acct != acct || ! show_cleared && (*i)->cleared)
continue;
char buf[32];
- std::strftime(buf, 31, "%Y.%m.%d ", std::localtime(&(*i)->date));
+ std::strftime(buf, 31, "%m.%d ", std::localtime(&(*i)->date));
out << buf;
+#if 0
if ((*i)->cleared)
out << "* ";
else
@@ -83,19 +84,20 @@ void print_register(int argc, char **argv, std::ostream& out)
out << " ";
else
out << std::left << (*i)->code;
+#endif
out << " ";
- out.width(20);
+ out.width(30);
if ((*i)->desc.empty())
out << " ";
else
out << std::left << (*i)->desc;
out << " ";
- out.width(18);
- out << std::left << (*x)->acct->as_str() << " ";
+ transaction * xact = (*i)->xacts.front();
- (*x)->cost->negate();
+ out.width(22);
+ out << std::left << xact->acct->as_str() << " ";
out.width(12);
out << std::right << (*x)->cost->as_str(true);
diff --git a/report b/report
index c7c6187a..949ccc3e 100755
--- a/report
+++ b/report
@@ -9,10 +9,10 @@ command=$1
shift
case "$command" in
- balance) $line "$@" balance bank checking mastercard cash ;;
+ balance) $line "$@" balance -s -- -Equity -Income -Expenses -Retirement ;;
worth) $line "$@" balance assets liabilities ;;
profit) $line "$@" balance income expense ;;
- spending) $line "$@" balance -n food movies gas tips \
+ spending) $line "$@" balance -F food movies gas tips \
health supplies -insurance -vacation ;;
huquq) $line "$@" balance ^huquq ;;
gold) $line "$@" balance -G $1 ^huquq ;;