clean up package list UI: put actions in a dropdown
[freeside.git] / httemplate / view / cust_main / packages / section.html
1 % if ( @$packages ) { 
2 <THEAD>
3 <TR>
4 % #my $width = $show_location ? 'WIDTH="25%"' : 'WIDTH="33%"';
5   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Package') |h %></TH>
6   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Status') |h %></TH>
7   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Contact/Location') |h %></TH>
8 % if (!$opt{no_services}) {
9   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Services') |h %></TH>
10 % }
11 </TR>
12 </THEAD>
13
14 % #$FS::cust_pkg::DEBUG = 2;
15 %   foreach my $cust_pkg (@$packages) {
16 %    # if requested, this can override cust_pkg-group_by_location
17     <& .packagerow, $cust_pkg,
18         %conf_opt,
19         ( map { $_ => $opt{$_} } qw(
20             cust_main bgcolor no_links cust_location_cache
21             before_pkg_callback before_svc_callback after_svc_callback
22             cust_pkg-group_by_location
23             no_services
24         )),
25         #for status.html
26         'has_cust_payby_auto' => $opt{cust_main}->has_cust_payby_auto,
27     &>
28 %   }
29 % } else { # there are no packages
30 <BR>
31 % }
32 <%def .packagerow>
33 %
34 % my ($cust_pkg, %iopt) = @_;
35 % $iopt{'cust_pkg'} = $cust_pkg;
36 % $iopt{'part_pkg'} = $cust_pkg->part_pkg;
37 % $iopt{'row'} = $row;
38   <!--pkgnum: <% $cust_pkg->pkgnum %>-->
39   <TR CLASS="row<%$row % 2%>">
40     <& package.html, %iopt &>
41     <& status.html,  %iopt &>
42     <TD CLASS="inv" BGCOLOR="<% $iopt{bgcolor} %>" WIDTH="20%" VALIGN="top">
43       <& contact.html, %iopt &>
44       <& location.html, %iopt &>
45     </TD>
46 %   if (!$iopt{no_services}) {
47     <& services.html, %iopt &>
48 %   }
49   </TR>
50 % # insert hidden predecessors to this package, if any
51 % # and a rolldown button to show them
52 % # (we'll make it do something later)
53 % if ( $cust_pkg->get('changed_from_pkg') ) {
54   <TR CLASS="row<% $row % 2 %>">
55     <TD COLSPAN=4>
56     <BUTTON CLASS="rolldown_button"
57             ID="rolldown_<% $cust_pkg->change_pkgnum %>">
58       History &#x2b07;
59     </BUTTON>
60 % # the hidden block here has ID="cust_pkgX" where X is the first pkgnum
61 % # it contains.
62     <& hidden.html, $cust_pkg->get('changed_from_pkg'),
63        %iopt,
64        'next_pkg' => $cust_pkg,
65     &>
66     </TD>
67   </TR>
68 % }
69 % $row++;
70 % # show the change target, if there is one
71 % if ( $cust_pkg->change_to_pkg ) {
72     <& .packagerow, $cust_pkg->change_to_pkg, %iopt, 'change_from' => 1 &>
73 % }
74 % # include supplemental packages if any
75 % if ( $cust_pkg->_supplemental ) {
76 %   $iopt{'supplemental'} = ($iopt{'supplemental'} || 0) + 1;
77 %   foreach my $supp_pkg (@{ $cust_pkg->_supplemental }) {
78       <& .packagerow, $supp_pkg, %iopt &>
79 %   }
80 % }
81 </%def>
82 <%shared>
83 my $row = 0;
84 </%shared>
85 <%init>
86
87 my %opt = @_;
88 my $conf = new FS::Conf;
89
90 my $curuser = $FS::CurrentUser::CurrentUser;
91
92 my $packages = $opt{'packages'};
93
94 # Sort order is hardcoded for now, can change this if needed.
95 @$packages = sort { 
96   ( $a->getfield('cancel') <=> $b->getfield('cancel') )  or
97   ( $a->getfield('setup')  <=> $b->getfield('setup')  )  or
98   ( $a->getfield('pkgnum') <=> $b->getfield('pkgnum') )
99 } @$packages;
100
101 my %change_custnum = map { $_->change_custnum => 1 }
102                        grep { $_->change_custnum }
103                          grep { $_->getfield('cancel') }
104                            @$packages;
105
106 my $pkg_attached = ( scalar(keys %change_custnum) == 1
107                        && ! grep { ! $_->getfield('cancel') } @$packages
108                    );
109
110 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';  
111
112 my %conf_opt = (
113   #for package.html
114   'invoice-unitprice'         => $conf->exists('invoice-unitprice'),
115   'show_pkgnum'               => $curuser->option('show_pkgnum'),
116   'part_pkg-term_discounts'   => $conf->exists('part_pkg-term_discounts'),
117
118   #for services.html and status.html
119   'cust_pkg-display_times'    => ($conf->exists('cust_pkg-display_times')
120                                  || $curuser->option('cust_pkg-display_times')),
121   #for status.html
122   'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
123   'pkg_attached'              => $pkg_attached,
124   'part_pkg-delay_cancel-days' => $conf->config('part_pkg-delay_cancel-days') || 1,
125   #for status.html pkg-balances
126   'pkg-balances'              => $conf->exists('pkg-balances'),
127   'money_char'                => ( $conf->config('money_char') || '$' ),
128
129   #for location.html
130   'countrydefault'            => $countrydefault,
131   'statedefault'              => ( scalar($conf->config('statedefault'))
132                                   || ($countrydefault eq 'US' ? 'CA' : '') ),
133   'cust_pkg-group_by_location'=> $conf->exists('cust_pkg-group_by_location'),
134   'cust_main-require_censustract'=> $conf->exists('cust_main-require_censustract'),
135   'company_address'           => [ $conf->config('company_address', $opt{cust_main}->agentnum ) ],
136   
137   #for services.html
138   'svc_external-skip_manual'  => $conf->exists('svc_external-skip_manual'),
139   'svc_phone-bulk_provision_simple' => $conf->exists('svc_phone-bulk_provision_simple'),
140   'legacy_link'               => $conf->exists('legacy_link'),
141   'manage_link'               => scalar($conf->config('svc_broadband-manage_link')),
142   'manage_link_text'          => scalar($conf->config('svc_broadband-manage_link_text')),
143   'manage_link_loc'           => scalar($conf->config('svc_broadband-manage_link_loc')),
144   'manage_link-new_window'    => $conf->exists('svc_broadband-manage_link-new_window'),
145   'cust_pkg-large_pkg_size'   => scalar($conf->config('cust_pkg-large_pkg_size')),
146   'cust_pkg-hide_discontinued-part_svc' => $conf->exists('cust_pkg-hide_discontinued-part_svc'),
147
148 );
149
150 </%init>