combine ticket notification scrips, #15353
[freeside.git] / httemplate / search / 477partV.html
1 <% include( 'elements/search.html',
2                   'html_init'         => $html_init,
3                   'name'              => 'zip code',
4                   'query'             => [ @sql_query ],
5                   'count_query'       => $count_query,
6                   'nohtmlheader'      => 1,
7                   'disable_total'     => 1,
8                   'header'            => [ 'zip code' ],
9                   'xml_elements'      => [ 'zip codes' ],
10                   'no_field_elements' => 1,
11                   'fields'            => [ 'zip' ],
12                   'url'               => $opt{url} || '',
13
14               )
15 %>
16 <%init>
17
18 my $curuser = $FS::CurrentUser::CurrentUser;
19
20 die "access denied"
21   unless $curuser->access_right('List packages');
22
23 my %opt = @_;
24 my $html_init = '<H2>Part V</H2>';
25 my %search_hash = ();
26 my @sql_query = ();
27 my @count_query = ();
28   
29 for ( qw(agentnum magic) ) {
30   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
31 }
32 $search_hash{'classnum'} = [ $cgi->param('classnum') ];
33 $search_hash{report_option} = $cgi->param('partv_report_option')
34   if $cgi->param('partv_report_option');
35
36 my $sql_query = FS::cust_pkg->search( { %search_hash, 'fcc_line' > 1 });
37 $sql_query->{select} = 'DISTINCT substr(zip,1,5) as zip';
38 $sql_query->{extra_sql} =~ s/ORDER BY [.\w]+//;
39 push @sql_query, $sql_query;
40 push @count_query, delete($sql_query->{'count_query'});
41 $count_query[0] =~ s/COUNT\(\*\)/count(DISTINCT substr(zip,1,5))/;
42 $count_query[0] =~ s/ORDER BY [.\w]+//;
43
44 $search_hash{report_option} = $cgi->param('partv_report_option')
45   if $cgi->param('partv_report_option');
46
47 $sql_query = FS::cust_pkg->search( { %search_hash } );
48 $sql_query->{select} = 'DISTINCT substr(zip,1,5) as zip';
49 $sql_query->{extra_sql} =~ s/ORDER BY [.\w]+//;
50 push @sql_query, $sql_query;
51 push @count_query, delete($sql_query->{'count_query'});
52 $count_query[1] =~ s/COUNT\(\*\)/count(DISTINCT substr(zip,1,5))/;
53 $count_query[1] =~ s/ORDER BY [.\w]+//;
54 my $count_query = join(' UNION ', @count_query);
55
56 </%init>