4 #doesn't yet deal with daily/weekly packages
6 #needs to be re-written in sql for efficiency
10 my $now = $cgi->param('date') && str2time($cgi->param('date')) || $time;
11 $now =~ /^(\d+)$/ or die "unparsable date?";
14 my( $total, $total_legacy ) = ( 0, 0 );
17 grep { $_->cust_pkg && $_->cust_pkg->part_pkg->freq !~ /^([01]|\d+[dw])$/ }
18 qsearch( 'cust_bill_pkg', {
19 'recur' => { op=>'!=', value=>0 },
20 'edate' => { op=>'>', value=>$now },
24 grep { $_->part_pkg->recur != 0
25 && $_->part_pkg->freq !~ /^([01]|\d+[dw])$/
27 qsearch ( 'cust_pkg', {
28 'bill' => { op=>'>', value=>$now }
31 foreach my $cust_bill_pkg ( @cust_bill_pkg) {
32 my $period = $cust_bill_pkg->edate - $cust_bill_pkg->sdate;
34 my $elapsed = $now - $cust_bill_pkg->sdate;
35 $elapsed = 0 if $elapsed < 0;
37 my $remaining = 1 - $elapsed/$period;
39 my $unearned = $remaining * $cust_bill_pkg->recur;
44 foreach my $cust_pkg ( @cust_pkg ) {
45 my $period = $cust_pkg->bill - $cust_pkg->last_bill;
47 my $elapsed = $now - $cust_pkg->last_bill;
48 $elapsed = 0 if $elapsed < 0;
50 my $remaining = 1 - $elapsed/$period;
52 my $unearned = $remaining * $cust_pkg->part_pkg->recur; #!! only works for flat/legacy
53 $total_legacy += $unearned;
57 $total = sprintf('%.2f', $total);
58 $total_legacy = sprintf('%.2f', $total_legacy);
62 <%= header( 'Prepaid Income (Unearned Revenue) Report',
63 menubar( 'Main Menu'=>$p, ) ) %>
66 <TH>Actual Unearned Revenue</TH>
67 <TH>Legacy Unearned Revenue</TH>
70 <TD ALIGN="right">$<%= $total %>
72 <%= $now == $time ? "\$$total_legacy" : '<i>N/A</i>'%>
78 Actual unearned revenue is the amount of unearned revenue Freeside has
79 actually invoiced for packages with longer-than monthly terms.
81 Legacy unearned revenue is the amount of unearned revenue represented by
82 customer packages. This number may be larger than actual unearned
83 revenue if you have imported longer-than monthly customer packages from
84 a previous billing system.