1 <% include( 'elements/search.html',
2 'title' => 'Unprovisioned Service Search Results',
3 'name' => 'packages with unprovisioned services',
11 # everything fails gloriously otherwise
12 'cust_pkg.custnum as cust_main_custnum',
14 FS::UI::Web::cust_sql_fields(),
16 'extra_sql' => $search,
17 'addl_from' => $addl_from,
19 'count_query' => $count_query,
20 'header' => [ 'Package',
21 'Unprovisioned Services',
22 FS::UI::Web::cust_header(),
30 my @available_part_svc = $cust_pkg->available_part_svc;
32 foreach my $part_svc ( @available_part_svc ) {
33 $out .= $part_svc->svc . ' ('
34 . $part_svc->num_avail . ')<BR>'
35 if grep{ $part_svc->svcpart eq $_ } @svcpart;
39 \&FS::UI::Web::cust_fields,
41 'align' => 'll'.FS::UI::Web::cust_aligns(),
45 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
46 FS::UI::Web::cust_header()
51 FS::UI::Web::cust_colors(),
55 FS::UI::Web::cust_styles(),
62 unless $FS::CurrentUser::CurrentUser->access_right('List services');
64 my $svcpart_limit = "";
65 my @svcpart = $cgi->param('svcpart');
66 foreach my $svcpart ( @svcpart ) {
67 die 'invalid svcpart' if $svcpart !~ /^\d+$/;
69 $svcpart_limit = " and pkg_svc.svcpart in (". join(',',@svcpart) . ")"
72 my $search = " where cust_pkg.cancel is null and pkg_svc.quantity > 0 and "
73 . " pkg_svc.quantity > (select count(1) from cust_svc where "
74 . " cust_svc.pkgnum = cust_pkg.pkgnum and "
75 . " cust_svc.svcpart = pkg_svc.svcpart) $svcpart_limit";
77 my $addl_from = " join pkg_svc using (pkgpart) join cust_main using (custnum) ";
79 # this was very painful to derive but it appears correct
80 #select cust_pkg.custnum,cust_pkg.pkgpart,cust_pkg.pkgnum, pkg_svc.svcpart from cust_pkg join
81 #pkg_svc using (pkgpart) where cancel is null and pkg_svc.quantity > 0 and pkg_svc.quantity >
82 #(select count(1) from cust_svc where cust_svc.pkgnum = cust_pkg.pkgnum and cust_svc.svcpart =
83 #pkg_svc.svcpart) order by pkgnum, svcpart;
85 my $count_query = "select count(*) from cust_pkg $addl_from $search";
88 return [ "${p}view/cust_main.cgi?", 'custnum' ];