package search on null dates, RT#73715
[freeside.git] / httemplate / misc / process / bulk_change_pkg.cgi
1 % if ($error) {
2 <% $cgi->redirect(popurl(2)."/bulk_change_pkg.cgi?".$cgi->query_string ) %>
3 % }
4 <% include('/elements/header-popup.html', "Packages Changed") %>
5 <%init>
6
7 die "access denied"
8   unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages');
9
10 my %search_hash = ();
11
12 $search_hash{'query'} = $cgi->param('query');
13
14 #scalars
15 for (qw( agentnum cust_status cust_main_salesnum salesnum custnum magic status
16          custom cust_fields pkgbatch zip
17          477part 477rownum date 
18     )) 
19 {
20   $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
21 }
22
23 #arrays
24 for my $param (qw( pkgpart classnum refnum towernum )) {
25   $search_hash{$param} = [ $cgi->param($param) ]
26     if grep { $_ eq $param } $cgi->param;
27 }
28
29 #scalars that need to be passed if empty
30 for my $param (qw( censustract censustract2 )) {
31   $search_hash{$param} = $cgi->param($param) || ''
32     if grep { $_ eq $param } $cgi->param;
33 }
34
35 #location flags (checkboxes)
36 my @loc = grep /^\w+$/, $cgi->param('loc');
37 $search_hash{"location_$_"} = 1 foreach @loc;
38
39 my $report_option = $cgi->param('report_option');
40 $search_hash{report_option} = $report_option if $report_option;
41
42 for my $param (grep /^report_option_any/, $cgi->param) {
43   $search_hash{$param} = $cgi->param($param);
44 }
45
46 ###
47 # parse dates
48 ###
49
50 #false laziness w/report_cust_pkg.html and bulk_pkg_increment_bill.cgi
51 my %disable = (
52   'all'             => {},
53   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
54   'active'          => { 'susp'=>1, 'cancel'=>1 },
55   'suspended'       => { 'cancel' => 1 },
56   'cancelled'       => {},
57   ''                => {},
58 );
59
60 foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end change_date cancel active )) {
61
62   $search_hash{$field.'_null'} = scalar( $cgi->param($field.'_null') );
63
64   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
65
66   next if $beginning == 0 && $ending == 4294967295
67        or $disable{$cgi->param('status')}->{$field};
68
69   $search_hash{$field} = [ $beginning, $ending ];
70
71 }
72
73 my $sql_query = FS::cust_pkg->search(\%search_hash);
74 $sql_query->{'select'} = 'cust_pkg.pkgnum';
75
76 my $error = FS::cust_pkg::bulk_change( [ $cgi->param('new_pkgpart') ],
77                                        [ map { $_->pkgnum } qsearch($sql_query) ],
78                                      );
79
80 $cgi->param("error", substr($error, 0, 512)); # arbitrary length believed
81                                               # suited for all supported
82                                               # browsers
83
84
85 </%init>