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