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 for my $param (qw(agentnum magic status classnum pkgpart)) {
15   $search_hash{$param} = $cgi->param($param)
16     if $cgi->param($param);
17 }
18
19 ###
20 # parse dates
21 ###
22
23 #false laziness w/report_cust_pkg.html
24 my %disable = (
25   'all'             => {},
26   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
27   'active'          => { 'susp'=>1, 'cancel'=>1 },
28   'suspended'       => { 'cancel' => 1 },
29   'cancelled'       => {},
30   ''                => {},
31 );
32
33 foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end change_date cancel active )) {
34
35   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
36
37   next if $beginning == 0 && $ending == 4294967295
38        or $disable{$cgi->param('status')}->{$field};
39
40   $search_hash{$field} = [ $beginning, $ending ];
41
42 }
43
44 my $sql_query = FS::cust_pkg->search(\%search_hash);
45 $sql_query->{'select'} = 'cust_pkg.pkgnum';
46
47 my $error = FS::cust_pkg::bulk_change( [ $cgi->param('new_pkgpart') ],
48                                        [ map { $_->pkgnum } qsearch($sql_query) ],
49                                      );
50
51 $cgi->param("error", substr($error, 0, 512)); # arbitrary length believed
52                                               # suited for all supported
53                                               # browsers
54
55
56 </%init>