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;
40 % $total += $unearned;
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);
63 <% include("/elements/header.html", 'Prepaid Income (Unearned Revenue) Report',
64 menubar( 'Main Menu'=>$p, ) ) %>
67 <TH>Actual Unearned Revenue</TH>
68 <TH>Legacy Unearned Revenue</TH>
71 <TD ALIGN="right">$<% $total %>
73 <% $now == $time ? "\$$total_legacy" : '<i>N/A</i>'%>
79 Actual unearned revenue is the amount of unearned revenue Freeside has
80 actually invoiced for packages with longer-than monthly terms.
82 Legacy unearned revenue is the amount of unearned revenue represented by
83 customer packages. This number may be larger than actual unearned
84 revenue if you have imported longer-than monthly customer packages from
85 a previous billing system.