add less than and greater than amounts to credit and payment searches
[freeside.git] / httemplate / search / cust_credit.html
1 %
2 %   my $title = 'Credit Search Results';
3 %   #my( $count_query, $sql_query );
4 %
5 %   my @search = ();
6 %
7 %   if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
8 %     push @search, "cust_credit.otaker = '$1'";
9 %   }
10 %
11 %   if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
12 %     push @search, "agentnum = $1";
13 %     my $agent = qsearchs('agent', { 'agentnum' => $1 } );
14 %     die "unknown agentnum $1" unless $agent;
15 %     $title = $agent->agent. " $title";
16 %   }
17 %
18 %   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
19 %   push @search, "_date >= $beginning ",
20 %                 "_date <= $ending";
21 %
22 %   push @search, FS::UI::Web::parse_lt_gt($cgi, 'amount' );
23 %
24 %   #here is the agent virtualization
25 %   push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
26 %
27 %   my $where = 'WHERE '. join(' AND ', @search);
28 %
29 %   my $count_query = 'SELECT COUNT(*), SUM(amount) '.
30 %                     'FROM cust_credit LEFT JOIN cust_main USING ( custnum ) '.
31 %                     $where;
32 %
33 %   my $sql_query   = {
34 %     'table'     => 'cust_credit',
35 %     'select'    => join(', ',
36 %                      'cust_credit.*',
37 %                      'cust_main.custnum as cust_main_custnum',
38 %                      FS::UI::Web::cust_sql_fields(),
39 %                    ),
40 %     'hashref'   => {},
41 %     'extra_sql' => $where,
42 %     'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
43 %   };
44 %
45 %     my $clink = sub {
46 %       my $cust_bill = shift;
47 %       $cust_bill->cust_main_custnum
48 %         ? [ "${p}view/cust_main.cgi?", 'custnum' ]
49 %         : '';
50 %     };
51 %
52 %
53 <% include( 'elements/search.html',
54                  'title'       => $title,
55                  'name'        => 'credits',
56                  'query'       => $sql_query,
57                  'count_query' => $count_query,
58                  'count_addl'  => [ '$%.2f total credited', ],
59                  #'redirect'    => $link,
60                  'header'      => [ 'Amount',
61                                     'Date',
62                                     FS::UI::Web::cust_header(),
63                                     'By',
64                                     'Reason'
65                                   ],
66                  'fields'      => [
67                    #'crednum',
68                    sub { sprintf('$%.2f', shift->amount ) },
69                    sub { time2str('%b %d %Y', shift->_date ) },
70                    \&FS::UI::Web::cust_fields,
71                    'otaker',
72                    'reason',
73                  ],
74                  #'align' => 'rrrllll',
75                  'align' => 'rr',
76                  'links' => [
77                    '',
78                    '',
79                    ( map { $clink } FS::UI::Web::cust_header() ),
80                    '',
81                    '',
82                  ],
83       )
84 %>