X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_receivables.cgi;h=6e5893870e35e61808eadc7b3f9d9ce568be2a61;hb=db4034e2019cb6c7f455640b89e8d5fedeb28932;hp=fdd3779a983e2d0f521da586d0a31af4767a82cb;hpb=0ebeec96313dd7edfca340f01f8fbbbac1f4aa1d;p=freeside.git
diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi
index fdd3779a9..6e5893870 100755
--- a/httemplate/search/report_receivables.cgi
+++ b/httemplate/search/report_receivables.cgi
@@ -1,19 +1,229 @@
-
-<%
+<% include( 'elements/search.html',
+ 'title' => 'Accounts Receivable Aging Summary',
+ 'name' => 'customers',
+ 'query' => $sql_query,
+ 'count_query' => $count_sql,
+ 'header' => [
+ FS::UI::Web::cust_header(),
+ #'Status', # (me)',
+ #'Status', # (cust_main)',
+ '0-30',
+ '30-60',
+ '60-90',
+ '90+',
+ 'Total',
+ ],
+ 'footer' => [
+ 'Total',
+ ( map '',
+ ( 1 ..
+ scalar(FS::UI::Web::cust_header()-1)
+ )
+ ),
+ #'',
+ #'',
+ sprintf( $money_char.'%.2f',
+ $row->{'owed_0_30'} ),
+ sprintf( $money_char.'%.2f',
+ $row->{'owed_30_60'} ),
+ sprintf( $money_char.'%.2f',
+ $row->{'owed_60_90'} ),
+ sprintf( $money_char.'%.2f',
+ $row->{'owed_90_0'} ),
+ sprintf( ''. $money_char.'%.2f'. '',
+ $row->{'owed_0_0'} ),
+ ],
+ 'fields' => [
+ \&FS::UI::Web::cust_fields,
+ #sub { ( &{$status_statuscol}(shift) )[0] },
+ #sub { ucfirst(shift->status) },
+ sub { sprintf( $money_char.'%.2f',
+ shift->get('owed_0_30') ) },
+ sub { sprintf( $money_char.'%.2f',
+ shift->get('owed_30_60') ) },
+ sub { sprintf( $money_char.'%.2f',
+ shift->get('owed_60_90') ) },
+ sub { sprintf( $money_char.'%.2f',
+ shift->get('owed_90_0') ) },
+ sub { sprintf( $money_char.'%.2f',
+ shift->get('owed_0_0') ) },
+ ],
+ 'links' => [
+ ( map { $_ ne 'Cust. Status' ? $clink : '' }
+ FS::UI::Web::cust_header()
+ ),
+ #'',
+ #'',
+ '',
+ '',
+ '',
+ '',
+ '',
+ ],
+ #'align' => 'rlccrrrrr',
+ 'align' => FS::UI::Web::cust_aligns(). 'rrrrr',
+ #'size' => [ '', '', '-1', '-1', '', '', '', '', '', ],
+ #'style' => [ '', '', 'b', 'b', '', '', '', '', 'b', ],
+ 'size' => [ ( map '', FS::UI::Web::cust_header() ),
+ #'-1', '', '', '', '', '', ],
+ '', '', '', '', '', ],
+ 'style' => [ FS::UI::Web::cust_styles(),
+ #'b', '', '', '', '', 'b', ],
+ '', '', '', '', 'b', ],
+ 'color' => [
+ FS::UI::Web::cust_colors(),
+ #sub { ( &{$status_statuscol}(shift) )[1] },
+ #sub { shift->statuscolor; },
+ '',
+ '',
+ '',
+ '',
+ '',
+ ],
-my $user = getotaker;
+ )
+%>
+<%once>
+
+sub owed {
+ my($start, $end, %opt) = @_;
+
+ my @where = ();
+
+ #handle start and end ranges
+
+ #24h * 60m * 60s
+ push @where, "cust_bill._date <= extract(epoch from now())-".
+ ($start * 86400)
+ if $start;
+
+ push @where, "cust_bill._date > extract(epoch from now()) - ".
+ ($end * 86400)
+ if $end;
+
+ #handle 'cust' option
+
+ push @where, "cust_main.custnum = cust_bill.custnum"
+ if $opt{'cust'};
+
+ #handle 'agentnum' option
+ my $join = '';
+ if ( $opt{'agentnum'} ) {
+ $join = 'LEFT JOIN cust_main USING ( custnum )';
+ push @where, "agentnum = '$opt{'agentnum'}'";
+ }
-print header('Current Receivables Report Results');
+ my $where = scalar(@where) ? 'WHERE '.join(' AND ', @where) : '';
-open (REPORT, "freeside-receivables-report -v $user |");
+ my $as = $opt{'noas'} ? '' : "as owed_${start}_$end";
+
+ my $charged = <';
-while() {
- print $_;
}
-print '';
-print '