diff options
author | Bradley M. Kuhn <bkuhn@ebb.org> | 2013-02-18 14:07:27 -0500 |
---|---|---|
committer | Bradley M. Kuhn <bkuhn@ebb.org> | 2013-02-18 14:08:46 -0500 |
commit | 77827f9c80eac22834d17c4985778b70145e3243 (patch) | |
tree | a17576275bc6fb6029a727191e61c555c003d35f /contrib | |
parent | a08dd787deb89446bc516612a1ea01937cd2e963 (diff) | |
download | fork-ledger-77827f9c80eac22834d17c4985778b70145e3243.tar.gz fork-ledger-77827f9c80eac22834d17c4985778b70145e3243.tar.bz2 fork-ledger-77827f9c80eac22834d17c4985778b70145e3243.zip |
Subtotaling of BRANCH DEPOSITs.
The auditors seem to like to see the check deposits made to be subtotaled, so
that's done here. I attempted to aid this by using a --sort and/or
--sort-xacts option (or combo thereof) on the ledger command line, but this
didn't work as expected. I opened a bug in ledger about this:
http://bugs.ledger-cli.org/show_bug.cgi?id=901
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx b/contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx index 61b45b3c..58974a85 100755 --- a/contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx +++ b/contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx @@ -111,15 +111,56 @@ foreach my $typeData ({ name => 'disbursements', query => 'a<=0' }, } $formatString .= $tagStrings . '\n%/"","","","%A","%t"' . $tagStrings . '\n'; + # I thought '--sort', 'd', '--sort-xact', 'a', should + # have worked below for a good sort. Then I tried + # rather than '--sort', "d,n,a", which didn't work either. + # I opened a bug: http://bugs.ledger-cli.org/show_bug.cgi?id=901 + my @csvRegLedgerOpts = ('-f', $tempFile, '-V', '-F', $formatString, '-w', '--sort', 'd', '-b', $beginDate, '-e', $endDate, 'reg'); open(CSV_DATA, "-|", $LEDGER_CMD, @csvRegLedgerOpts) or die "unable to run ledger command for $fileNameBase.csv: $!"; - while (my $line = <CSV_DATA>) { $line =~ s/"link:"/""/g; print CSV_OUT $line; } + my($curDepositDate, $curDepositTotal); + + while (my $line = <CSV_DATA>) { + $line =~ s/"link:"/""/g; + + my $date = $line; chomp $date; + $date =~ s/^\s*"([^"]*)"\s*,.*$/$1/; + if (defined $date and $date !~ /^\s*$/ and + defined $curDepositDate and ($date ne $curDepositDate or + ($date eq $curDepositDate and $line !~ /DEPOSIT[\s\-]+BRANCH/))) { + print CSV_OUT "\"$curDepositDate\",\"SUBTOTAL\",\"BRANCH DEPOSIT TOTAL:\",\"\",\"\$$curDepositTotal\"\n\n"; + $curDepositTotal = $curDepositDate = undef; + } + if ($line =~ /DEPOSIT[\s\-]+BRANCH/) { + if (not defined $curDepositDate) { + $curDepositDate = $line; chomp $curDepositDate; + $curDepositDate =~ s/^\s*"([^"]+)"\s*,.*$/$1/; + } + } + # This is a bit of a hack because I can't ssume that the line with the + # description on it has the account name in it. + if (defined $curDepositDate and $line =~ /$acct/) { + my $amt = $line; + chomp $amt; + $amt =~ s/^\s*"[^"]*","[^"]*","[^"]*","[^"]*","\$\s*([^"]*)".*$/$1/; + $amt =~ s/,//g; + + $curDepositTotal = 0.0 unless defined $curDepositTotal; + $curDepositTotal += $amt; + print "$amt and $curDepositTotal for deposit on $curDepositDate\n"; + } + print CSV_OUT $line; + } + # Catch potential last Deposit subtotal + print CSV_OUT "\n\"$curDepositDate\",\"SUBTOTAL\",\"BRANCH DEPOSIT TOTAL:\",\"\",\"\$$curDepositTotal\"\n\n" + if (defined $curDepositDate); + close(CSV_DATA); die "Error read from csv ledger command $!" unless $? == 0; - print CSV_OUT "\npagebreak\n"; + print CSV_OUT "pagebreak\n"; SKIP_REGISTER_COMMANDS: unlink($tempFile); } |