update flat_introrate plan to better fit current codebase RT#4912
[freeside.git] / httemplate / search / report_receivables.cgi
index 3e50006..63adba0 100755 (executable)
@@ -71,7 +71,8 @@
 <%init>
 
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+  unless $FS::CurrentUser::CurrentUser->access_right('Receivables report')
+      or $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
 my @ranges = (
   [  0, 30 ],
@@ -116,6 +117,15 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   push @where, "agentnum = $agentnum";
 }
 
+#status (false laziness w/cust_main::search_sql
+
+#prospect active inactive suspended cancelled
+if ( grep { $cgi->param('status') eq $_ } FS::cust_main->statuses() ) {
+  my $method = $cgi->param('status'). '_sql';
+  #push @where, $class->$method();
+  push @where, FS::cust_main->$method();
+}
+
 #here is the agent virtualization
 push @where, $FS::CurrentUser::CurrentUser->agentnums_sql;
 
@@ -127,7 +137,13 @@ my $count_sql = "select count(*) from cust_main $where";
 my $sql_query = {
   'table'     => 'cust_main',
   'hashref'   => {},
-  'select'    => "*, $owed_cols, $packages_cols",
+  'select'    => join(',',
+                   #'cust_main.*',
+                   'custnum',
+                   $owed_cols,
+                   $packages_cols,
+                   FS::UI::Web::cust_sql_fields(),
+                 ),
   'extra_sql' => $where,
   'order_by'  => "order by coalesce(lower(company), ''), lower(last)",
 };
@@ -174,7 +190,7 @@ sub balance {
   $start = $start ? "( $str2time now() $closing - ".($start * 86400). ' )' : '';
   $end   = $end   ? "( $str2time now() $closing - ".($end   * 86400). ' )' : '';
 
-  #$opt{'unapplied_date'} = 1;
+  $opt{'unapplied_date'} = 1;
 
   ( $opt{sum} ? 'SUM( ' : '' ). 
   FS::cust_main->balance_date_sql( $start, $end, %opt ).