fix upgrade for dangling cust_event_fee (how?), RT#75113
[freeside.git] / httemplate / search / cust_pkg_svc.html
1 <& elements/search.html,
2               'title'       => $part_svc->svc.' services in package #'.$pkgnum,
3               'name'        => 'services',
4               'html_form'   => $html_form,
5               'query'       => $sql_query,
6               'count_query' => $count_query,
7               'redirect'    => $link,
8               'header'      => [ '#',
9                                  'Service',
10                                  '', #checkboxes
11                                ],
12               'fields'      => [ 'svcnum',
13                                  sub {
14                                    ($_[0]->label)[1]
15                                  },
16                                  sub {
17                                    $areboxes = 1;
18                                    '<INPUT TYPE="checkbox" NAME="svcnum" VALUE='.$_[0]->svcnum.'>'
19                                  },
20                                ],
21               'links'       => [ $link,
22                                  $link,
23                                  '',
24                                ],
25               'align' => 'rrlc',
26               'color' => [ 
27                            ('')x4,
28                          ],
29               'style' => [ 
30                            ('')x4,
31                          ],
32               'html_foot' => sub { $areboxes ? $html_foot : '' }
33           
34 &>
35 <%init>
36
37 die "access denied"
38   unless $FS::CurrentUser::CurrentUser->access_right('List services');
39
40 my $pkgnum = $cgi->param('pkgnum');
41 $pkgnum =~ /^(\d+)$/ or die "invalid pkgnum: $pkgnum";
42 my @extra_sql = ( "cust_svc.pkgnum = $pkgnum" );
43
44 my $svcpart = $cgi->param('svcpart');
45 $svcpart =~ /^(\d+)$/ or die "invalid svcpart: $svcpart";
46 push @extra_sql, "cust_svc.svcpart = $svcpart";
47 my $part_svc = qsearchs('part_svc', {svcpart => $svcpart});
48 my $svcdb = $part_svc->svcdb;
49
50 my $orderby = 'ORDER BY svcnum'; #others?
51
52 my $addl_from = " LEFT JOIN part_svc USING (svcpart)
53 LEFT JOIN cust_pkg USING (pkgnum)
54 LEFT JOIN cust_main USING (custnum)
55 INNER JOIN $svcdb USING (svcnum)";
56
57 my $search_string;
58 if ( length( $cgi->param('search_svc') ) ) {
59
60   $search_string = $cgi->param('search_svc');
61   $search_string =~ s/(^\s+|\s+$)//;
62   push @extra_sql, "FS::$svcdb"->search_sql($search_string);
63
64 }
65
66 #here is the agent virtualization
67 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 
68                    'null_right' => 'View/link unlinked services'
69                  );
70
71 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
72
73 my $sql_query = {
74   'select'     => join(', ',
75                     'cust_svc.*',
76                     'part_svc.svc',
77                   ),
78   'table'      => 'cust_svc',
79   'addl_from'  => $addl_from,
80   'hashref'    => {},
81   'extra_sql'  => $extra_sql,
82   'order_by'   => $orderby,
83 };
84
85 #warn Dumper($sql_query)."\n";
86
87 my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";
88
89 my $link = sub {
90   my $cust_svc = shift;
91   my $url = svc_url(
92     'm'        => $m,
93     'action'   => 'view',
94     'svcdb'    => $svcdb,
95     'query'     => '',
96   );
97   [ $url, 'svcnum' ];
98 };
99
100 my $html_form = qq!
101 <SCRIPT TYPE="text/javascript">
102 function areyousure(obj) {
103   return confirm('Permanently delete the selected services?');
104 }
105 </SCRIPT>
106 <FORM METHOD="POST" ACTION="${p}misc/unprovision.cgi" onsubmit="return areyousure()">!; 
107
108 my $areboxes = 0;
109
110 my $html_foot = qq!
111 <BR>
112 <INPUT TYPE="submit" NAME="submit" VALUE="Unprovision selected">
113 <INPUT TYPE="hidden" NAME="pkgnum" VALUE=$pkgnum>
114 <INPUT TYPE="hidden" NAME="svcpart" VALUE=$svcpart>
115 </FORM>!;
116
117
118 </%init>