Various changes to this report, but I don't actually think it's generating
a trial balance report accurately. I'm going to try a different approach.
This commit is contained in:
parent
65d3786d3f
commit
f18adccb53
1 changed files with 39 additions and 28 deletions
|
@ -20,6 +20,7 @@
|
||||||
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor
|
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
@ -29,6 +30,22 @@ my $LEDGER_CMD = "/usr/bin/ledger";
|
||||||
|
|
||||||
my $ACCT_WIDTH = 70;
|
my $ACCT_WIDTH = 70;
|
||||||
|
|
||||||
|
# http://www.moneyinstructor.com/lesson/trialbalance.asp
|
||||||
|
# told me:
|
||||||
|
|
||||||
|
# Key to preparing a trial balance is making sure that all the account
|
||||||
|
# balances are listed under the correct column. The appropriate columns
|
||||||
|
# are as follows:
|
||||||
|
|
||||||
|
# Assets = Debit balance
|
||||||
|
# Liabilities = Credit balance
|
||||||
|
# Expenses = Debit Balance
|
||||||
|
# Equity = Credit balance
|
||||||
|
# Revenue = Credit balance
|
||||||
|
|
||||||
|
|
||||||
|
# So, there are some sign switches that are needed:
|
||||||
|
|
||||||
sub ParseNumber($) {
|
sub ParseNumber($) {
|
||||||
$_[0] =~ s/,//g;
|
$_[0] =~ s/,//g;
|
||||||
return Math::BigFloat->new($_[0]);
|
return Math::BigFloat->new($_[0]);
|
||||||
|
@ -42,68 +59,62 @@ if (@ARGV == 0) {
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my(@ledgerOptions) = ('--wide-register-format', "%-.${ACCT_WIDTH}A %22.108t\n", '-w', '-s', @ARGV,
|
my(@ledgerOptions) = ('--wide-register-format', "%-.${ACCT_WIDTH}A %22.108t" .'\n', '-w', '-s', @ARGV,
|
||||||
'reg');
|
'reg');
|
||||||
|
|
||||||
|
|
||||||
open(LEDGER_NEGATIVE, "-|", $LEDGER_CMD, '-d', 'a<0', @ledgerOptions)
|
open(LEDGER_DEBIT, "-|", $LEDGER_CMD, '-d', 'a>0', @ledgerOptions)
|
||||||
or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!";
|
or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!";
|
||||||
|
|
||||||
my %acct;
|
my %acct;
|
||||||
while (my $negLine = <LEDGER_NEGATIVE>) {
|
while (my $negLine = <LEDGER_DEBIT>) {
|
||||||
|
|
||||||
chomp $negLine;
|
chomp $negLine;
|
||||||
|
|
||||||
die "Unable to parse output line from negative_ledger command: $negLine"
|
die "Unable to parse output line from negative_ledger command: $negLine"
|
||||||
unless $negLine =~ /^\s*([^\$]+)\s+\$\s*\-\s*([\d\.\,]+)/;
|
unless $negLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
||||||
my($account, $amount) = ($1, $2);
|
my($account, $amount) = ($1, $2);
|
||||||
$amount = ParseNumber($amount);
|
$amount = ParseNumber($amount);
|
||||||
$account =~ s/^\s+//; $account =~ s/\s+$//;
|
$account =~ s/^\s+//; $account =~ s/\s+$//;
|
||||||
|
$acct{$account}{debit} = $amount;
|
||||||
$acct{$account}{negative} = $amount;
|
|
||||||
}
|
}
|
||||||
close LEDGER_NEGATIVE;
|
close LEDGER_DEBIT;
|
||||||
die "error($0): $! while running negative_ledger command line" unless ($? == 0);
|
die "error($0): $! while running negative_ledger command line" unless ($? == 0);
|
||||||
|
|
||||||
open(LEDGER_NEGATIVE, "-|", $LEDGER_CMD, '-d', 'a<0', @ledgerOptions)
|
|
||||||
or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!";
|
|
||||||
|
|
||||||
|
|
||||||
# Lazy here: this is nearly identical to loop above
|
# Lazy here: this is nearly identical to loop above
|
||||||
|
|
||||||
open(LEDGER_POSITIVE, "-|", $LEDGER_CMD, '-d', 'a>0', @ledgerOptions)
|
open(LEDGER_CREDIT, "-|", $LEDGER_CMD, '-d', 'a<0', @ledgerOptions)
|
||||||
or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!";
|
or die "Unable to run $LEDGER_CMD -d a<0 @ledgerOptions: $!";
|
||||||
while (my $postLine = <LEDGER_POSITIVE>) {
|
while (my $postLine = <LEDGER_CREDIT>) {
|
||||||
chomp $postLine;
|
chomp $postLine;
|
||||||
|
|
||||||
die "Unable to parse output line from positive_ledger command: $postLine"
|
die "Unable to parse output line from positive_ledger command: $postLine"
|
||||||
unless $postLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
unless $postLine =~ /^\s*([^\$]+)\s+\$\s*\-\s*([\d\.\,]+)/;
|
||||||
my($account, $amount) = ($1, $2);
|
my($account, $amount) = ($1, $2);
|
||||||
$amount = ParseNumber($amount);
|
$amount = ParseNumber($amount);
|
||||||
$account =~ s/^\s+//; $account =~ s/\s+$//;
|
$account =~ s/^\s+//; $account =~ s/\s+$//;
|
||||||
|
|
||||||
$acct{$account}{positive} = $amount;
|
$acct{$account}{credit} = $amount;
|
||||||
}
|
}
|
||||||
close LEDGER_POSITIVE;
|
close LEDGER_CREDIT;
|
||||||
die "error($0): $! while running positive_ledger command line" unless ($? == 0);
|
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");
|
||||||
|
|
||||||
print sprintf("%${ACCT_WIDTH}s %s %s\n\n", "ACCOUNT", "DEBITS", "CREDITS");
|
my $format = "%-${ACCT_WIDTH}.${ACCT_WIDTH}s \$%11.2f \$%11.2f\n";
|
||||||
|
my($totDeb, $totCred) = ($ZERO, $ZERO);
|
||||||
print "ACCOUNT DEBITS CREDITS\n\n";
|
foreach my $account (sort keys %acct) {
|
||||||
|
foreach my $val (qw/debit credit /) {
|
||||||
my($totNeg, $totPos) = ($ZERO, $ZERO);
|
|
||||||
foreach my $account (keys %acct) {
|
|
||||||
foreach my $val (qw/positive negative/) {
|
|
||||||
$acct{$account}{$val} = $ZERO unless defined $acct{$account}{$val};
|
$acct{$account}{$val} = $ZERO unless defined $acct{$account}{$val};
|
||||||
}
|
}
|
||||||
print sprintf("%${ACCT_WIDTH}s \$%-.2d \$%-2.d\n", $account,
|
print sprintf($format, $account,
|
||||||
$acct{$account}{negative}, $acct{$account}{positive});
|
$acct{$account}{debit}, $acct{$account}{credit});
|
||||||
$totNeg += $acct{$account}{negative};
|
$totDeb += $acct{$account}{debit};
|
||||||
$totPos += $acct{$account}{positive};
|
$totCred += $acct{$account}{credit};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
print sprintf("%${ACCT_WIDTH}s \$%-.2d \$%-2.d\n", 'TOTAL', $totNeg, $totPos);
|
print "\n\n", sprintf($format, 'TOTAL', $totDeb, $totCred);
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Local variables:
|
# Local variables:
|
||||||
|
|
Loading…
Add table
Reference in a new issue