Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / cust_main.html
1 <& elements/search.html,
2                   'title'       => emt('Customer Search Results'), 
3                   'menubar'     => $menubar,
4                   'name'        => emt('customers'),
5                   'query'       => $sql_query,
6                   'count_query' => $count_query,
7                   'header'      => [ FS::UI::Web::cust_header(
8                                        $cgi->param('cust_fields')
9                                      ),
10                                      @extra_headers,
11                                    ],
12                   'fields'      => [
13                     \&FS::UI::Web::cust_fields,
14                     @extra_fields,
15                   ],
16                   'color'       => [ FS::UI::Web::cust_colors(),
17                                      map '', @extra_fields
18                                    ],
19                   'style'       => [ FS::UI::Web::cust_styles(),
20                                      map '', @extra_fields
21                                    ],
22                   'align'       => [ FS::UI::Web::cust_aligns(),
23                                      map '', @extra_fields
24                                    ],
25                   'links'       => [ ( map { $_ ne 'Cust. Status' ? $link : '' }
26                                            FS::UI::Web::cust_header(
27                                                       $cgi->param('cust_fields')
28                                                                    )
29                                      ),
30                                      map '', @extra_fields
31                                    ],
32 &>
33 <%init>
34
35 die "access denied"
36   unless $FS::CurrentUser::CurrentUser->access_right('Advanced customer search');
37
38 my %search_hash = ();
39
40 #$search_hash{'query'} = $cgi->keywords;
41
42 #scalars
43 my @scalars = qw (
44   agentnum status address paydate_year paydate_month invoice_terms
45   no_censustract with_geocode custbatch usernum
46   cancelled_pkgs
47   cust_fields flattened_pkgs
48 );
49
50 for my $param ( @scalars ) {
51   $search_hash{$param} = scalar( $cgi->param($param) )
52     if $cgi->param($param);
53 }
54
55 #lists
56 for my $param (qw( classnum refnum payby tagnum )) {
57   $search_hash{$param} = [ $cgi->param($param) ];
58 }
59
60 ###
61 # parse dates
62 ###
63
64 foreach my $field (qw( signupdate birthdate spouse_birthdate )) {
65
66   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
67
68   next if $beginning == 0 && $ending == 4294967295 && ( $field ne 'signupdate' || !defined($cgi->param('signuphour')) );
69        #or $disable{$cgi->param('status')}->{$field};
70
71   unless ( $field eq 'signupdate' ) {
72     $beginning -= 43200;
73     $ending    -= 43200;
74   }
75
76   my @ary = ( $beginning, $ending );
77   push @ary, scalar($cgi->param('signuphour')) if $field eq 'signupdate';
78
79   $search_hash{$field} = \@ary;
80
81 }
82
83 ##
84 # amounts
85 ##
86
87 $search_hash{'current_balance'} =
88   [ FS::UI::Web::parse_lt_gt($cgi, 'current_balance') ];
89
90 ###
91 # etc
92 ###
93
94 my $sql_query = FS::cust_main::Search->search(\%search_hash);
95 my $count_query   = delete($sql_query->{'count_query'});
96 my @extra_headers = @{ delete($sql_query->{'extra_headers'}) };
97 my @extra_fields  = @{ delete($sql_query->{'extra_fields'})  };
98
99 my $link = [ "${p}view/cust_main.cgi?", 'custnum' ];
100
101 ###
102 # email links
103 ###
104
105 my $menubar = [];
106
107 if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) {
108
109   my $uri = new URI;
110   $uri->query_form( \%search_hash );
111   my $query = $uri->query;
112
113   push @$menubar, emt('Email a notice to these customers') =>
114                     "${p}misc/email-customers.html?table=cust_main&$query",
115
116 }
117
118 </%init>