-<%= header( 'Prepaid Income (Unearned Revenue) Report',
- menubar( 'Main Menu'=>$p, ) ) %>
-<%= table() %>
-<%
-
- my $total = 0;
-
- my ($now_mon, $now_year) = (localtime($now))[4,5];
- $now_mon+=2; $now_year+=1900;
- until ( $now_mon < 13 ) { $now_mon -= 12; $now_year++; }
-
- my $subseq = 0;
- for my $year ( $now_year .. 2037 ) {
- for my $mon ( ( $subseq++ ? 1 : $now_mon ) .. 12 ) {
- if ( $prepaid{"$year-$mon"} ) {
- $total += $prepaid{"$year-$mon"};
- %> <TR><TD ALIGN="right"><%= $mon[$mon-1]. ' '. $year %></TD>
- <TD ALIGN="right">
- <%= sprintf("%.2f", $prepaid{"$year-$mon"} ) %>
- </TD>
- </TR>
- <%
- }
- }
-
- }
-
-%>
-<TR><TH>Total</TH><TD ALIGN="right"><%= sprintf("%.2f", $total) %></TD></TR>
-</TABLE>
-</BODY>
-</HTML>
+}
+
+foreach my $cust_pkg ( @cust_pkg ) {
+ my $period = $cust_pkg->bill - $cust_pkg->last_bill;
+
+ my $elapsed = $now - $cust_pkg->last_bill;
+ $elapsed = 0 if $elapsed < 0;
+
+ my $remaining = 1 - $elapsed/$period;
+
+ my $unearned = $remaining * $cust_pkg->part_pkg->recur; #!! only works for flat/legacy
+ $total_legacy += $unearned;
+
+}
+
+$total = sprintf('%.2f', $total);
+$total_legacy = sprintf('%.2f', $total_legacy);
+
+</%init>