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