First crack at an unpaid accruals report.
This commit is contained in:
parent
4290a4ec52
commit
b04fbb1b73
1 changed files with 84 additions and 0 deletions
84
contrib/non-profit-audit-reports/unpaid-accruals-report.plx
Executable file
84
contrib/non-profit-audit-reports/unpaid-accruals-report.plx
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/perl
|
||||
# unpaid-acccurals-report.plx -*- Perl -*-
|
||||
|
||||
# This report is designed to create what our accounts call a "Schedule of
|
||||
# accounts payable". and "Schedule of accounts receivable".
|
||||
|
||||
|
||||
|
||||
# Copyright (C) 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
|
||||
# as published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program in a file called 'GPLv3'. If not, write to the:
|
||||
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Math::BigFloat;
|
||||
use Date::Manip;
|
||||
|
||||
my $LEDGER_CMD = "/usr/local/bin/ledger";
|
||||
|
||||
my $ACCT_WIDTH = 70;
|
||||
|
||||
sub ParseNumber($) {
|
||||
$_[0] =~ s/,//g;
|
||||
return Math::BigFloat->new($_[0]);
|
||||
}
|
||||
Math::BigFloat->precision(-2);
|
||||
my $ZERO = Math::BigFloat->new("0.00");
|
||||
my $TWO_CENTS = Math::BigFloat->new("0.02");
|
||||
|
||||
if (@ARGV < 2) {
|
||||
print STDERR "usage: $0 <START_DATE> <END_DATE> <LEDGER_OPTIONS>\n";
|
||||
exit 1;
|
||||
}
|
||||
my($startDate, $endDate, @mainLedgerOptions) = @ARGV;
|
||||
|
||||
my $err;
|
||||
my $formattedEndDate = UnixDate(DateCalc(ParseDate($endDate), ParseDateDelta("- 1 day"), \$err),
|
||||
"%Y/%m/%d");
|
||||
die "Date calculation error on $endDate" if ($err);
|
||||
my $formattedStartDate = UnixDate(ParseDate($startDate), "%Y/%m/%d");
|
||||
die "Date calculation error on $startDate" if ($err);
|
||||
|
||||
my(@ledgerOptions) = (@mainLedgerOptions,
|
||||
'-V', '-X', '$', '-F',
|
||||
'\"%(tag("Invoice"))\",\"%A\",\"%(date)\",\"%(payee)\",\"%22.108t\"\n',
|
||||
'--limit', 'tag("Invoice") !~ /^\s*$/', 'reg');
|
||||
|
||||
my @possibleTypes = ('Accrued:Loans Receivable', 'Accrued:Accounts Payable',
|
||||
'Accrued:Accounts Receivable', 'Accrued:Expenses');
|
||||
|
||||
|
||||
foreach my $type (@possibleTypes) {
|
||||
open(LEDGER_FUNDS, "-|", $LEDGER_CMD, @ledgerOptions, "/^$type/")
|
||||
or die "Unable to run $LEDGER_CMD @ledgerOptions: $!";
|
||||
|
||||
while (my $line = <LEDGER_FUNDS>) {
|
||||
next if $line =~ /"\<Adjustment\>"/;
|
||||
die "Unable to parse output line $line from @ledgerOptions"
|
||||
|
||||
unless $line =~ /^\s*"([^"]+)","([^"]+)","([^"]+)","([^"]+)","\s*\$\s*([\-\d\.\,]+)"\s*$/;
|
||||
my($invoice, $account, $date, $payee, $amount) = ($1, $2, $3, $4, $5);
|
||||
$amount = ParseNumber($amount);
|
||||
}
|
||||
}
|
||||
###############################################################################
|
||||
#
|
||||
# Local variables:
|
||||
# compile-command: "perl -c unpaid-accruals-report.plx"
|
||||
# End:
|
||||
|
||||
Loading…
Add table
Reference in a new issue