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