summaryrefslogtreecommitdiff
path: root/contrib/non-profit-audit-reports
diff options
context:
space:
mode:
authorBradley M. Kuhn <bkuhn@ebb.org>2011-11-01 12:13:31 -0400
committerBradley M. Kuhn <bkuhn@ebb.org>2012-11-26 13:54:43 -0500
commit6a3b25f85bd31ae8d7fdd55dd7f9a83a95d96e0d (patch)
tree35f8d65efe850c59dc1a765ee80074cfdd4ce2f6 /contrib/non-profit-audit-reports
parentb5316132d44a91ff664b39c194710f5f88051d74 (diff)
downloadfork-ledger-6a3b25f85bd31ae8d7fdd55dd7f9a83a95d96e0d.tar.gz
fork-ledger-6a3b25f85bd31ae8d7fdd55dd7f9a83a95d96e0d.tar.bz2
fork-ledger-6a3b25f85bd31ae8d7fdd55dd7f9a83a95d96e0d.zip
Began fund-report.plx, which started as a copy of trial-balance-report.plx.
The revision history of trial-balance-report.plx can be found in the following location: http://gitorious.org/bkuhn/small-hacks/blobs/history/master/trial-balance-report.plx
Diffstat (limited to 'contrib/non-profit-audit-reports')
-rwxr-xr-xcontrib/non-profit-audit-reports/fund-report.plx135
1 files changed, 135 insertions, 0 deletions
diff --git a/contrib/non-profit-audit-reports/fund-report.plx b/contrib/non-profit-audit-reports/fund-report.plx
new file mode 100755
index 00000000..e690b13b
--- /dev/null
+++ b/contrib/non-profit-audit-reports/fund-report.plx
@@ -0,0 +1,135 @@
+#!/usr/bin/perl
+# fund-report.plx -*- Perl -*-
+#
+# Script to generate a Trial Balance report for a ledger.
+#
+# Copyright (C) 2011, Bradley M. Kuhn
+#
+# This program gives you software freedom; you can copy, modify, convey,
+# and/or redistribute it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program in a file called 'GPLv3'. If not, write to the:
+# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor
+# Boston, MA 02110-1301, USA.
+
+use strict;
+use warnings;
+
+use Math::BigFloat;
+
+my $LEDGER_CMD = "/usr/bin/ledger";
+
+my $ACCT_WIDTH = 70;
+
+sub ParseNumber($) {
+ $_[0] =~ s/,//g;
+ return Math::BigFloat->new($_[0]);
+}
+Math::BigFloat->precision(-2);
+my $ZERO = Math::BigFloat->new("0.00");
+
+if (@ARGV < 2) {
+ print STDERR "usage: $0 <START_DATE> <END_DATE> <LEDGER_OPTIONS>\n";
+ exit 1;
+}
+
+my($startDate, $endDate, @mainLedgerOptions) = @ARGV;
+
+# First, get fund list from ending balance
+my(@ledgerOptions) = (@mainLedgerOptions,
+ '--wide-register-format', "%-.70A %22.108t\n", '-w', '-s',
+ '-e', $endDate, 'reg', '^Funds:Restricted:');
+
+
+my %funds;
+
+open(LEDGER_FUNDS, "-|", $LEDGER_CMD, @ledgerOptions)
+ or die "Unable to run $LEDGER_CMD for funds: $!";
+
+while (my $fundLine = <LEDGER_FUNDS>) {
+ die "Unable to parse output line from funds command: $fundLine"
+ unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
+ my($account, $amount) = ($1, $2);
+ $amount = ParseNumber($amount);
+ $account =~ s/^\s*Funds:Restricted://; $account =~ s/\s+$//;
+ $funds{$account}{ending} = $amount;
+}
+close LEDGER_FUNDS;
+
+# First, get fund list from ending balance
+@ledgerOptions = (@mainLedgerOptions,
+ '--wide-register-format', "%-.70A %22.108t\n", '-w', '-s',
+ '-e', $startDate, 'reg', '^Funds:Restricted:');
+
+open(LEDGER_FUNDS, "-|", $LEDGER_CMD, @ledgerOptions)
+ or die "Unable to run $LEDGER_CMD for funds: $!";
+
+while (my $fundLine = <LEDGER_FUNDS>) {
+ die "Unable to parse output line from funds command: $fundLine"
+ unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
+ my($account, $amount) = ($1, $2);
+ $amount = ParseNumber($amount);
+ $account =~ s/^\s*Funds:Restricted://; $account =~ s/\s+$//;
+ $funds{$account}{starting} = $amount;
+}
+close LEDGER_FUNDS;
+
+
+foreach my $fund (keys %funds) {
+ $funds{$fund}{starting} = $ZERO if not defined $funds{$fund}{starting};
+}
+
+@ledgerOptions = (@mainLedgerOptions,
+ '--wide-register-format', "%-.70A %22.108t\n", '-w', '-s',
+ '-b', $startDate, '-e', $endDate, 'reg');
+
+foreach my $type ('Income', 'Expenses') {
+ foreach my $fund (keys %funds) {
+ open(LEDGER_INCOME, "-|", $LEDGER_CMD, @ledgerOptions, "^${type}:$fund")
+ or die "Unable to run $LEDGER_CMD for funds: $!";
+ $funds{$fund}{$type} = $ZERO;
+ while (my $line = <LEDGER_INCOME>) {
+ die "Unable to parse output line from $type line command: $line"
+ unless $line =~ /^\s*([^\$]+)\s+\$\s*\s*([\-\d\.\,]+)/;
+ my($account, $amount) = ($1, $2);
+ $amount = ParseNumber($amount);
+ $funds{$fund}{$type} += $amount;
+ }
+ close LEDGER_INCOME;
+ }
+}
+
+my($totStart, $totEnd) = ($ZERO, $ZERO);
+
+foreach my $fund (sort keys %funds) {
+ print "Fund: $fund\n";
+ print " Balance as of $startDate: ", sprintf("\$%15.2f\n\n", $funds{$fund}{starting});
+ print " Income during period: ", sprintf("\$%15.2f\n", $funds{$fund}{Income});
+ print " Expenses during period: ", sprintf("\$%15.2f\n\n", $funds{$fund}{Expenses});
+ print " Balance as of $endDate: ", sprintf("\$%15.2f\n", $funds{$fund}{ending});
+ print "\n\n";
+ # Santity check:
+ if ($funds{$fund}{ending} !=
+ ( ($funds{$fund}{starting} - $funds{$fund}{Income}) - $funds{$fund}{Expenses})) {
+ print "$fund FAILED SANITY CHECK\n\n\n";
+ die "$fund FAILED SANITY CHECK";
+ }
+ $totStart += $funds{$fund}{starting};
+ $totEnd += $funds{$fund}{ending};
+}
+print "\n\n\nTotal Restricted Funds as of $startDate: ", sprintf("\$%15.2f\n", $totStart);
+print "\nTotal Restricted Funds as of $endDate: ", sprintf("\$%15.2f\n", $totEnd);
+###############################################################################
+#
+# Local variables:
+# compile-command: "perl -c fund-report.plx"
+# End:
+