Annotation of RT/Invoicing/report_transactions.pl, Revision 1.1
1.1 ! afresh1 1: #!/usr/bin/perl
! 2: use strict;
! 3: use warnings;
! 4: use 5.010;
! 5:
! 6: use lib 'lib';
! 7: use RTI::State;
! 8:
! 9: use List::Util qw( sum );
! 10:
! 11: #my $custid = 'jscherz@itc-home.com';
! 12: my $custid = 'GSG';
! 13:
! 14: my $state = RTI::State->new('rt_invoice.state');
! 15:
! 16: my @payments = reverse @{ $state->{payment}->{$custid} || [] };
! 17:
! 18: my $paid = sum map { $_->{paid} } @payments;
! 19: my $invoiced = sum map { $_->{total} }
! 20: grep { $_->{custid} eq $custid } values %{ $state->{invoice} };
! 21:
! 22: my $running = 0;
! 23: foreach my $invoice ( sort { $a <=> $b } keys %{ $state->{invoice} } ) {
! 24: my $i = $state->{invoice}->{$invoice};
! 25: next unless $i->{custid};
! 26: next unless $i->{custid} eq $custid;
! 27: next if $i->{void};
! 28:
! 29: while ( @payments && $payments[0]->{date} < $i->{invdate} ) {
! 30: show_payment( shift @payments );
! 31: }
! 32:
! 33: next unless $i->{total};
! 34:
! 35: $running += $i->{total};
! 36:
! 37: my $date = $i->{invdate} ? $i->{invdate}->ymd : 'Earlier';
! 38: printf "\$%7.02f : %10s invoice %03d \$ %6.02f\n", $running,
! 39: $date, $invoice, $i->{total};
! 40: }
! 41:
! 42: show_payment($_) for @payments;
! 43:
! 44: printf "invoiced: \$ %6.02f paid: \$ %6.02f balance: \$%7.02f\n",
! 45: $invoiced,
! 46: $paid, $running;
! 47:
! 48: sub show_payment {
! 49: my ($p) = @_;
! 50: my $type = $p->{type} || '';
! 51: $type .= " $p->{number}" if $p->{number};
! 52:
! 53: my $date = $p->{date} ? $p->{date}->ymd : 'Earlier';
! 54:
! 55: $running -= $p->{paid};
! 56: printf "\$%7.02f : %10s payment for \$ %6.02f %s\n", $running, $date,
! 57: $p->{paid}, $type;
! 58: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>