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 <% popup_link('edit/quick-charge.html?custnum='. $cust_main->custnum, 'One-time charge', 'One-time charge', 545) %>
14 % if ( $curuser->access_right('Bulk change customer packages') ) {
16 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
25 % if ( $cust_main->num_cancelled_pkgs ) {
26 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
27 % || ( $conf->exists('hidecancelledpackages')
28 % && ! $cgi->param('showcancelledpackages')
32 % $cgi->param('showcancelledpackages', 1);
35 ( <a href="<% $cgi->self_url %>">show
37 % $cgi->param('showcancelledpackages', 0);
40 ( <a href="<% $cgi->self_url %>">hide
43 cancelled packages</a> )
48 <% include('/elements/table-grid.html') %>
49 % my $bgcolor1 = '#eeeeee';
50 % my $bgcolor2 = '#ffffff';
54 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
55 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
56 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
59 %foreach my $cust_pkg (@$packages) {
61 % my $part_pkg = $cust_pkg->part_pkg;
63 % if ( $bgcolor eq $bgcolor1 ) {
64 % $bgcolor = $bgcolor2;
66 % $bgcolor = $bgcolor1;
70 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
72 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
73 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
74 <% $part_pkg->pkg %> - <% $part_pkg->comment %><BR>
76 % unless ( $cust_pkg->get('cancel') ) {
77 % if ( $curuser->access_right('Change customer package') ) {
79 ( <%pkg_change_link($cust_pkg)%> )
81 % if ( $curuser->access_right('Edit customer package dates') ) {
83 ( <%pkg_dates_link($cust_pkg)%> )
85 % if ( $curuser->access_right('Customize customer package') ) {
87 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
93 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
94 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
97 % my $part_pkg = shift;
98 % my $freq = $part_pkg->freq_pretty;
99 % $freq =~ s/ / /g;
103 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
104 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
105 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
107 % #false laziness w/edit/REAL_cust_pkg.cgi
108 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
109 % unless ( $part_pkg->is_prepaid ) {
110 % $billed_or_prepaid = 'billed';
111 % $last_bill_or_renewed = 'Last bill';
112 % $next_bill_or_prepaid_until = 'Next bill';
114 % $billed_or_prepaid = 'prepaid';
115 % $last_bill_or_renewed = 'Renewed';
116 % $next_bill_or_prepaid_until = 'Prepaid until';
120 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
122 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000' ) %>
124 <% pkg_status_row_colspan(
125 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
126 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
130 % unless ( $cust_pkg->get('setup') ) {
132 <% pkg_status_row_colspan('Never billed') %>
136 <% pkg_status_row( $cust_pkg, 'Setup', 'setup' ) %>
137 <% pkg_status_row_changed( $cust_pkg ) %>
138 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
139 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp' ) %>
145 % if ( $cust_pkg->get('susp') ) { #status: suspended
147 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
149 <% pkg_status_row_colspan(
150 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
151 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
155 % unless ( $cust_pkg->get('setup') ) {
156 <% pkg_status_row_colspan('Never billed') %>
158 <% pkg_status_row($cust_pkg, 'Setup', 'setup' ) %>
161 <% pkg_status_row_changed( $cust_pkg ) %>
162 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
163 % # pkg_status_row($cust_pkg, 'Next bill', 'bill')
164 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
167 <TD COLSPAN=<%$colspan%>>
169 % if ( $curuser->access_right('Unsuspend customer package') ) {
170 ( <% pkg_unsuspend_link($cust_pkg) %> )
172 % if ( $curuser->access_right('Cancel customer package immediately') ) {
173 ( <% pkg_cancel_link($cust_pkg) %> )
179 % } else { #status: active
181 % unless ( $cust_pkg->get('setup') ) { #not setup
183 % unless ( $part_pkg->freq ) {
185 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
188 <TD COLSPAN=<%$colspan%>>
190 % if ( $curuser->access_right('Cancel customer package immediately') ) {
191 ( <% pkg_cancel_link($cust_pkg) %> )
199 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
205 % unless ( $part_pkg->freq ) {
207 <% pkg_status_row_colspan('One-time charge') %>
209 <% pkg_status_row($cust_pkg, 'Billed', 'setup') %>
213 % if (scalar($cust_pkg->overlimit)) {
215 <% pkg_status_row_colspan(
217 $billed_or_prepaid. ' '. myfreq($part_pkg),
223 <% pkg_status_row_colspan(
225 $billed_or_prepaid. ' '. myfreq($part_pkg),
231 <% pkg_status_row($cust_pkg, 'Setup', 'setup') %>
237 <% pkg_status_row_changed( $cust_pkg ) %>
238 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
239 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill' ) %>
240 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn' ) %>
241 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
243 % if ( $part_pkg->freq ) {
246 <TD COLSPAN=<%$colspan%>>
248 % if ( $curuser->access_right('Suspend customer package') ) {
249 ( <% pkg_suspend_link($cust_pkg) %> )
251 % if ( $curuser->access_right('Suspend customer package later') ) {
252 ( <% pkg_adjourn_link($cust_pkg) %> )
254 % if ( $curuser->access_right('Cancel customer package immediately') ) {
255 ( <% pkg_cancel_link($cust_pkg) %> )
257 % if ( $curuser->access_right('Cancel customer package later') ) {
258 ( <% pkg_expire_link($cust_pkg) %> )
272 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
273 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
275 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
276 % foreach my $part_svc ( $cust_pkg->part_svc ) {
278 % #foreach my $service (@{$svcpart->{services}}) {
279 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
282 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
283 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
287 <TD ALIGN="right" COLSPAN="2" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
289 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
294 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
296 % if ( $curuser->access_right('Recharge customer service')
297 % && $part_svc->svcdb eq 'svc_acct'
298 % && ( $cust_svc->svc_x->seconds ne ''
299 % || $cust_svc->svc_x->upbytes ne ''
300 % || $cust_svc->svc_x->downbytes ne ''
301 % || $cust_svc->svc_x->totalbytes ne ''
304 ( <%svc_recharge_link($cust_svc)%> )
308 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
310 % if ( $curuser->access_right('Unprovision customer service') ) {
311 ( <%svc_unprovision_link($cust_svc)%> )
317 % if ( ! $cust_pkg->get('cancel')
318 % && $curuser->access_right('Provision customer service')
319 % && $part_svc->num_avail
323 <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
324 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
334 % } #end display packages
345 my( $cust_main ) = @_;
346 my $conf = new FS::Conf;
348 my $curuser = $FS::CurrentUser::CurrentUser;
350 my $packages = get_packages($cust_main, $conf);
352 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
353 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
356 my( $cust_pkg, $title, $field, %opt ) = @_;
358 my $color = $opt{'color'};
360 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
361 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
362 $html .= qq($title );
363 $html .= qq(</B></FONT>) if length($color);
365 $html .= pkg_datestr($cust_pkg, $field, $conf).'</TR>';
370 sub pkg_status_row_if {
371 my( $cust_pkg, $title, $field, %opt ) = @_;
372 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
375 sub pkg_status_row_changed {
377 return '' unless $cust_pkg->change_date;
378 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date' );
379 my $old = $cust_pkg->old_cust_pkg;
381 my $part_pkg = $old->part_pkg;
382 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
383 $part_pkg->pkg. ' - '. $part_pkg->comment;
384 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
389 sub pkg_status_row_colspan {
390 my($title, $addl, %opt) = @_;
392 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
393 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
394 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
396 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
397 $html .= qq(<FONT $color $size>) if length($color) || $size;
398 $html .= qq(<B>) if $color && !$size;
400 $html .= qq(</B>) if $color && !$size;
401 $html .= qq(</FONT>) if length($color) || $size;
402 $html .= ", $addl" if length($addl);
403 $html .= qq(</TD></TR>);
415 my $cust_main = shift or return undef;
420 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
421 || ( $conf->exists('hidecancelledpackages')
422 && ! $cgi->param('showcancelledpackages') )
425 $method = 'ncancelled_pkgs';
427 $method = 'all_pkgs';
430 [ $cust_main->$method() ];
433 sub svc_provision_link {
434 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
435 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
436 my $num_avail = $part_svc->num_avail;
437 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
438 "svcpart=". $part_svc->svcpart;
440 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
441 && $conf->exists('svc_external-skip_manual')
443 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
448 'part_svc' => $part_svc,
449 'query' => $pkgnum_svcpart,
451 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
454 my $link = qq!<A CLASS="provision" HREF="$url">!.
455 "Provision $svc_nbsp ($num_avail)</A>";
456 if ( $conf->exists('legacy_link')
457 && $curuser->access_right('View/link unlinked services')
461 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
462 qq!$pkgnum_svcpart">!.
463 "Link to legacy $svc_nbsp ($num_avail)</A>";
468 sub svc_unprovision_link {
469 my $cust_svc = shift or return '';
470 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
471 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
475 my($cust_pkg, $field, $conf) = @_ or return '';
476 return ' ' unless $cust_pkg->get($field);
477 my $format = '<TD align="left"><B>%b</B></TD>'.
478 '<TD align="right"><B> %o,</B></TD>'.
479 '<TD align="right"><B> %Y</B></TD>';
480 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
481 $format .= '<TD ALIGN="right"><B> %l</TD>'.
482 '<TD ALIGN="center"><B>:</B></TD>'.
483 '<TD ALIGN="left"><B>%M</B></TD>'.
484 '<TD ALIGN="left"><B> %P</B></TD>'
485 if $conf->exists('cust_pkg-display_times');
486 my $strip = time2str($format, $cust_pkg->get($field) );
487 $strip =~ s/ (\d)/$1/g;
491 sub pkg_change_link { pkg_popup_link('misc/change_pkg.cgi?dummy=value',
492 'Change package',
498 sub pkg_suspend_link { pkg_popup_link( 'misc/cancel_pkg.html?method=suspend',
505 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
506 sub pkg_expire_link { pkg_link('misc/expire_pkg', 'Cancel later', @_ ); }
507 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
509 sub pkg_cancel_link { pkg_popup_link( 'misc/cancel_pkg.html?method=cancel',
515 sub pkg_adjourn_link { pkg_popup_link( 'misc/cancel_pkg.html?method=adjourn',
516 'Suspend later',
522 sub pkg_expire_link { pkg_popup_link( 'misc/cancel_pkg.html?method=expire',
524 'Expire', #"Cancel package $num later"
529 sub svc_recharge_link { svc_popup_link( 'misc/recharge_svc.html',
537 my($action, $label, $cust_pkg) = @_;
538 return '' unless $cust_pkg;
539 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
543 my($action, $label, $actionlabel, $cust_pkg) = @_;
544 $action .= '&pkgnum='. $cust_pkg->pkgnum;
545 $actionlabel .= ' package '. $cust_pkg->pkgnum;
546 popup_link($action, $label, $actionlabel, 768);
550 my($action, $label, $actionlabel, $cust_svc) = @_;
551 $action .= '?svcnum='. $cust_svc->svcnum;
552 $actionlabel .= ' service '. $cust_svc->svcnum;
553 popup_link($action, $label, $actionlabel, 392);
557 my($action, $label, $actionlabel, $width) = @_;
559 qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('$p$action', $width, 336, 'pkg_or_svc_action_popup' ), CAPTION, '$actionlabel', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">$label</A>!;
562 sub pkg_customize_link {
563 my $cust_pkg = shift or return '';
564 my $custnum = $cust_pkg->custnum;
565 qq!<A HREF="${p}edit/part_pkg.cgi?!.
566 "keywords=$custnum;".
567 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
568 "pkgnum=". $cust_pkg->pkgnum.