summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley M. Kuhn <bkuhn@ebb.org>2013-02-16 22:15:15 -0500
committerBradley M. Kuhn <bkuhn@ebb.org>2013-02-18 14:08:46 -0500
commitaea1445b042d3e5fac02da00775299bfa0807c64 (patch)
treeedaff4f4e596cb9c8da2a8592d00b1fa61f20af2
parente87b6abb7f1c7bfd7a626ba5d27dc03fd48f701b (diff)
downloadfork-ledger-aea1445b042d3e5fac02da00775299bfa0807c64.tar.gz
fork-ledger-aea1445b042d3e5fac02da00775299bfa0807c64.tar.bz2
fork-ledger-aea1445b042d3e5fac02da00775299bfa0807c64.zip
Rework report to be just two files (disbursements and receipts).
Ensure that tagged linked files appear for all lines.
-rwxr-xr-xcontrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx37
1 files changed, 18 insertions, 19 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 b620a75e..65f0bda0 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
@@ -4,7 +4,7 @@
# Script to generate a General Ledger report that accountants like
# using Ledger.
#
-# Copyright (C) 2011, 2012 Bradley M. Kuhn
+# Copyright (C) 2011, 2012, 2013 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
@@ -21,6 +21,7 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor
# Boston, MA 02110-1301, USA.
+
use strict;
use warnings;
@@ -76,19 +77,14 @@ die "bad one day less" if $oneDayLess->parse("- 1 day");
$formattedEndDate = $formattedEndDate->calc($oneDayLess);
$formattedEndDate = $formattedEndDate->printf("%Y/%m/%d");
-foreach my $acct (@accounts) {
- next unless ($acct =~ /^(?:Assets|Liabilities)/);
-
- my $acctFilename = LedgerAcctToFilename($acct);
-
- foreach my $typeData ({ name => 'disbursements', query => 'a<=0' },
- { name => 'receipts', query => 'a>0' }) {
- my $fileNameBase = $acctFilename . '-' . $typeData->{name};
+foreach my $typeData ({ name => 'disbursements', query => 'a<=0' },
+ { name => 'receipts', query => 'a>0' }) {
+ my $fileNameBase = $typeData->{name};
- open(CSV_OUT, ">", "$fileNameBase.csv") or die "unable to open $fileNameBase.csv: $!";
+ open(CSV_OUT, ">", "$fileNameBase.csv") or die "unable to open $fileNameBase.csv: $!";
- print CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$beginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n";
- print CSV_OUT '"DATE","CHECK NUM","NAME","ACCOUNT","AMOUNT"';
+ foreach my $acct (sort { $a cmp $b } @accounts) {
+ next unless ($acct =~ /^(?:Assets|Liabilities)/);
my @entryLedgerOpts = ('-l', $typeData->{query},
'-b', $beginDate, '-e', $endDate, @otherLedgerOpts, 'print', $acct);
@@ -104,27 +100,30 @@ foreach my $acct (@accounts) {
goto SKIP_REGISTER_COMMANDS if (-z $tempFile);
- my $formatString = '\n"%(date)","%C","%P","%A","%t"\n%/"","","","%A","%t"';
+ print CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$beginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n";
+ print CSV_OUT '"DATE","CHECK NUM","NAME","ACCOUNT","AMOUNT"';
+
+ my $formatString = '\n"%(date)","%C","%P","%A","%t"';
+ my $tagStrings = "";
foreach my $tagField (qw/Receipt Invoice Statement Contract PurchaseOrder Approval Check IncomeDistributionAnalysis CurrencyRate/) {
print CSV_OUT ',"', $tagField, '"';
- $formatString .= ',"link:%(tag(\'' . $tagField . '\'))"';
+ $tagStrings .= ',"link:%(tag(\'' . $tagField . '\'))"';
}
- $formatString .= "\n";
- print CSV_OUT "\n";
+ $formatString .= $tagStrings . '\n%/"","","","%A","%t"' . $tagStrings . '\n';
+
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; }
close(CSV_DATA); die "Error read from csv ledger command $!" unless $? == 0;
-
+ print CSV_OUT "\npagebreak\n";
SKIP_REGISTER_COMMANDS:
- close(CSV_OUT); die "Error read write csv out to $fileNameBase.csv: $!" unless $? == 0;
unlink($tempFile);
}
+ close(CSV_OUT); die "Error read write csv out to $fileNameBase.csv: $!" unless $? == 0;
}
###############################################################################
#