future package change, #20687
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top" <%$style%>>
2   <TABLE CLASS="inv package"> 
3     <TR>
4       <TD COLSPAN=2>
5         <% $opt{before_pkg_callback}
6              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
7              : ''
8         %>
9         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
10            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
11         ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
12         - 
13         <% $part_pkg->custom_comment |h %>
14       </TD>
15     </TR>
16
17 % if ( $cust_pkg->quantity > 1 ) {
18     <TR>
19       <TD COLSPAN=2>
20         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
21         <B><% $cust_pkg->quantity %></B>
22       </TD>
23     </TR>
24 % }
25
26     <TR>
27       <TD COLSPAN=2>
28         <FONT SIZE=-1>
29
30 %         unless ( $cust_pkg->get('cancel') || $opt{no_links} ) {
31 %
32 %           if ( $change_from ) {
33 %             # This is the target package for a future change.
34 %             # Nothing you can do with it besides modify/cancel the 
35 %             # future change, and that's on the current package.
36 %           } elsif ( $supplemental or $part_pkg->freq eq '0' ) {
37 %             # Supplemental packages can't be changed independently.
38 %             # One-time charges don't need to be changed.
39 %             # For both of those, we only show "Add comments",
40 %             # and "Add invoice details".
41 %           } else {
42 %             # the usual case: links to change package definition,
43 %             # discount, and customization
44 %             my $br = 0;
45 %             if ( $curuser->access_right('Change customer package') ) {
46 %               $br=1;
47                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
48 %             } 
49 %
50 %             if ( $curuser->access_right('Discount customer package')
51 %                  && $part_pkg->can_discount
52 %                  && ! scalar($cust_pkg->cust_pkg_discount_active)
53 %                  && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
54 %                )
55 %             {
56 %               $br=1;
57                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
58 %             }
59 %
60 %             if ( $curuser->access_right('Customize customer package') ) {
61 %               $br=1;
62                 (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
63 %             } 
64 %
65               <% $br ? '<BR>' : '' %>
66 %           } 
67
68 %           if ( $cust_pkg->num_cust_event
69 %                && (    $curuser->access_right('Billing event reports')
70 %                     || $curuser->access_right('View customer billing events')
71 %                   )
72 %              ) {
73               (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
74 %           }
75 %         } #!$supplemental
76
77         </FONT>
78       </TD>
79     </TR>
80
81 %   my $editi = $curuser->access_right('Edit customer package invoice details');
82 %   my $editc = $curuser->access_right('Edit customer package comments');
83 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
84 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
85 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
86 %
87 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
88 %
89 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
90 %                    ';detailtype=';
91
92       <TR>
93
94 %       if ( @invoice_detail ) {
95           <TD VALIGN="top">
96             <& /elements/table-grid.html &>
97               <TR>
98                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
99                   <FONT SIZE="-1">
100                     <% mt('Invoice details') |h %> 
101 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
102                       (<& /elements/popup_link.html, { 
103                                     'action'      => $editlink. 'I',
104                                     'label'       => emt('edit'),
105                                     'actionlabel' => emt('Edit invoice details'),
106                                     'color'       => '#333399',
107                                     'width'       => 763,
108                                  }
109                        &>)
110 %                   }
111                   </FONT>
112                 </TH>
113               </TR>
114 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
115                 <TR>
116                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
117                 </TR>
118 %             }
119             </TABLE>
120           </TD>
121 %       } else {
122           <TD>
123 %           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
124               <FONT SIZE="-1">
125                 (&nbsp;<% include('/elements/popup_link.html', { 
126                                'action'      => $editlink. 'I',
127                                'label'       => emt('Add invoice details'),
128                                'actionlabel' => emt('Add invoice details'),
129                                'color'       => '#333399',
130                                'width'       => 763,
131                             })
132                   %>&nbsp;)
133               </FONT>
134 %           }
135           </TD>
136 %       }
137
138 %       if ( @comments ) { 
139           <TD VALIGN="top">
140             <& /elements/table-grid.html &>
141               <TR>
142                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
143                   <FONT SIZE="-1">
144                     <% mt('Comments') |h %> 
145 %                   if ( $editc && ! $opt{no_links} ) {
146                       (<& /elements/popup_link.html, { 
147                                     'action'      => $editlink. 'C',
148                                     'label'       => emt('edit'),
149                                     'actionlabel' => emt('Edit comments'),
150                                     'color'       => '#333399',
151                                     'width'       => 763,
152                                  }
153                        &>)
154 %                   }
155                   </FONT>
156                 </TH>
157               </TR>
158 %             foreach my $cust_pkg_detail ( @comments ) {
159                 <TR>
160                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
161                 </TR>
162 %             }
163             </TABLE>
164           </TD>
165 %       } else {
166           <TD>
167 %           if ( $editc && ! $opt{no_links} ) {
168               <FONT SIZE="-1">
169                 (&nbsp;<& /elements/popup_link.html, { 
170                                'action'      => $editlink. 'C',
171                                'label'       => emt('Add comments'),
172                                'actionlabel' => emt('Add comments'),
173                                'color'       => '#333399',
174                                'width'       => 763,
175                             }
176                   &>&nbsp;)
177               </FONT>
178 %           }
179           </TD>
180 %       }
181
182       </TR>
183 %     if ( $curuser->access_right('Change customer package')
184 %            && ! $cust_pkg->get('cancel')
185 %            && ! $supplemental
186 %            && $part_pkg->freq ne '0'
187 %            && ! $opt{no_links}
188 %        )
189 %     {
190       <TR>
191 % # yeah, I guess we'll let you do this on a future change package
192 %       if ( FS::Conf->new->exists('invoice-unitprice') ) {
193         <TD><FONT SIZE="-1">
194           (&nbsp;<% pkg_change_quantity_link($cust_pkg) %>&nbsp;)
195         </FONT></TD>
196 %       }
197       </TR>
198 %     }
199 %   }
200   </TABLE>
201 % if ( @cust_pkg_usage ) {
202   <TABLE CLASS="usage inv">
203     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
204 %   foreach my $usage (@cust_pkg_usage) {
205 %     my $part = $usage->part_pkg_usage;
206 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
207 %     $ratio = 255 if $ratio > 255; # because rollover
208 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
209 %     my $trstyle = '';
210 %     $trstyle = ' CLASS="shared"' if $part->shared;
211     <TR<%$trstyle%>>
212       <TD ALIGN="right"><% $part->description %>: </TD>
213       <TD <%$color%> ALIGN="right"><% $usage->minutes %></TD>
214       <TD <%$color%>> / </TD>
215       <TD <%$color%>><% $part->minutes %></TD>
216 %     if ( $part->shared ) {
217       <TD><I>(shared)</I></TD>
218 %     }
219     </TR>
220 %   }
221   </TABLE>
222 % }
223
224 </TD>
225
226 <%init>
227
228 my %opt = @_;
229
230 my $bgcolor  = $opt{'bgcolor'};
231 my $cust_pkg = $opt{'cust_pkg'};
232 my $part_pkg = $opt{'part_pkg'};
233
234 my $curuser = $FS::CurrentUser::CurrentUser;
235
236 my $countrydefault = $opt{'countrydefault'} || 'US';
237 my $statedefault   = $opt{'statedefault'}
238                      || ($countrydefault eq 'US' ? 'CA' : '');
239
240 # put a marker on the left edge of this column
241 # if this package is somehow special
242 my $supplemental = $opt{'supplemental'} || 0;
243 my $change_from = $opt{'change_from'} || 0;
244 my $style = '';
245 if ( $supplemental or $change_from ) {
246   $style = 'border-left-width: '.($supplemental + $change_from)*30 . 'px; '.
247            'border-color: ';
248   if ( $supplemental ) {
249     $style .= '#bbbbff';
250   } elsif ( $change_from ) {
251     $style .= '#bbffbb';
252   }
253   $style = qq!STYLE="$style"!;
254 }
255
256 $cust_pkg->pkgnum =~ /^(\d+)$/;
257 my $pkgnum = $1;
258 my @cust_pkg_usage = qsearch({
259   'select'    => 'cust_pkg_usage.*',
260   'table'     => 'cust_pkg_usage',
261   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
262   'extra_sql' => " WHERE pkgnum = $1",
263   'order_by'  => ' ORDER BY priority ASC, description ASC',
264 });
265
266 #subroutines
267
268 #false laziness w/status.html
269 sub pkg_link {
270   my($action, $label, $cust_pkg) = @_;
271   return '' unless $cust_pkg;
272   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
273 }
274
275 sub pkg_change_link {
276   my $cust_pkg = shift;
277   my $locationnum = $cust_pkg->locationnum;
278   include( '/elements/popup_link-cust_pkg.html',
279     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
280     'label'       => emt('Change package'),
281     'actionlabel' => emt('Change'),
282     'cust_pkg'    => $cust_pkg,
283     'width'       => 763,
284     'height'      => 480,
285   );
286 }
287
288 sub pkg_change_location_link {
289   my $cust_pkg = shift;
290   my $pkgpart = $cust_pkg->pkgpart;
291   include( '/elements/popup_link-cust_pkg.html',
292     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
293                      "address1=;address2=;city=;county=;state=$statedefault;".
294                      "zip=;country=$countrydefault",
295     'label'       => emt('Change location'),
296     'actionlabel' => emt('Change'),
297     'cust_pkg'    => $cust_pkg,
298     'width'       => 763,
299     'height'      => 380,
300   );
301 }
302
303 sub pkg_change_quantity_link {
304   include( '/elements/popup_link-cust_pkg.html',
305     'action'      => $p. 'edit/cust_pkg_quantity.html?',
306     'label'       => emt('Change quantity'),
307     'actionlabel' => emt('Change'),
308     'cust_pkg'    => shift,
309     'width'       => 390,
310     'height'      => 220,
311   );
312 }
313
314 sub pkg_discount_link {
315   my $cust_pkg = shift or return '';
316   include( '/elements/popup_link-cust_pkg.html',
317     'action'      => $p.'edit/cust_pkg_discount.html',
318     'label'       => emt('Discount'),
319     'actionlabel' => emt('Discount'),
320     'cust_pkg'    => $cust_pkg,
321     'width'       => 616,
322   );
323 }
324
325 sub pkg_customize_link {
326   my $cust_pkg = shift or return '';
327   my $part_pkg = shift;
328   my $custnum = $cust_pkg->custnum;
329   qq!<A HREF="${p}edit/part_pkg.cgi?!.
330     "clone=". $part_pkg->pkgpart. ';'.
331     "pkgnum=". $cust_pkg->pkgnum.
332     qq!">!.emt('Customize').'</A>';
333 }
334
335 sub pkg_event_link {
336   my($cust_pkg) = @_;
337   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
338   emt('View package events').
339   '</a>';
340 }
341
342 </%init>