From 47130b2dfb2d2489b0dc825d43fe31c2644ac0b6 Mon Sep 17 00:00:00 2001 From: Tom Marble Date: Sat, 8 Sep 2012 00:30:37 -0500 Subject: First pass technical study of creating ODS from ledger --- contrib/non-profit-audit-reports/demo.sh | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 contrib/non-profit-audit-reports/demo.sh (limited to 'contrib/non-profit-audit-reports/demo.sh') diff --git a/contrib/non-profit-audit-reports/demo.sh b/contrib/non-profit-audit-reports/demo.sh new file mode 100755 index 00000000..6a9dcadf --- /dev/null +++ b/contrib/non-profit-audit-reports/demo.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# demo.sh +# Demonstrate a non-profit GL export and conversion to ODS + +program=$(basename $0) +dir=$(dirname $0) +cd $dir +dir=$(pwd -P) +export PYTHONPATH=$dir/ooolib2 + +getcsv=$dir/general-ledger-report.plx +csv2ods=$dir/csv2ods.py + +echo "Demonstrating ledger to ODS export in $dir/tests" +cd $dir/tests +sampledata=non-profit-test-data.ledger +echo " based on the sample data in $sampledata" + +$getcsv 2011/03/01 2012/03/01 -f $sampledata +if [ -e general-ledger.csv ]; then + echo "data was exported to: general-ledger.csv" +else + echo "error creating csv file" + exit 1 +fi + +$csv2ods --verbose --csv general-ledger.csv +if [ -e general-ledger.ods ]; then + echo "csv was converted to: general-ledger.ods" +else + echo "error creating ods file" + exit 1 +fi + +# create a portable zip file with the spreadsheet +# and the linked artifacts + +echo creating portable zipfile... +zip -r ../general-ledger.zip general-ledger.ods Financial Projects -x '*.txt' + +echo " " +echo "created general-ledger.zip" + -- cgit v1.2.3 From b5316132d44a91ff664b39c194710f5f88051d74 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 21 Nov 2012 13:34:55 -0500 Subject: MANIFEST output file that indicates which files are mentioned in general-ledger. Due to reporting options given to ledger, not every file will be referenced by the general-ledger spreadsheet. The generated MANIFEST file now indicates which files were actually referenced in the general-ledger. The demo.sh script now uses this MANIFEST to create a zip file that contains only those files. --- contrib/non-profit-audit-reports/demo.sh | 4 +++- contrib/non-profit-audit-reports/general-ledger-report.plx | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'contrib/non-profit-audit-reports/demo.sh') diff --git a/contrib/non-profit-audit-reports/demo.sh b/contrib/non-profit-audit-reports/demo.sh index 6a9dcadf..a4b837a6 100755 --- a/contrib/non-profit-audit-reports/demo.sh +++ b/contrib/non-profit-audit-reports/demo.sh @@ -32,11 +32,13 @@ else exit 1 fi +echo general-ledger.ods >> MANIFEST + # create a portable zip file with the spreadsheet # and the linked artifacts echo creating portable zipfile... -zip -r ../general-ledger.zip general-ledger.ods Financial Projects -x '*.txt' +cat MANIFEST | zip -@ ../general-ledger.zip echo " " echo "created general-ledger.zip" diff --git a/contrib/non-profit-audit-reports/general-ledger-report.plx b/contrib/non-profit-audit-reports/general-ledger-report.plx index 1c293db9..07f0b9da 100755 --- a/contrib/non-profit-audit-reports/general-ledger-report.plx +++ b/contrib/non-profit-audit-reports/general-ledger-report.plx @@ -44,6 +44,7 @@ if (@ARGV < 3) { print STDERR "usage: $0 \n"; exit 1; } +open(MANIFEST, ">", "MANIFEST") or die "Unable to open MANIFEST for writing: $!"; my($beginDate, $endDate, @otherLedgerOpts) = @ARGV; @@ -53,8 +54,6 @@ my(@chartOfAccountsOpts) = ('-F', "%150A\n", '-w', '-s', open(CHART_DATA, "-|", $LEDGER_CMD, @chartOfAccountsOpts) or die "Unable to run $LEDGER_CMD @chartOfAccountsOpts: $!"; -open(CHART_OUTPUT, ">", "chart-of-accounts.txt") or die "unable to write chart-of-accounts.txt: $!"; - my @accounts; while (my $line = ) { chomp $line; @@ -65,6 +64,7 @@ while (my $line = ) { close(CHART_DATA); die "error reading ledger output for chart of accounts: $!" unless $? == 0; open(CHART_OUTPUT, ">", "chart-of-accounts.txt") or die "unable to write chart-of-accounts.txt: $!"; +print MANIFEST "chart-of-accounts.txt\n"; my @sortedAccounts; foreach my $acct ( @@ -91,7 +91,9 @@ $formattedEndDate = $formattedEndDate->calc($oneDayLess); $formattedEndDate = $formattedEndDate->printf("%Y/%m/%d"); open(GL_TEXT_OUT, ">", "general-ledger.txt") or die "unable to write general-ledger.txt: $!"; +print MANIFEST "general-ledger.txt\n"; open(GL_CSV_OUT, ">", "general-ledger.csv") or die "unable to write general-ledger.csv: $!"; +print MANIFEST "general-ledger.csv\n"; foreach my $acct (@sortedAccounts) { print GL_TEXT_OUT "\n\nACCOUNT: $acct\nFROM: $beginDate TO $formattedEndDate\n\n"; @@ -122,6 +124,14 @@ foreach my $acct (@sortedAccounts) { foreach my $line () { print GL_CSV_OUT $line; + next if $line =~ /ACCOUNT:.*PERIOD/; # Skip column header lines + $line =~ s/^"[^"]*","[^"]*","[^"]*","[^"]*","[^"]*",//; + while ($line =~ s/^"([^"]*)"(,|$)//) { + my $file = $1; + next if $file =~ /^\s*$/; + warn "$file does not exist and/or is not readable" unless -r $file; + print MANIFEST "$file\n"; + } } close(GL_CSV_DATA); die "error reading ledger output for chart of accounts: $!" unless $? == 0; } -- cgit v1.2.3