no reason for multi-select to be disabled on these
[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
4
5     <TR>
6       <TD COLSPAN=2>
7         <% $opt{before_pkg_callback}
8              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
9              : ''
10         %>
11         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
12            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
13         ><% $opt{show_pkgnum} ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
14 %
15 %       my $custom_comment;
16 %       if ( 0 && FS::part_pkg::flat->can('price_info') eq $part_pkg->can('price_info') ) {
17 %         #perf hack / disabled in 4.x (feature pricing / cust_pkg_usageprice incompatible, well, harder)
18 %
19 %         $part_pkg->{"_$_"} = $part_pkg->option($_) || 0
20 %           foreach grep !defined($part_pkg->{"_$_"} ), qw(setup_fee recur_fee);
21 %           
22 %         my $str = '';
23 %         $str = $opt{money_char} . $part_pkg->{_setup_fee}.
24 %                ($part_pkg->{_recur_fee} ? ' setup' : ' one-time')
25 %           if $part_pkg->{_setup_fee};
26 %         $str .= ', ' if $part_pkg->{_setup_fee} && $part_pkg->{_recur_fee};
27 %         $str .= $opt{money_char}. $part_pkg->{_recur_fee}.
28 %                 '/'. $part_pkg->freq_pretty
29 %           if $part_pkg->{_recur_fee};
30 %         $str;
31 %
32 %         $custom_comment = 
33 %           ( $part_pkg->custom ? '(CUSTOM) ' : '' ).
34 %           $part_pkg->comment.
35 %           ( ($part_pkg->custom || $part_pkg->comment) ? ' - ' : '' ).
36 %           ($str || 'No charge');
37 %
38 %       } else {
39 %         $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
40 %       }
41         <% $custom_comment ? ' - ' : '' %>
42         <% $custom_comment |h %>
43       </TD>
44     </TR>
45
46
47     <TR>
48       <TD COLSPAN=2>
49         <FONT SIZE=-1>
50
51 %         if ( $part_pkg->freq eq '0' and !$opt{no_links} ) {
52 %           # One-time charge.  Nothing you can do with this, unless:
53 %           if ( $curuser->access_right('Modify one-time charge') ) {
54                 (&nbsp;<%onetime_change_link($cust_pkg)%>&nbsp;)
55                 <BR>
56 %           }
57 %
58 %         } elsif ( !$cust_pkg->get('cancel') and !$opt{no_links} ) {
59 %
60 %           if ( $change_from ) {
61 %             # This is the target package for a future change.
62 %             # Nothing you can do with it besides modify/cancel the 
63 %             # future change, and that's on the current package.
64 %           } elsif ( $supplemental ) {
65 %             # Supplemental packages can't be changed independently.
66 %             # Show only "Add comments" and "Add invoice details".
67 %           } else {
68 %             # the usual case: links to change package definition,
69 %             # discount, and customization
70 %             my $br = 0;
71 %             if ( $curuser->access_right('Change customer package') ) {
72 %               $br=1;
73                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
74 %             } 
75 %
76 %             if ( $curuser->access_right('Discount customer package')
77 %                  && $part_pkg->can_discount
78 %                  && ! scalar( @{ $cust_pkg->{_cust_pkg_discount_active} } )
79 %                  && (    ! $opt{'term_discounts'}
80 %                       || ! scalar($cust_pkg->part_pkg->part_pkg_discount)
81 %                     )
82 %                )
83 %             {
84 %               $br=1;
85                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
86 %             }
87 %
88 %             if ( $curuser->access_right('Customize customer package') ) {
89 %               $br=1;
90                 (&nbsp;<%pkg_customize_link($cust_pkg,$part_pkg)%>&nbsp;)
91 %             } 
92 %
93               <% $br ? '<BR>' : '' %>
94 %           } 
95
96 %           if (    (    $curuser->access_right('Billing event reports')
97 %                     || $curuser->access_right('View customer billing events')
98 %                   )
99 %                && $cust_pkg->exists_cust_event
100 %              ) {
101               (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
102 %           }
103 %         } #!$supplemental
104
105         </FONT>
106       </TD>
107     </TR>
108
109
110     <TR>
111       <TD COLSPAN=2>
112
113 %       my $change_quan_label = 'Change quantity';
114 %       if ( $cust_pkg->quantity > 1 ) {
115 %         $change_quan_label = 'change';
116           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
117           <B><% $cust_pkg->quantity %></B>
118 %       }
119
120 %       if ( $curuser->access_right('Change customer package')
121 %              && ! $cust_pkg->get('cancel')
122 %              && ! $supplemental
123 %              && $part_pkg->freq ne '0'
124 %              && ! $opt{no_links}
125 %              && $opt{'invoice-unitprice'}
126 %          )
127 %       {
128           <FONT SIZE="-1">
129             (&nbsp;<% pkg_change_quantity_link($cust_pkg, $change_quan_label) %>&nbsp;)
130           </FONT>
131 %       }
132
133       </TD>
134     </TR>
135
136
137     <TR>
138       <TD COLSPAN=2>
139
140 %       my $change_sales_label = 'Change sales person';
141 %       if ( $cust_pkg->salesnum ) {
142 %         $change_sales_label = 'change';
143           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Sales Person:') |h %> 
144           <B><% $cust_pkg->salesperson |h %></B>
145 %       }
146
147 %       if ( $curuser->access_right('Change customer package')
148 %              && ! $cust_pkg->get('cancel')
149 %              && ! $supplemental
150 %              #&& $part_pkg->freq ne '0'
151 %              && ! $opt{no_links}
152 %          )
153 %       {
154         <FONT SIZE="-1">
155           (&nbsp;<% pkg_change_salesnum_link($cust_pkg, $change_sales_label) %>&nbsp;)
156         </FONT>
157 %     }
158
159       </TD>
160     </TR>
161
162
163 %   my $editi = $curuser->access_right('Edit customer package invoice details');
164 %   my $editc = $curuser->access_right('Edit customer package comments');
165 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
166 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
167 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
168 %
169 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
170 %
171 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
172 %                    ';detailtype=';
173
174       <TR>
175
176 %       if ( @invoice_detail ) {
177           <TD VALIGN="top">
178             <& /elements/table-grid.html &>
179               <TR>
180                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
181                   <FONT SIZE="-1">
182                     <% mt('Invoice details') |h %> 
183 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
184                       (<& /elements/popup_link.html, { 
185                                     'action'      => $editlink. 'I',
186                                     'label'       => emt('edit'),
187                                     'actionlabel' => emt('Edit invoice details'),
188                                     'color'       => '#333399',
189                                     'width'       => 763,
190                                  }
191                        &>)
192 %                   }
193                   </FONT>
194                 </TH>
195               </TR>
196 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
197                 <TR>
198                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
199                 </TR>
200 %             }
201             </TABLE>
202           </TD>
203 %       } else {
204           <TD>
205 %           if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
206               <FONT SIZE="-1">
207                 (&nbsp;<% include('/elements/popup_link.html', { 
208                                'action'      => $editlink. 'I',
209                                'label'       => emt('Add invoice details'),
210                                'actionlabel' => emt('Add invoice details'),
211                                'color'       => '#333399',
212                                'width'       => 763,
213                             })
214                   %>&nbsp;)
215               </FONT>
216 %           }
217           </TD>
218 %       }
219
220 %       if ( @comments ) { 
221           <TD VALIGN="top">
222             <& /elements/table-grid.html &>
223               <TR>
224                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
225                   <FONT SIZE="-1">
226                     <% mt('Comments') |h %> 
227 %                   if ( $editc && ! $opt{no_links} ) {
228                       (<& /elements/popup_link.html, { 
229                                     'action'      => $editlink. 'C',
230                                     'label'       => emt('edit'),
231                                     'actionlabel' => emt('Edit comments'),
232                                     'color'       => '#333399',
233                                     'width'       => 763,
234                                  }
235                        &>)
236 %                   }
237                   </FONT>
238                 </TH>
239               </TR>
240 %             foreach my $cust_pkg_detail ( @comments ) {
241                 <TR>
242                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
243                 </TR>
244 %             }
245             </TABLE>
246           </TD>
247 %       } else {
248           <TD>
249 %           if ( $editc && ! $opt{no_links} ) {
250               <FONT SIZE="-1">
251                 (&nbsp;<& /elements/popup_link.html, { 
252                                'action'      => $editlink. 'C',
253                                'label'       => emt('Add comments'),
254                                'actionlabel' => emt('Add comments'),
255                                'color'       => '#333399',
256                                'width'       => 763,
257                             }
258                   &>&nbsp;)
259               </FONT>
260 %           }
261           </TD>
262 %       }
263
264       </TR>
265
266
267 %   }
268   </TABLE>
269
270 % if ( @cust_pkg_usage ) {
271   <TABLE CLASS="usage inv">
272     <TR><TH COLSPAN=4><% mt('Included usage') %></TH></TR>
273 %   foreach my $usage (@cust_pkg_usage) {
274 %     my $part = $usage->part_pkg_usage;
275 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
276 %     $ratio = 255 if $ratio > 255; # because rollover
277 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
278 %     my $trstyle = '';
279 %     $trstyle = ' CLASS="shared"' if $part->shared;
280     <TR<%$trstyle%>>
281       <TD ALIGN="right"><% $part->description %>: </TD>
282       <TD <%$color%> ALIGN="right"><% sprintf('%.1f', $usage->minutes) %></TD>
283       <TD <%$color%>> / </TD>
284       <TD <%$color%>><% $part->minutes %></TD>
285 %     if ( $part->shared ) {
286       <TD><I>(shared)</I></TD>
287 %     }
288     </TR>
289 %   }
290   </TABLE>
291 % }
292
293 </TD>
294
295 <%init>
296
297 my %opt = @_;
298
299 my $bgcolor  = $opt{'bgcolor'};
300 my $cust_pkg = $opt{'cust_pkg'};
301 my $part_pkg = $opt{'part_pkg'};
302
303 my $curuser = $FS::CurrentUser::CurrentUser;
304
305 my $countrydefault = $opt{'countrydefault'} || 'US';
306 my $statedefault   = $opt{'statedefault'}
307                      || ($countrydefault eq 'US' ? 'CA' : '');
308
309 # put a marker on the left edge of this column
310 # if this package is somehow special
311 my $supplemental = $opt{'supplemental'} || 0;
312 my $change_from = $opt{'change_from'} || 0;
313 my $style = '';
314 if ( $supplemental or $change_from ) {
315   $style = 'border-left-width: '.($supplemental + $change_from)*30 . 'px; '.
316            'border-color: ';
317   if ( $supplemental ) {
318     $style .= '#bbbbff';
319   } elsif ( $change_from ) {
320     $style .= '#bbffbb';
321   }
322   $style = qq!STYLE="$style"!;
323 }
324
325 $cust_pkg->pkgnum =~ /^(\d+)$/;
326 my $pkgnum = $1;
327 my @cust_pkg_usage = qsearch({
328   'select'    => 'cust_pkg_usage.*',
329   'table'     => 'cust_pkg_usage',
330   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
331   'extra_sql' => " WHERE pkgnum = $1",
332   'order_by'  => ' ORDER BY priority ASC, description ASC',
333 });
334
335 #subroutines
336
337 #false laziness w/status.html
338 sub pkg_link {
339   my($action, $label, $cust_pkg) = @_;
340   return '' unless $cust_pkg;
341   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
342 }
343
344 sub pkg_change_link {
345   my $cust_pkg = shift;
346   my $locationnum = $cust_pkg->locationnum;
347   include( '/elements/popup_link-cust_pkg.html',
348     'action'      => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
349     'label'       => emt('Change package'),
350     'actionlabel' => emt('Change'),
351     'cust_pkg'    => $cust_pkg,
352     'width'       => 960,
353     'height'      => 490,
354   );
355 }
356
357 sub onetime_change_link {
358   my $cust_pkg = shift;
359   my $pkgnum = $cust_pkg->pkgnum;
360   include( '/elements/popup_link-cust_pkg.html',
361     'action'      => $p. "edit/quick-charge.html?change_pkgnum=$pkgnum",
362     'label'       => emt('Modify one-time charge'),
363     'actionlabel' => emt('Modify'),
364     'cust_pkg'    => $cust_pkg,
365     'width'       => 690,
366     'height'      => 380,
367   );
368 }
369
370 sub pkg_change_location_link {
371   my $cust_pkg = shift;
372   my $pkgpart = $cust_pkg->pkgpart;
373   include( '/elements/popup_link-cust_pkg.html',
374     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
375                      "address1=;address2=;city=;county=;state=$statedefault;".
376                      "zip=;country=$countrydefault",
377     'label'       => emt('Change location'),
378     'actionlabel' => emt('Change'),
379     'cust_pkg'    => $cust_pkg,
380     'width'       => 960,
381     'height'      => 490,
382   );
383 }
384
385 sub pkg_change_quantity_link {
386   my( $cust_pkg, $label ) = @_;
387   include( '/elements/popup_link-cust_pkg.html',
388     'action'      => $p. 'edit/cust_pkg_quantity.html?',
389     'label'       => emt($label),
390     'actionlabel' => emt('Change'),
391     'cust_pkg'    => $cust_pkg,
392     'width'       => 390,
393     'height'      => 220,
394   );
395 }
396
397 sub pkg_change_salesnum_link {
398   my( $cust_pkg, $label ) = @_;
399   include( '/elements/popup_link-cust_pkg.html',
400     'action'      => $p. 'edit/cust_pkg_salesnum.html?',
401     'label'       => emt($label),
402     'actionlabel' => emt('Change'),
403     'cust_pkg'    => $cust_pkg,
404     'width'       => 390,
405     'height'      => 220,
406   );
407 }
408
409 sub pkg_discount_link {
410   my $cust_pkg = shift or return '';
411   include( '/elements/popup_link-cust_pkg.html',
412     'action'      => $p.'edit/cust_pkg_discount.html',
413     'label'       => emt('Discount'),
414     'actionlabel' => emt('Discount'),
415     'cust_pkg'    => $cust_pkg,
416     'width'       => 616,
417   );
418 }
419
420 sub pkg_customize_link {
421   my $cust_pkg = shift or return '';
422   my $part_pkg = shift;
423   my $custnum = $cust_pkg->custnum;
424   qq!<A HREF="${p}edit/part_pkg.cgi?!.
425     "clone=". $part_pkg->pkgpart. ';'.
426     "pkgnum=". $cust_pkg->pkgnum.
427     qq!">!.emt('Customize').'</A>';
428 }
429
430 sub pkg_event_link {
431   my($cust_pkg) = @_;
432   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
433   emt('View package events').
434   '</a>';
435 }
436
437 </%init>