Revert "RT# 39340 - configured the minimal selfservice to get mac address from radius...
[freeside.git] / httemplate / search / cust_bill_void.html
1 <& elements/search.html,
2                  'title'       => emt('Voided Invoice Search Results'),
3                  'name'        => 'voided invoices',
4                  'query'       => $sql_query,
5                  'count_query' => $count_query,
6                  'count_addl'  => $count_addl,
7                  'redirect'    => $link,
8                  'header'      => [ emt('Invoice #'),
9                                     emt('Amount'),
10                                     emt('Date'),
11                                     FS::UI::Web::cust_header(),
12                                     emt('Voided by'),
13                                     emt('Date'),
14                                     emt('Reason'),
15                                   ],
16                  'fields'      => [
17                    'display_invnum',
18                    sub { sprintf($money_char.'%.2f', shift->charged     ) },
19                    sub { time2str('%b %d %Y', shift->_date ) },
20                    \&FS::UI::Web::cust_fields,
21                    'username',
22                    sub { time2str('%b %d %Y', shift->void_date) },
23                    'reason',
24                  ],
25                  'sort_fields' => [
26                    'COALESCE( agent_invid, invnum )',
27                    'charged',
28                    '_date',
29                    FS::UI::Web::cust_sort_fields(),
30                    'username',
31                    'void_date',
32                    'reason',
33                  ],
34                  'align' => 'rrl'.FS::UI::Web::cust_aligns().'lll',
35                  'links' => [
36                    $link,
37                    $link,
38                    $link,
39                    ( map { $_ ne 'Cust. Status' ? $clink : '' }
40                          FS::UI::Web::cust_header()
41                    ),
42                    $link,
43                    $link,
44                  ],
45                  'color' => [ 
46                               '',
47                               '',
48                               '',
49                               FS::UI::Web::cust_colors(),
50                             ],
51                  'style' => [ 
52                               '',
53                               '',
54                               '',
55                               FS::UI::Web::cust_styles(),
56                             ],
57 &>
58 <%init>
59
60 die "access denied"
61   unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
62   # or something else?
63
64 my $conf = new FS::Conf;
65 my $money_char = $conf->config('money_char') || '$';
66
67 my $addl_from =
68   ' LEFT JOIN access_user ON (cust_bill_void.void_usernum = access_user.usernum) '.
69    FS::UI::Web::join_cust_main('cust_bill_void');
70 #here is the agent virtualization
71 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
72
73 my( $count_query, $sql_query );
74 my $count_addl = '';
75 my %search;
76
77 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
78
79   my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
80   my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
81   
82   $count_query = "SELECT COUNT(*) FROM cust_bill_void $addl_from $where";
83
84   $sql_query = {
85     'table'     => 'cust_bill_void',
86     'addl_from' => $addl_from,
87     'hashref'   => {},
88     'extra_sql' => $where,
89   };
90
91 } else {
92
93   #some false laziness w/cust_bill::re_X
94   my $orderby = 'ORDER BY cust_bill_void._date';
95
96   if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
97     $search{'agentnum'} = $1;
98   }
99
100   if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
101     $search{'refnum'} = $1;
102   }
103
104 if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
105     $search{'cust_classnum'} = [ $cgi->param('cust_classnum') ];
106   }
107
108   if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
109     $search{'custnum'} = $1;
110   }
111
112   # begin/end/beginning/ending
113   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
114   $search{'_date'} = [ $beginning, $ending ]
115     unless $beginning == 0 && $ending == 4294967295;
116
117   ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'void_');
118   $search{'void_date'} = [ $beginning, $ending ]
119     unless $beginning == 0 && $ending == 4294967295;
120
121   if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
122     $search{'invnum_min'} = $1;
123   }
124   if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
125     $search{'invnum_max'} = $1;
126   }
127
128   #amounts
129   $search{'charged'} = [ FS::UI::Web::parse_lt_gt($cgi, 'charged') ];
130
131   my $extra_sql = FS::cust_bill_void->search_sql_where( \%search );
132   $extra_sql = "WHERE $extra_sql" if $extra_sql;
133
134   unless ( $count_query ) {
135     $count_query = 'SELECT COUNT(*), SUM(charged)';
136     $count_addl = [ $money_char . '%.2f voided' ];
137   }
138   $count_query .=  " FROM cust_bill_void $addl_from $extra_sql";
139
140   $sql_query = {
141     'table'     => 'cust_bill_void',
142     'addl_from' => $addl_from,
143     'hashref'   => {},
144     'select'    => join(', ',
145                      'cust_bill_void.*',
146                      #( map "cust_main.$_", qw(custnum last first company) ),
147                      'cust_main.custnum as cust_main_custnum',
148                      FS::UI::Web::cust_sql_fields(),
149                      'access_user.username',
150                    ),
151     'extra_sql' => $extra_sql,
152     'order_by'  => $orderby,
153   };
154
155 }
156 my $link  = [ "${p}view/cust_bill_void.html?", 'invnum', ];
157 my $clink = sub {
158   my $cust_bill = shift;
159   $cust_bill->cust_main_custnum
160     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
161     : '';
162 };
163
164 # really don't want the ability to print/spool/email voided invoices
165 </%init>