X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_prepaid_income.cgi;h=27dbcbf9f86acb88673681db4ac5ca5491fdd7a1;hb=12c2362c84bea9f2e03ed9c67b2de8d453202ebf;hp=241e8a0089fc48057d78412e228ad609e1d047b8;hpb=3ce7691203a7737406bf2d4442f7fd84b81f847e;p=freeside.git diff --git a/httemplate/search/report_prepaid_income.cgi b/httemplate/search/report_prepaid_income.cgi index 241e8a008..27dbcbf9f 100644 --- a/httemplate/search/report_prepaid_income.cgi +++ b/httemplate/search/report_prepaid_income.cgi @@ -1,67 +1,5 @@ - -% -% -% #doesn't yet deal with daily/weekly packages -% -% #needs to be re-written in sql for efficiency -% -% my $time = time; -% -% my $now = $cgi->param('date') && str2time($cgi->param('date')) || $time; -% $now =~ /^(\d+)$/ or die "unparsable date?"; -% $now = $1; -% -% my( $total, $total_legacy ) = ( 0, 0 ); -% -% my @cust_bill_pkg = -% grep { $_->cust_pkg && $_->cust_pkg->part_pkg->freq !~ /^([01]|\d+[dw])$/ } -% qsearch( 'cust_bill_pkg', { -% 'recur' => { op=>'!=', value=>0 }, -% 'edate' => { op=>'>', value=>$now }, -% }, ); -% -% my @cust_pkg = -% grep { $_->part_pkg->recur != 0 -% && $_->part_pkg->freq !~ /^([01]|\d+[dw])$/ -% } -% qsearch ( 'cust_pkg', { -% 'bill' => { op=>'>', value=>$now } -% } ); -% -% foreach my $cust_bill_pkg ( @cust_bill_pkg) { -% my $period = $cust_bill_pkg->edate - $cust_bill_pkg->sdate; -% -% my $elapsed = $now - $cust_bill_pkg->sdate; -% $elapsed = 0 if $elapsed < 0; -% -% my $remaining = 1 - $elapsed/$period; -% -% my $unearned = $remaining * $cust_bill_pkg->recur; -% $total += $unearned; -% -% } -% -% 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); -% -% - - -<% include("/elements/header.html", 'Prepaid Income (Unearned Revenue) Report', - menubar( 'Main Menu'=>$p, ) ) %> +<% include("/elements/header.html", 'Prepaid Income (Unearned Revenue) Report') %> + <% table() %> Actual Unearned Revenue @@ -85,3 +23,65 @@ revenue if you have imported longer-than monthly customer packages from a previous billing system. +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); + +#doesn't yet deal with daily/weekly packages + +#needs to be re-written in sql for efficiency + +my $time = time; + +my $now = $cgi->param('date') && str2time($cgi->param('date')) || $time; +$now =~ /^(\d+)$/ or die "unparsable date?"; +$now = $1; + +my( $total, $total_legacy ) = ( 0, 0 ); + +my @cust_bill_pkg = + grep { $_->cust_pkg && $_->cust_pkg->part_pkg->freq !~ /^([01]|\d+[dw])$/ } + qsearch( 'cust_bill_pkg', { + 'recur' => { op=>'!=', value=>0 }, + 'edate' => { op=>'>', value=>$now }, + }, ); + +my @cust_pkg = + grep { $_->part_pkg->recur != 0 + && $_->part_pkg->freq !~ /^([01]|\d+[dw])$/ + } + qsearch ( 'cust_pkg', { + 'bill' => { op=>'>', value=>$now } + } ); + +foreach my $cust_bill_pkg ( @cust_bill_pkg) { + my $period = $cust_bill_pkg->edate - $cust_bill_pkg->sdate; + + my $elapsed = $now - $cust_bill_pkg->sdate; + $elapsed = 0 if $elapsed < 0; + + my $remaining = 1 - $elapsed/$period; + + my $unearned = $remaining * $cust_bill_pkg->recur; + $total += $unearned; + +} + +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); + +