From b939bbe8c61a819e413b3e2a24d223f6232bd0d9 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Thu, 3 Jan 2013 12:30:43 -0500 Subject: Convert trial-balance report to CSV from TXT file. Also, ignore Ledger's Equity: accounts properly. --- .../non-profit-audit-reports/summary-reports.plx | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'contrib/non-profit-audit-reports/summary-reports.plx') diff --git a/contrib/non-profit-audit-reports/summary-reports.plx b/contrib/non-profit-audit-reports/summary-reports.plx index da2dba9d..dae8f2ce 100755 --- a/contrib/non-profit-audit-reports/summary-reports.plx +++ b/contrib/non-profit-audit-reports/summary-reports.plx @@ -378,15 +378,15 @@ die "calculated total of $overallTotal does equal $firstTotal" print STDERR "\n"; -open(TRIAL, ">", "trial-balance.txt") or die "unable to open accrued.txt for writing: $!"; +open(TRIAL, ">", "trial-balance.csv") or die "unable to open accrued.txt for writing: $!"; @fullCommand = ($LEDGER_BIN, @mainLedgerOptions, '-V', '-X', '$', '-e', $endDate, '-F', '%-.80A %22.108t\n', '-s', 'reg'); -print TRIAL " TRIAL BALANCE \n", - " Ending $formattedEndDate\n\n"; +print TRIAL "\"TRIAL BALANCE REPORT\",", + "\"ENDING:\",\"$formattedEndDate\"\n\n\"ACCOUNT NAME\", \"AMOUNT\"\n\n"; open(FILE, "-|", @fullCommand) or die "unable to run command ledger command: @fullCommand: $!"; @@ -395,17 +395,28 @@ print STDERR ($VERBOSE ? "Running: @fullCommand\n" : "."); my $accruedTotal = $ZERO; +my %trialBalances; + foreach my $line () { die "Unable to parse output line from second funds command: $line" unless $line =~ /^\s*([^\$]+)\s+\$\s*([\-\d\.\,]+)/; my($account, $amount) = ($1, $2); $amount = ParseNumber($amount); $account =~ s/\s+$//; - next if $account =~ /\|^Equity:/ and (abs($amount) <= 0.02); - print TRIAL $line; - + next if $account =~ /\/ and (abs($amount) <= 0.02); + next if $account =~ /^Equity:/; # Stupid auto-account made by ledger. + $trialBalances{$account} = $amount; $accruedTotal += $amount; } +close FILE; +die "unable to run trial balance ledger command: $!" unless ($? == 0); + +foreach my $account (sort preferredAccountSorting keys %trialBalances) { + print TRIAL "\"$account\",\"$trialBalances{$account}\"\n"; +} + +close TRIAL; +die "unable to write trial-balance.csv: $!" unless ($? == 0); ############################################################################### # -- cgit v1.2.3