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