1 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
2 % if ( $curuser->access_right('Order customer package') ) {
4 <% include('order_pkg.html', $cust_main ) %>
6 % if ( $curuser->access_right('One-time charge')
7 % && $conf->config('payby-default') ne 'HIDE'
11 <% include('/elements/popup_link.html',
13 'action' => $p. 'edit/quick-charge.html?custnum='. $cust_main->custnum,
14 'label' => 'One-time charge',
15 'actionlabel' => 'One-time charge',
21 % if ( $curuser->access_right('Bulk change customer packages') ) {
23 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
32 % if ( $cust_main->num_cancelled_pkgs ) {
33 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
34 % || ( $conf->exists('hidecancelledpackages')
35 % && ! $cgi->param('showcancelledpackages')
39 % $cgi->param('showcancelledpackages', 1);
42 ( <a href="<% $cgi->self_url %>">show
44 % $cgi->param('showcancelledpackages', 0);
47 ( <a href="<% $cgi->self_url %>">hide
50 cancelled packages</a> )
55 <% include('/elements/table-grid.html') %>
56 % my $bgcolor1 = '#eeeeee';
57 % my $bgcolor2 = '#ffffff';
61 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
62 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
63 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
66 %foreach my $cust_pkg (@$packages) {
68 % my $part_pkg = $cust_pkg->part_pkg;
70 % if ( $bgcolor eq $bgcolor1 ) {
71 % $bgcolor = $bgcolor2;
73 % $bgcolor = $bgcolor1;
77 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
79 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
80 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
81 <% $part_pkg->pkg %> - <% $part_pkg->comment %>
84 % if ( $cust_pkg->quantity > 1 ) {
85 Quantity: <B><% $cust_pkg->quantity %></B><BR>
89 % unless ( $cust_pkg->get('cancel') ) {
90 % if ( $curuser->access_right('Change customer package') ) {
92 ( <%pkg_change_link($cust_pkg)%> )
94 % if ( $curuser->access_right('Edit customer package dates') ) {
96 ( <%pkg_dates_link($cust_pkg)%> )
98 % if ( $curuser->access_right('Customize customer package') ) {
100 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
106 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
107 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
110 % my $part_pkg = shift;
111 % my $freq = $part_pkg->freq_pretty;
112 % $freq =~ s/ / /g;
116 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
117 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
118 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
120 % #false laziness w/edit/REAL_cust_pkg.cgi
121 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
122 % unless ( $part_pkg->is_prepaid ) {
123 % $billed_or_prepaid = 'billed';
124 % $last_bill_or_renewed = 'Last bill';
125 % $next_bill_or_prepaid_until = 'Next bill';
127 % $billed_or_prepaid = 'prepaid';
128 % $last_bill_or_renewed = 'Renewed';
129 % $next_bill_or_prepaid_until = 'Prepaid until';
133 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
134 % my $cpr = $cust_pkg->last_cust_pkg_reason;
136 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
138 <% pkg_status_row_colspan(
139 ( ( $cpr && ( $cpr->date == $cust_pkg->get('cancel') ||
140 $cpr->date == $cust_pkg->expire
142 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
143 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
148 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
150 % unless ( $cust_pkg->get('setup') ) {
152 <% pkg_status_row_colspan('Never billed') %>
156 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
157 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
158 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
159 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf ) %>
165 % if ( $cust_pkg->get('susp') ) { #status: suspended
166 % my $cpr = $cust_pkg->last_cust_pkg_reason;
168 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
170 <% pkg_status_row_colspan(
171 ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
172 $cpr->date == $cust_pkg->adjourn
174 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
175 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
179 % unless ( $cust_pkg->get('setup') ) {
180 <% pkg_status_row_colspan('Never billed') %>
182 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
185 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
186 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
187 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
188 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
191 <TD COLSPAN=<%$colspan%>>
193 % if ( $curuser->access_right('Unsuspend customer package') ) {
194 ( <% pkg_unsuspend_link($cust_pkg) %> )
196 % if ( $curuser->access_right('Cancel customer package immediately') ) {
197 ( <% pkg_cancel_link($cust_pkg) %> )
203 % } else { #status: active
205 % unless ( $cust_pkg->get('setup') ) { #not setup
207 % unless ( $part_pkg->freq ) {
209 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
212 <TD COLSPAN=<%$colspan%>>
214 % if ( $curuser->access_right('Cancel customer package immediately') ) {
215 ( <% pkg_cancel_link($cust_pkg) %> )
223 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
229 % unless ( $part_pkg->freq ) {
231 <% pkg_status_row_colspan('One-time charge') %>
233 <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
237 % if (scalar($cust_pkg->overlimit)) {
239 <% pkg_status_row_colspan(
241 $billed_or_prepaid. ' '. myfreq($part_pkg),
247 <% pkg_status_row_colspan(
249 $billed_or_prepaid. ' '. myfreq($part_pkg),
255 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
261 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
262 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
263 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf ) %>
264 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf ) %>
265 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
267 % if ( $part_pkg->freq ) {
270 <TD COLSPAN=<%$colspan%>>
272 % if ( $curuser->access_right('Suspend customer package') ) {
273 ( <% pkg_suspend_link($cust_pkg) %> )
275 % if ( $curuser->access_right('Suspend customer package later') ) {
276 ( <% pkg_adjourn_link($cust_pkg) %> )
278 % if ( $curuser->access_right('Cancel customer package immediately') ) {
279 ( <% pkg_cancel_link($cust_pkg) %> )
281 % if ( $curuser->access_right('Cancel customer package later') ) {
282 ( <% pkg_expire_link($cust_pkg) %> )
296 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
297 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
299 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
300 % foreach my $part_svc ( $cust_pkg->part_svc ) {
302 % #foreach my $service (@{$svcpart->{services}}) {
303 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
306 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
307 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
308 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
312 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
314 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
319 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
321 % if ( $curuser->access_right('Recharge customer service')
322 % && $part_svc->svcdb eq 'svc_acct'
323 % && ( $cust_svc->svc_x->seconds ne ''
324 % || $cust_svc->svc_x->upbytes ne ''
325 % || $cust_svc->svc_x->downbytes ne ''
326 % || $cust_svc->svc_x->totalbytes ne ''
329 ( <%svc_recharge_link($cust_svc)%> )
333 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
335 % if ( $curuser->access_right('Unprovision customer service') ) {
336 ( <%svc_unprovision_link($cust_svc)%> )
342 % if ( ! $cust_pkg->get('cancel')
343 % && $curuser->access_right('Provision customer service')
344 % && $part_svc->num_avail
348 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
349 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
359 % } #end display packages
370 my( $cust_main ) = @_;
371 my $conf = new FS::Conf;
373 my $curuser = $FS::CurrentUser::CurrentUser;
375 my $packages = get_packages($cust_main, $conf);
377 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
378 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
381 my( $cust_pkg, $title, $field, %opt ) = @_;
383 my $color = $opt{'color'};
385 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
386 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
387 $html .= qq($title );
388 $html .= qq(</B></FONT>) if length($color);
390 $html .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
395 sub pkg_status_row_if {
396 my( $cust_pkg, $title, $field, %opt ) = @_;
397 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
400 sub pkg_status_row_changed {
401 my( $cust_pkg, %opt ) = @_;
402 return '' unless $cust_pkg->change_date;
403 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date', conf=>$opt{'conf'} );
404 my $old = $cust_pkg->old_cust_pkg;
406 my $part_pkg = $old->part_pkg;
407 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
408 $part_pkg->pkg. ' - '. $part_pkg->comment;
409 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
414 sub pkg_status_row_colspan {
415 my($title, $addl, %opt) = @_;
417 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
418 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
419 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
421 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
422 $html .= qq(<FONT $color $size>) if length($color) || $size;
423 $html .= qq(<B>) if $color && !$size;
425 $html .= qq(</B>) if $color && !$size;
426 $html .= qq(</FONT>) if length($color) || $size;
427 $html .= ", $addl" if length($addl);
428 $html .= qq(</TD></TR>);
437 my $cust_main = shift or return undef;
442 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
443 || ( $conf->exists('hidecancelledpackages')
444 && ! $cgi->param('showcancelledpackages') )
447 $method = 'ncancelled_pkgs';
449 $method = 'all_pkgs';
452 [ $cust_main->$method() ];
455 sub svc_provision_link {
456 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
457 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
458 my $num_avail = $part_svc->num_avail;
459 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
460 "svcpart=". $part_svc->svcpart;
462 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
463 && $conf->exists('svc_external-skip_manual')
465 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
470 'part_svc' => $part_svc,
471 'query' => $pkgnum_svcpart,
473 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
476 my $link = qq!<A CLASS="provision" HREF="$url">!.
477 "Provision $svc_nbsp ($num_avail)</A>";
478 if ( $conf->exists('legacy_link')
479 && $curuser->access_right('View/link unlinked services')
483 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
484 qq!$pkgnum_svcpart">!.
485 "Link to legacy $svc_nbsp ($num_avail)</A>";
490 sub svc_unprovision_link {
491 my $cust_svc = shift or return '';
492 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
493 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
497 my($cust_pkg, $field, $conf) = @_ or return '';
498 return ' ' unless $cust_pkg->get($field);
499 my $format = '<TD align="left"><B>%b</B></TD>'.
500 '<TD align="right"><B> %o,</B></TD>'.
501 '<TD align="right"><B> %Y</B></TD>';
502 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
503 $format .= '<TD ALIGN="right"><B> %l</TD>'.
504 '<TD ALIGN="center"><B>:</B></TD>'.
505 '<TD ALIGN="left"><B>%M</B></TD>'.
506 '<TD ALIGN="left"><B> %P</B></TD>'
507 if $conf->exists('cust_pkg-display_times');
508 my $strip = time2str($format, $cust_pkg->get($field) );
509 $strip =~ s/ (\d)/$1/g;
513 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
514 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
515 'label' => 'Change package',
516 'actionlabel' => 'Change',
522 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
523 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
524 'label' => 'Suspend now',
525 'actionlabel' => 'Suspend',
531 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
532 sub pkg_expire_link { pkg_link('misc/expire_pkg', 'Cancel later', @_ ); }
533 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
535 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
536 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
537 'label' => 'Cancel now',
538 'actionlabel' => 'Cancel',
544 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
545 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
546 'label' => 'Suspend later',
547 'actionlabel' => 'Adjourn',
553 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
554 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
555 'label' => 'Cancel later',
556 'actionlabel' => 'Expire',
562 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
563 { 'action' => $p. 'misc/recharge_svc.html',
564 'label' => 'Recharge',
565 'actionlabel' => 'Recharge',
572 my($action, $label, $cust_pkg) = @_;
573 return '' unless $cust_pkg;
574 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
577 sub pkg_customize_link {
578 my $cust_pkg = shift or return '';
579 my $custnum = $cust_pkg->custnum;
580 qq!<A HREF="${p}edit/part_pkg.cgi?!.
581 "keywords=$custnum;".
582 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
583 "pkgnum=". $cust_pkg->pkgnum.