diff options
author | Bradley M. Kuhn <bkuhn@ebb.org> | 2013-01-09 16:44:54 -0500 |
---|---|---|
committer | Bradley M. Kuhn <bkuhn@ebb.org> | 2013-02-18 14:08:45 -0500 |
commit | 94094ce3650e26e584b68f3c0d94d593732dc3bc (patch) | |
tree | be6518856faee3468c9184bf1b61e0cad9cdf314 /contrib/non-profit-audit-reports | |
parent | 0530b729e2b38931f653e226bc3c1cfc47d55d24 (diff) | |
download | fork-ledger-94094ce3650e26e584b68f3c0d94d593732dc3bc.tar.gz fork-ledger-94094ce3650e26e584b68f3c0d94d593732dc3bc.tar.bz2 fork-ledger-94094ce3650e26e584b68f3c0d94d593732dc3bc.zip |
Finish reporting details for STDOUT; change command line arg to bank balance.
Report in CSV now goes to STDOUT.
The command line argument that was the difference to seek is now the bank
balance.
Diffstat (limited to 'contrib/non-profit-audit-reports')
-rwxr-xr-x | contrib/non-profit-audit-reports/bank-reconcilation.plx | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/contrib/non-profit-audit-reports/bank-reconcilation.plx b/contrib/non-profit-audit-reports/bank-reconcilation.plx index 18d74067..ada923f3 100755 --- a/contrib/non-profit-audit-reports/bank-reconcilation.plx +++ b/contrib/non-profit-audit-reports/bank-reconcilation.plx @@ -112,10 +112,6 @@ sub ParseNumber($) { $_[0] =~ s/,//g; return Math::BigFloat->new($_[0]); } -if (@ARGV < 4) { - print STDERR "usage: $0 [-d] <ACCOUNT_REGEX> <END_DATE> <BANK_STATEMENT_BALANCE> <LEDGER_OPTIONS>\n"; - exit 1; -} ###################################################################### sub ConvertTwoDigitPrecisionToInteger ($) { return sprintf("%d", $_[0] * $ONE_HUNDRED); @@ -129,17 +125,43 @@ my $firstArg = shift @ARGV; my $solver = \&BruteForceSubSetSumSolver; +if (@ARGV < 5) { + print STDERR "usage: $0 [-d] <TITLE> <ACCOUNT_REGEX> <END_DATE> <BANK_STATEMENT_BALANCE> <LEDGER_OPTIONS>\n"; + exit 1; +} if ($firstArg eq '-d') { $solver = \&DynamicProgrammingSubSetSumSolver; } else { unshift(@ARGV, $firstArg); } -my($account, $endDate, $balanceSought, @mainLedgerOptions) = @ARGV; +my($title, $account, $endDate, $bankBalance, @mainLedgerOptions) = @ARGV; + +$bankBalance = ParseNumber($bankBalance); +my(@fullCommand) = ($LEDGER_BIN, @mainLedgerOptions, '-V', '-X', '$', + '-e', $endDate, '-F', '%t\n', 'bal', "/$account/"); -$balanceSought = ParseNumber($balanceSought); +open(FILE, "-|", @fullCommand) or die "unable to run command ledger command: @fullCommand: $!"; + +my $total; +foreach my $line (<FILE>) { + chomp $line; + die "Unable to parse output line from: \"$line\"" + unless $line =~ /^\s*\$\s*([\-\d\.\,]+)\s*$/ and not defined $total; + $total = $1; + $total = ParseNumber($total); +} +close FILE; +if (not defined $total or $? != 0) { + die "unable to run ledger @fullCommand: $!"; +} +my $differenceSought = $total - $bankBalance; my $err; +my $formattedEndDate = UnixDate(DateCalc(ParseDate($endDate), ParseDateDelta("- 1 day"), \$err), + "%Y-%m-%d"); +die "Date calculation error on $endDate" if ($err); + my $earliestStartDate = DateCalc(ParseDate($endDate), ParseDateDelta("- 1 month"), \$err); die "Date calculation error on $endDate" if ($err); @@ -148,11 +170,11 @@ my $startDate = ParseDate($endDate); my @solution; while ($startDate ge $earliestStartDate) { - print "START LOOP ITR: $startDate $earliestStartDate\n"; + print STDERR "START LOOP ITR: $startDate $earliestStartDate\n" if ($VERBOSE); $startDate = DateCalc(ParseDate($startDate), ParseDateDelta("- 1 day"), \$err); die "Date calculation error on $endDate" if ($err); - my $formattedStartDate = UnixDate($startDate, "%Y/%m/%d"); + my $formattedStartDate = UnixDate($startDate, "%Y-%m-%d"); print STDERR "Testing $formattedStartDate through $endDate: \n" if $VERBOSE; @@ -180,26 +202,24 @@ while ($startDate ge $earliestStartDate) { close FILE; die "unable to properly run ledger command: @fullCommand: $!" unless ($? == 0); - @solution = (); - if (@entries == 1) { - @solution = ( (abs($entries[0]->{amount}) == abs($balanceSought)), \@entries); - } else { - @solution = $solver->(\@entries, - ConvertTwoDigitPrecisionToInteger($balanceSought), - \&ConvertTwoDigitPrecisionToIntegerInEntry); - } + @solution = $solver->(\@entries, + ConvertTwoDigitPrecisionToInteger($differenceSought), + \&ConvertTwoDigitPrecisionToIntegerInEntry); if ($VERBOSE) { use Data::Dumper; - print STDERR "Solution for $formattedStartDate, $balanceSought: \n", Data::Dumper->Dump(\@solution); + print STDERR "Solution for $formattedStartDate to $formattedEndDate, $differenceSought: \n", + Data::Dumper->Dump(\@solution); } last if ($solution[0]); } if ($solution[0]) { - print "FINAL SOLUTION: "; + print "\"title:$formattedEndDate: $title\"\n\"BANK RECONCILATION: $account\",\"ENDING\",\"$formattedEndDate\"\n"; + print "\n\n\"DATE\",\"CHECK NUM\",\"PAYEE\",\"AMOUNT\"\n\n"; + print "\"$formattedEndDate\",\"\",\"BANK ACCOUNT BALANCE\",\"$bankBalance\"\n\n"; foreach my $ee (@{$solution[1]}) { - print Data::Dumper->Dump($solution[1]); - print "$ee->{date}, $ee->{payee}, $ee->{amount}\n"; + print "\"$ee->{date}\",\"$ee->{checkNum}\",\"$ee->{payee}\",\"$ee->{amount}\"\n"; } + print "\n\"$formattedEndDate\",\"\",\"OUR ACCOUNT BALANCE\",\"$total\"\n\n"; } ############################################################################### # |