1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top">
2 <% join('', @marker ) %>
3 <TABLE CLASS="inv package">
6 <% $opt{before_pkg_callback}
7 ? &{ $opt{before_pkg_callback} }( $cust_pkg )
14 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
15 ID ="cust_pkg<% $cust_pkg->pkgnum %>"
16 ><% $opt{show_pkgnum} ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
19 % if ( 0 && FS::part_pkg::flat->can('price_info') eq $part_pkg->can('price_info') ) {
20 % #perf hack / disabled in 4.x (feature pricing / cust_pkg_usageprice incompatible, well, harder)
22 % $part_pkg->{"_$_"} = $part_pkg->option($_) || 0
23 % foreach grep !defined($part_pkg->{"_$_"} ), qw(setup_fee recur_fee);
26 % $str = $opt{money_char} . $part_pkg->{_setup_fee}.
27 % ($part_pkg->{_recur_fee} ? ' setup' : ' one-time')
28 % if $part_pkg->{_setup_fee};
29 % $str .= ', ' if $part_pkg->{_setup_fee} && $part_pkg->{_recur_fee};
30 % $str .= $opt{money_char}. $part_pkg->{_recur_fee}.
31 % '/'. $part_pkg->freq_pretty
32 % if $part_pkg->{_recur_fee};
36 % ( $part_pkg->custom ? '(CUSTOM) ' : '' ).
38 % ( ($part_pkg->custom || $part_pkg->comment) ? ' - ' : '' ).
39 % ($str || 'No charge');
42 % $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
44 <% $custom_comment ? ' - ' : '' %>
45 <% $custom_comment |h %>
52 % if ( $cust_pkg->quantity > 1 ) {
55 <% mt('Quantity:') |h %>
56 <B><% $cust_pkg->quantity %></B>
58 % if ( $curuser->access_right('Change customer package')
59 % && ! $cust_pkg->get('cancel')
62 % && $part_pkg->freq ne '0'
64 % && $opt{'invoice-unitprice'}
68 ( <% pkg_change_quantity_link($cust_pkg, 'change') %> )
78 % if ( $cust_pkg->salesnum ) {
81 <% mt('Sales Person:') |h %>
82 <B><% $cust_pkg->salesperson |h %></B>
83 % if ( $curuser->access_right('Change customer package')
84 % && ! $cust_pkg->get('cancel')
87 % #&& $part_pkg->freq ne '0'
92 ( <% pkg_change_salesnum_link($cust_pkg, 'change') %> )
101 % # Invoice details & comments
103 % my $editi = $curuser->access_right('Edit customer package invoice details');
104 % my $editc = $curuser->access_right('Edit customer package comments');
105 % my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
106 % my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
107 % my @comments = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
109 % if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
111 % my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
116 % if ( @invoice_detail ) {
118 <& /elements/table-grid.html &>
120 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
122 <% mt('Invoice details') |h %>
123 % if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
124 (<& /elements/popup_link.html, {
125 'action' => $editlink. 'I',
126 'label' => emt('edit'),
127 'actionlabel' => emt('Edit invoice details'),
128 'color' => '#333399',
136 % foreach my $cust_pkg_detail ( @invoice_detail ) {
138 <TD><FONT SIZE="-1"> - <% $cust_pkg_detail->detail |h %></FONT></TD>
150 <& /elements/table-grid.html &>
152 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
154 <% mt('Comments') |h %>
155 % if ( $editc && ! $opt{no_links} ) {
156 (<& /elements/popup_link.html, {
157 'action' => $editlink. 'C',
158 'label' => emt('edit'),
159 'actionlabel' => emt('Edit comments'),
160 'color' => '#333399',
168 % foreach my $cust_pkg_detail ( @comments ) {
170 <TD><FONT SIZE="-1"> - <% $cust_pkg_detail->detail |h %></FONT></TD>
186 % if ( @cust_pkg_usage ) {
187 <TABLE CLASS="usage inv">
188 <TR><TH COLSPAN=4><% emt('Included usage') %></TH></TR>
189 % foreach my $usage (@cust_pkg_usage) {
190 % my $part = $usage->part_pkg_usage;
191 % my $ratio = 255 * ($usage->minutes / $part->minutes);
192 % $ratio = 255 if $ratio > 255; # because rollover
193 % my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
195 % $trstyle = ' CLASS="shared"' if $part->shared;
197 <TD ALIGN="right"><% $part->description %>: </TD>
198 <TD <%$color%> ALIGN="right"><% sprintf('%.1f', $usage->minutes) %></TD>
199 <TD <%$color%>> / </TD>
200 <TD <%$color%>><% $part->minutes %></TD>
201 % if ( $part->shared ) {
202 <TD><I>(shared)</I></TD>
211 % # Package actions dropdown
213 % unless ( $opt{no_links} ) {
215 <TABLE CLASS="inv package">
219 % my $plink = "pkgnum=$pkgnum";
220 % my $reg_recur_cond = sub { $part_pkg->freq ne '0'
223 % && ! $cust_pkg->get('cancel')
225 % my $change_cond = sub { $part_pkg->freq ne '0'
228 % && ! $cust_pkg->get('cancel')
229 % && $cust_pkg->change_to_pkgnum,
232 <& /elements/dropdown-menu.html,
233 id => 'cust_pkg'. $cust_pkg->pkgnum. '_menu',
234 bgcolor => $opt{row} % 2 ? '#ffffff' : '#eeeeee',
238 #TODO: order/group these better
240 { label => 'Package actions',
242 '<FONT STYLE="text-decoration:underline;font-weight:bold">'.
243 'Package actions</FONT>'.
244 ' <IMG SRC="'.$p.'images/arrow.down.black.png">',
247 { label => 'Modify one-time charge',
248 acl => 'Modify one-time charge',
249 condition => sub { $part_pkg->freq eq '0' },
250 url => "edit/quick-charge.html?change_$plink",
253 { label => 'Change package',
254 acl => 'Change customer package',
255 condition => $reg_recur_cond,
256 popup => "misc/change_pkg.cgi?$plink".
257 ';locationnum='. $cust_pkg->locationnum,
258 actionlabel => emt('Change package'),
264 { label => 'Discount package',
265 condition => sub { ! $change_from
267 && ! $cust_pkg->get('cancel')
270 popup => "edit/cust_pkg_discount.html?$plink",
271 actionlabel => emt('Discount package'),
275 { label => 'Customize package',
276 acl => 'Customize customer package',
277 condition => $reg_recur_cond,
278 url => "edit/part_pkg.cgi?$plink".
279 ';clone='. $part_pkg->pkgpart,
286 { label => 'View package events',
287 acl => [ 'Billing event reports',
288 'View customer billing events', ],
289 condition => sub { $cust_pkg->exists_cust_event },
290 url => "search/cust_event.html?$plink",
294 condition => sub { $cust_pkg->exists_cust_event },
298 { label => 'Change quantity',
299 acl => 'Change customer package',
300 condition => sub { $part_pkg->freq ne '0'
303 && ! $cust_pkg->get('cancel')
304 && $opt{'invoice-unitprice'}
306 popup => "edit/cust_pkg_quantity.html?$plink",
308 actionlabel => emt('Change quantity'),
313 { label => 'Change sales person',
314 acl => 'Change customer package',
315 condition => sub { ! $change_from
317 && ! $cust_pkg->get('cancel')
319 popup => "edit/cust_pkg_salesnum.html?$plink",
320 actionlabel => emt('Change sales persion'),
329 { label => (@invoice_detail ? 'Edit' : 'Add').
331 acl => 'Edit customer package invoice details',
332 condition => sub { ! $cust_pkg->get('cancel') },
333 popup => "edit/cust_pkg_detail.html?$plink".
335 actionlabel => emt( (@invoice_detail ? 'Edit' : 'Add').
341 { label => (@comments ? 'Edit' : 'Add'). ' comments',
342 acl => 'Edit customer package comments',
343 popup => "edit/cust_pkg_detail.html?$plink".
345 actionlabel => emt( (@comments ? 'Edit' : 'Add').
352 condition => sub { $part_pkg->freq ne '0' },
356 { label => 'Set start date',
357 acl => 'Change package start date',
358 condition => sub { $part_pkg->freq ne '0'
361 && ! $cust_pkg->get('cancel')
362 && ! $cust_pkg->get('setup')
364 popup => "misc/change_pkg_date.html?$plink".
366 actionlabel => emt('Set start of billing for'),
371 { label => 'Set contract end',
372 acl => 'Change package contract end date',
373 condition => sub { $part_pkg->freq ne '0'
376 && ! $cust_pkg->get('cancel')
377 && ! $cust_pkg->change_to_pkgnum
379 popup => "misc/change_pkg_date.html?$plink".
380 ';field=contract_end',
381 actionlabel => emt('Set contract end for'),
387 condition => sub { $part_pkg->freq ne '0' },
391 { label => 'Change now',
392 acl => 'Change customer package',
393 condition => $change_cond,
394 url => "misc/change_pkg_now.cgi?$pkgnum",
397 { label => 'Reschedule',
398 acl => 'Change customer package',
399 condition => sub { $part_pkg->freq ne '0'
402 && ! $cust_pkg->get('cancel')
403 && $cust_pkg->change_to_pkgnum,
405 popup => "misc/change_pkg.html?$plink",
406 actionlabel => emt('Edit scheduled change for'),
407 url => "misc/change_pkg_now.cgi?$pkgnum",
413 { label => 'Abort change',
414 acl => 'Change customer package',
415 condition => $change_cond,
416 url => "misc/do_not_change_pkg.cgi?$pkgnum",
420 acl => 'Change customer package',
421 condition => $change_cond,
425 { label => 'Suspend now',
426 acl => 'Suspend customer package',
427 condition => sub { $part_pkg->freq ne '0'
430 && ! $cust_pkg->get('cancel')
431 && ! $cust_pkg->get('susp')
433 popup => "misc/cancel_pkg.html?method=suspend;$plink",
434 actionlabel => emt('Suspend now'),
440 { label => 'Suspend later',
441 acl => 'Suspend customer package later',
442 condition => sub { $part_pkg->freq ne '0'
445 && ! $cust_pkg->get('cancel')
446 && ! $cust_pkg->get('susp')
448 popup => "misc/cancel_pkg.html?method=adjourn;$plink",
449 actionlabel => emt('Suspend later'),
455 { label => $cust_pkg->dundate
456 ? 'Edit suspension delay'
459 acl => 'Delay suspension events',
460 condition => sub { $part_pkg->freq ne '0'
463 && ! $cust_pkg->get('cancel')
464 && ! $cust_pkg->get('susp')
466 popup => "misc/delay_susp_pkg.html?$plink",
467 actionlabel => emt('Delay suspend for'),
471 { label => 'Start billing',
472 acl => 'Unsuspend customer package',
473 condition => sub { ! $change_from
475 && ! $cust_pkg->get('cancel')
476 && $cust_pkg->get('susp')
477 && $cust_pkg->order_date == $cust_pkg->get('susp')
479 popup => "misc/unhold_pkg.html?$plink",
480 actionlabel => emt('Start billing'),
486 { label => 'Unsuspend now',
487 acl => 'Unsuspend customer package',
488 condition => sub { $part_pkg->freq ne '0'
491 && ! $cust_pkg->get('cancel')
492 && $cust_pkg->get('susp')
493 && $cust_pkg->order_date != $cust_pkg->get('susp')
495 'url' => "misc/unsusp_pkg.cgi?$pkgnum",
498 { label => 'Unsuspend later',
499 acl => 'Unsuspend customer package',
500 condition => sub { $part_pkg->freq ne '0'
503 && ! $cust_pkg->get('cancel')
504 && $cust_pkg->get('susp')
505 && $cust_pkg->order_date != $cust_pkg->get('susp')
507 popup => "misc/cancel_pkg.html?method=resume;$plink",
508 actionlabel => emt('Unsuspend later'),
514 condition => sub { $part_pkg->freq ne '0'
517 && ! $cust_pkg->get('cancel')
518 && ! $cust_pkg->get('susp')
523 { label => 'Cancel now',
524 acl => 'Cancel customer package immediately',
525 condition => sub { $part_pkg->freq ne '0'
528 && ! $cust_pkg->change_to_pkgnum
529 && ! $cust_pkg->get('cancel')
531 popup => "misc/cancel_pkg.html?method=cancel;$plink",
532 actionlabel => emt('Cancel now'),
537 { label => 'Cancel later',
538 acl => 'Cancel customer package later',
539 condition => sub { $part_pkg->freq ne '0'
542 && ! $cust_pkg->change_to_pkgnum
543 && ! $cust_pkg->get('cancel')
545 popup => "misc/cancel_pkg.html?method=expire;$plink",
546 actionlabel => emt('Cancel later'),
551 { label => 'Un-cancel',
552 acl => 'Un-cancel customer package',
553 condition => sub { $part_pkg->freq ne '0'
555 && ! $cust_pkg->change_custnum
556 && $cust_pkg->get('cancel')
558 popup => "misc/cancel_pkg.html?method=uncancel;$plink",
559 actionlabel => emt('Un-cancel'),
566 condition => sub { $part_pkg->freq ne '0'
568 && ! $cust_pkg->get('cancel')
573 { label => 'Add contact',
574 #acl => 'Add package contact',#or something like that
575 condition => sub { ! $cust_pkg->get('cancel') },
576 popup => "misc/change_pkg_contact.html?$plink",
577 actionlabel => emt('Add contact'),
582 { label => 'Change location',
583 acl => 'Change customer package',
584 condition => sub { ! $change_from },
585 popup => "misc/change_pkg.cgi?locationnum=-1;$plink;".
586 "address1=;address2=;city=;county=;state=$statedefault;".
587 "zip=;country=$countrydefault",
588 actionlabel => emt('Change location'),
593 { label => 'Edit location',
594 acl => 'Change customer package',
595 condition => sub { ! $change_from && $cust_pkg->locationnum != $cust_pkg->cust_main->ship_locationnum },
596 popup => 'misc/cust_location.cgi?locationnum='.
597 $cust_pkg->locationnum,
598 actionlabel => emt('Edit location'),
613 <% join('', map '</DIV>', @marker ) %>
621 my $bgcolor = $opt{'bgcolor'};
622 my $cust_pkg = $opt{'cust_pkg'};
623 my $part_pkg = $opt{'part_pkg'};
625 my $curuser = $FS::CurrentUser::CurrentUser;
627 my $countrydefault = $opt{'countrydefault'} || 'US';
628 my $statedefault = $opt{'statedefault'}
629 || ($countrydefault eq 'US' ? 'CA' : '');
631 # put a marker on the left edge of this column
632 # if this package is somehow special
633 my $supplemental = $opt{'supplemental'} || 0;
634 my $change_from = $opt{'change_from'} || 0;
636 if ( $supplemental ) {
637 push @marker, '<DIV CLASS="package-marker-supplemental">';
639 if ( $change_from ) {
640 push @marker, '<DIV CLASS="package-marker-change_from">';
643 $cust_pkg->pkgnum =~ /^(\d+)$/;
645 my @cust_pkg_usage = qsearch({
646 'select' => 'cust_pkg_usage.*',
647 'table' => 'cust_pkg_usage',
648 'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
649 'extra_sql' => " WHERE pkgnum = $1",
650 'order_by' => ' ORDER BY priority ASC, description ASC',
655 #false laziness w/status.html
657 my($action, $label, $cust_pkg) = @_;
658 return '' unless $cust_pkg;
659 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
662 sub pkg_change_location_link {
663 my $cust_pkg = shift;
664 my $pkgpart = $cust_pkg->pkgpart;
665 include( '/elements/popup_link-cust_pkg.html',
666 'action' => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
667 "address1=;address2=;city=;county=;state=$statedefault;".
668 "zip=;country=$countrydefault",
669 'label' => emt('Change location'),
670 'actionlabel' => emt('Change'),
671 'cust_pkg' => $cust_pkg,
677 sub pkg_change_quantity_link {
678 my( $cust_pkg, $label ) = @_;
679 include( '/elements/popup_link-cust_pkg.html',
680 'action' => $p. 'edit/cust_pkg_quantity.html?',
681 'label' => emt($label),
682 'actionlabel' => emt('Change'),
683 'cust_pkg' => $cust_pkg,
689 sub pkg_change_salesnum_link {
690 my( $cust_pkg, $label ) = @_;
691 include( '/elements/popup_link-cust_pkg.html',
692 'action' => $p. 'edit/cust_pkg_salesnum.html?',
693 'label' => emt($label),
694 'actionlabel' => emt('Change'),
695 'cust_pkg' => $cust_pkg,
701 # figure out if this user will be able to edit either the setup or recurring
702 # discounts for this package
703 my $can_discount_pkg = 0;
705 if ( $part_pkg->can_discount ) {
706 #looking these up individually uses the ACL cache and is a big win for lots
708 my $discount = $curuser->access_right('Discount customer package');
709 my $waive = $curuser->access_right('Waive setup fee');
712 ( ($discount || $waive)
713 && $cust_pkg->base_setup > 0
717 && $cust_pkg->base_recur > 0
718 && $cust_pkg->freq ne '0'