From 86b20430423428f4ad371d98071679c9429f861b Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 21 Jan 2013 16:28:14 -0500 Subject: Remove output of TXT files. CSV output is adequate. --- .../cash-receipts-and-disbursments-journals.plx | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx') 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 2ad18a44..b620a75e 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 @@ -85,10 +85,8 @@ foreach my $acct (@accounts) { { name => 'receipts', query => 'a>0' }) { my $fileNameBase = $acctFilename . '-' . $typeData->{name}; - open(TEXT_OUT, ">", "$fileNameBase.txt") or die "unable to open $fileNameBase.txt: $!"; open(CSV_OUT, ">", "$fileNameBase.csv") or die "unable to open $fileNameBase.csv: $!"; - print TEXT_OUT "\n\nACCOUNT: $acct\nFROM: $beginDate TO $formattedEndDate\n\n"; print CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$beginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n"; print CSV_OUT '"DATE","CHECK NUM","NAME","ACCOUNT","AMOUNT"'; @@ -106,10 +104,6 @@ foreach my $acct (@accounts) { goto SKIP_REGISTER_COMMANDS if (-z $tempFile); - my @txtRegLedgerOpts = ('-f', $tempFile, '-V', '-F', - "%(date) %-.70P %-.10C %-.80A %18t\n", '-w', '--sort', 'd', - '-b', $beginDate, '-e', $endDate, 'reg'); - my $formatString = '\n"%(date)","%C","%P","%A","%t"\n%/"","","","%A","%t"'; foreach my $tagField (qw/Receipt Invoice Statement Contract PurchaseOrder Approval Check IncomeDistributionAnalysis CurrencyRate/) { print CSV_OUT ',"', $tagField, '"'; @@ -121,12 +115,6 @@ foreach my $acct (@accounts) { '-b', $beginDate, '-e', $endDate, 'reg'); - open(TXT_DATA, "-|", $LEDGER_CMD, @txtRegLedgerOpts) - or die "unable to run ledger command for $fileNameBase.txt: $!"; - - while (my $line = ) { print TEXT_OUT $line; } - close(TEXT_OUT); die "Error read write text out to $fileNameBase.txt: $!" unless $? == 0; - open(CSV_DATA, "-|", $LEDGER_CMD, @csvRegLedgerOpts) or die "unable to run ledger command for $fileNameBase.csv: $!"; @@ -134,7 +122,6 @@ foreach my $acct (@accounts) { close(CSV_DATA); die "Error read from csv ledger command $!" unless $? == 0; SKIP_REGISTER_COMMANDS: - close(TXT_DATA); die "Error read from txt ledger command $!" unless $? == 0; close(CSV_OUT); die "Error read write csv out to $fileNameBase.csv: $!" unless $? == 0; unlink($tempFile); } -- cgit v1.2.3 From aea1445b042d3e5fac02da00775299bfa0807c64 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Sat, 16 Feb 2013 22:15:15 -0500 Subject: Rework report to be just two files (disbursements and receipts). Ensure that tagged linked files appear for all lines. --- .../cash-receipts-and-disbursments-journals.plx | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx') 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 = ) { $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; } ############################################################################### # -- cgit v1.2.3 From a08dd787deb89446bc516612a1ea01937cd2e963 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 18 Feb 2013 14:05:15 -0500 Subject: Remove extra newline --- .../cash-receipts-and-disbursments-journals.plx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx') 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 65f0bda0..61b45b3c 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 @@ -100,7 +100,7 @@ foreach my $typeData ({ name => 'disbursements', query => 'a<=0' }, goto SKIP_REGISTER_COMMANDS if (-z $tempFile); - print CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$beginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n"; + print CSV_OUT "\"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"'; -- cgit v1.2.3 From 77827f9c80eac22834d17c4985778b70145e3243 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 18 Feb 2013 14:07:27 -0500 Subject: 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 --- .../cash-receipts-and-disbursments-journals.plx | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx') 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 = ) { $line =~ s/"link:"/""/g; print CSV_OUT $line; } + my($curDepositDate, $curDepositTotal); + + while (my $line = ) { + $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); } -- cgit v1.2.3 From 8fa91dcb31bc176634fbc8503035a1cc52256de8 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 18 Feb 2013 14:20:15 -0500 Subject: Remove spurious print statement. --- .../non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx | 1 - 1 file changed, 1 deletion(-) (limited to 'contrib/non-profit-audit-reports/cash-receipts-and-disbursments-journals.plx') 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 58974a85..cb19a19e 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 @@ -151,7 +151,6 @@ foreach my $typeData ({ name => 'disbursements', query => 'a<=0' }, $curDepositTotal = 0.0 unless defined $curDepositTotal; $curDepositTotal += $amt; - print "$amt and $curDepositTotal for deposit on $curDepositDate\n"; } print CSV_OUT $line; } -- cgit v1.2.3