summaryrefslogtreecommitdiff
path: root/contrib/non-profit-audit-reports
diff options
context:
space:
mode:
authorBradley M. Kuhn <bkuhn@ebb.org>2013-01-08 14:26:04 -0500
committerBradley M. Kuhn <bkuhn@ebb.org>2013-02-18 14:08:45 -0500
commit6962fc4c57c5709cb106bd544df3cdb338c7495a (patch)
tree4b27900fafeec5bc31d17ee1baf23daafd78c23e /contrib/non-profit-audit-reports
parentb214a2db5b64b52938aecc60711a0237fc95b575 (diff)
downloadfork-ledger-6962fc4c57c5709cb106bd544df3cdb338c7495a.tar.gz
fork-ledger-6962fc4c57c5709cb106bd544df3cdb338c7495a.tar.bz2
fork-ledger-6962fc4c57c5709cb106bd544df3cdb338c7495a.zip
Basic implementation probably correct, but needs much RAM.
This is the basic implementation but for large numbers, it needs a *LOT* of RAM.
Diffstat (limited to 'contrib/non-profit-audit-reports')
-rwxr-xr-xcontrib/non-profit-audit-reports/bank-reconcilation.plx45
1 files changed, 36 insertions, 9 deletions
diff --git a/contrib/non-profit-audit-reports/bank-reconcilation.plx b/contrib/non-profit-audit-reports/bank-reconcilation.plx
index 7201ef1f..b09519a3 100755
--- a/contrib/non-profit-audit-reports/bank-reconcilation.plx
+++ b/contrib/non-profit-audit-reports/bank-reconcilation.plx
@@ -8,8 +8,9 @@ use Date::Manip;
Math::BigFloat->precision(-2);
my $ZERO = Math::BigFloat->new("0.00");
+my $ONE_HUNDRED = Math::BigFloat->new("100.00");
-my $VERBOSE = 0;
+my $VERBOSE = 1;
my $DEBUG = 0;
my $LEDGER_BIN = "/usr/local/bin/ledger";
@@ -19,18 +20,27 @@ sub SubSetSumSolver ($$$) {
my($numberList, $totalSought, $extractNumber) = @_;
my($P, $N) = (0, 0);
- foreach my $ii (@{$numberList}) {
- if ($ii < $ZERO) {
- $N += $ii;
- } else {
- $P += $ii;
- }
- }
my $size = scalar(@{$numberList});
my %Q;
my(@L) =
map { { val => &$extractNumber($_), obj => $_ } } @{$numberList};
+
+ if ($VERBOSE) {
+ }
+ }
+ print STDERR " L in this iteration:\n [" if $VERBOSE;
+
+ foreach my $ee (@L) {
+ if ($ee->{val} < 0) {
+ $N += $ee->{val}
+ } else {
+ $P += $ee->{val};
+ }
+ print STDERR $ee->{val}, ", " if $VERBOSE;
+ }
+ print STDERR "]\n P = $P, N = $N\n" if ($VERBOSE);
+
for (my $ii = 0 ; $ii <= $size ; $ii++ ) {
$Q{$ii}{0}{value} = 1;
$Q{$ii}{0}{list} = [];
@@ -85,6 +95,14 @@ if (@ARGV < 4) {
exit 1;
}
######################################################################
+sub ConvertTwoDigitPrecisionToInteger ($) {
+ return sprintf("%d", $_[0] * $ONE_HUNDRED);
+}
+######################################################################
+sub ConvertTwoDigitPrecisionToIntegerInEntry ($) {
+ return ConvertTwoDigitPrecisionToInteger($_[0]->{amount});
+}
+######################################################################
my($account, $endDate, $balanceSought, @mainLedgerOptions) = @ARGV;
$balanceSought = ParseNumber($balanceSought);
@@ -111,9 +129,18 @@ foreach my $line (<FILE>) {
unless $amount =~ s/\s*\$\s*([\-\d\.\,]+)\s*$/$1/;
$amount = ParseNumber($amount);
- print "$date, $checkNum, $payee, $amount\n";
push(@entries, { date => $date, checkNum => $checkNum, amount => $amount });
}
+close FILE;
+die "unable to properly run ledger command: @fullCommand: $!" unless ($? == 0);
+
+my(@solution) = SubSetSumSolver(\@entries, ConvertTwoDigitPrecisionToInteger($balanceSought),
+ \&ConvertTwoDigitPrecisionToIntegerInEntry);
+
+if ($VERBOSE) {
+ use Data::Dumper;
+ print Data::Dumper->Dump(\@solution);
+}
###############################################################################
#