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