[BACK]Return to report_income.pl CVS log [TXT][DIR] Up to [local] / RT / Invoicing

File: [local] / RT / Invoicing / report_income.pl (download)

Revision 1.1, Thu Aug 20 02:11:55 2020 UTC (3 years, 8 months ago) by afresh1
Branch: MAIN
CVS Tags: HEAD

Add some helper tools

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

use lib 'lib';
use RTI::State;

use YAML::XS qw/ Dump /;

my $state = RTI::State->new('rt_invoice.state');

my %income;
while (my ($id, $i) = each %{ $state->{invoice} }) {
	next if $i->{void};
	next unless $i->{custid};
	#next unless $i->{custid} eq 'WireFree';
	#next unless $i->{custid} eq 'speakman';
	#next unless $i->{custid} eq 'jscherz@itc-home.com';

	my $unpaid = $state->unpaid_invoices($i->{custid});

	my $date = $i->{end} || $i->{invdate};
	my ($y, $m) = split /-/, $date;

	foreach my $mk ('', "$i->{custid} ") {
		foreach my $sk ($y, 'Total')  {
			my $k = "$mk$sk";
			$income{$k} //= { billed => 0, unpaid => 0 };
			$income{$k}{billed}   += $i->{total};
			$income{$k}{unpaid} += $unpaid->{ $id } if $unpaid->{$id};
		}
	}
}

print Dump \%income;