oops
[freeside.git] / httemplate / search / report_receivables.cgi
1 <% include( 'elements/cust_main_dayranges.html',
2                  'title'       => 'Accounts Receivable Aging Summary',
3                  'range_sub'   => \&balance,
4           )
5 %>
6 <%init>
7
8 die "access denied"
9   unless $FS::CurrentUser::CurrentUser->access_right('Receivables report')
10       or $FS::CurrentUser::CurrentUser->access_right('Financial reports');
11
12 </%init>
13 <%once>
14
15 #Example:
16 #
17 # my $balance = balance(
18 #   $start, $end, 
19 #   'no_as'  => 1, #set to true when using in a WHERE clause (supress AS clause)
20 #                 #or 0 / omit when using in a SELECT clause as a column
21 #                 #  ("AS balance_$start_$end")
22 #   'sum'    => 1, #set to true to get a SUM() of the values, for totals
23 #
24 #   #obsolete? options for totals (passed to cust_main::balance_date_sql)
25 #   'total'  => 1, #set to true to remove all customer comparison clauses
26 #   'join'   => $join,   #JOIN clause
27 #   'where'  => \@where, #WHERE clause hashref (elements "AND"ed together)
28 # )
29
30 sub balance {
31   my($start, $end) = @_; #, %opt ?
32
33   #handle start and end ranges (86400 = 24h * 60m * 60s)
34   my $str2time = str2time_sql;
35   my $closing = str2time_sql_closing;
36   $start = $start ? "( $str2time now() $closing - ".($start * 86400). ' )' : '';
37   $end   = $end   ? "( $str2time now() $closing - ".($end   * 86400). ' )' : '';
38
39   #$opt{'unapplied_date'} = 1;
40
41   FS::cust_main->balance_date_sql( $start, $end, 'unapplied_date'=>1,);
42
43 }
44
45 </%once>