From 513ac87644b05f0a2d6bf1f5f1827860ee25faa1 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Fri, 2 Dec 2011 07:21:49 -0500 Subject: [PATCH] Additional attempts to get this working. It still isn't. --- trial-balance-report.plx | 53 +++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/trial-balance-report.plx b/trial-balance-report.plx index d4ca660..b080825 100755 --- a/trial-balance-report.plx +++ b/trial-balance-report.plx @@ -29,7 +29,7 @@ use Math::BigFloat; my $LEDGER_CMD = "/usr/bin/ledger"; -my $ACCT_WIDTH = 70; +my $ACCT_WIDTH = 75; # http://www.moneyinstructor.com/lesson/trialbalance.asp # told me: @@ -60,45 +60,38 @@ if (@ARGV == 0) { exit 1; } -my(@ledgerOptions) = ('--wide-register-format', "%-.${ACCT_WIDTH}A %22.108t" .'\n', '-w', '-s', @ARGV, - 'reg'); +my(@ledgerOptions) = ('--wide-register-format', "%-.${ACCT_WIDTH}A %22.108t\n", '-w', + @ARGV, 'reg'); -open(LEDGER_DEBIT, "-|", $LEDGER_CMD, '-d', 'a>0', @ledgerOptions) - or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!"; +open(LEDGER_DATA, "-|", $LEDGER_CMD, @ledgerOptions) + or die "Unable to run $LEDGER_CMD @ledgerOptions: $!"; my %acct; -while (my $negLine = ) { +while (my $line = ) { - chomp $negLine; - - die "Unable to parse output line from negative_ledger command: $negLine" - unless $negLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/; + die "Unable to parse output line from negative_ledger command: $line" + unless $line =~ /^\s*([^\$]+)\s+\$\s*\s*([\-\d\.\,]+)/; my($account, $amount) = ($1, $2); $amount = ParseNumber($amount); $account =~ s/^\s+//; $account =~ s/\s+$//; - $acct{$account}{debit} = $amount; + $acct{$account}{debit} = $ZERO if not defined $acct{$account}{debit}; + $acct{$account}{credit} = $ZERO if not defined $acct{$account}{credit}; + + if ($account =~ /^(Asset|Expense)/) { + $acct{$account}{debit} += $amount; + } elsif ($account =~ /^(Income)/) { + $acct{$account}{debit} += - $amount; + } elsif ($account =~ /^(Liabilities)/) { + $acct{$account}{credit} += $amount; + } else { + die "unkown account type $account"; + } + } -close LEDGER_DEBIT; -die "error($0): $! while running negative_ledger command line" unless ($? == 0); +close LEDGER_DATA; +die "error($0): $! while running ledger command line" unless ($? == 0); -# Lazy here: this is nearly identical to loop above - -open(LEDGER_CREDIT, "-|", $LEDGER_CMD, '-d', 'a<0', @ledgerOptions) - or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!"; -while (my $postLine = ) { - chomp $postLine; - - die "Unable to parse output line from positive_ledger command: $postLine" - unless $postLine =~ /^\s*([^\$]+)\s+\$\s*\-\s*([\d\.\,]+)/; - my($account, $amount) = ($1, $2); - $amount = ParseNumber($amount); - $account =~ s/^\s+//; $account =~ s/\s+$//; - - $acct{$account}{credit} = $amount; -} -close LEDGER_CREDIT; -die "error($0): $! while running positive_ledger command line" unless ($? == 0); print sprintf("%-${ACCT_WIDTH}.${ACCT_WIDTH}s %s %s\n\n", "ACCOUNT", "DEBITS", "CREDITS");