push out event triggered suspensions
[freeside.git] / httemplate / view / cust_main / packages.html
index 167c625..5f1db4a 100755 (executable)
@@ -1,5 +1,73 @@
 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
 
+% if ( $curuser->access_right('One-time charge') ) {
+
+<SCRIPT TYPE="text/javascript">
+
+function taxproductmagic(which) {
+  var str = '';
+  var elements = which.form.elements;
+  for (var i = 0; i<elements.length; i++) {
+    if (elements[i].name == 'taxproductnum'){
+      document.getElementById('taxproductnum').value = elements[i].value;
+      continue;
+    }
+    if (elements[i].name == 'taxproductnum_description'){
+      continue;
+    }
+    if (str.length){str += ';';}
+    str += elements[i].name + '=' + escape(elements[i].value);
+  }
+  document.getElementById('charge_storage').value = str;
+  cClick();
+  overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&onclick=taxproductquickchargemagic&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK);
+}
+
+function taxproductquickchargemagic() {
+  var str = document.getElementById('charge_storage').value;
+  if (str.length){str += ';';}
+  str += 'magic=taxproductnum;taxproductnum=';
+  str += escape(document.getElementById('taxproductnum').value);
+  cClick();
+  overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close');
+
+}
+
+function taxoverridemagic(which) {
+  var str = '';
+  var elements = which.ownerDocument.QuickChargeForm.elements;
+  for (var i = 0; i<elements.length; i++) {
+    if (elements[i].name == 'tax_override'){
+      document.getElementById('tax_override').value = elements[i].value;
+      continue;
+    }
+    if (str.length){str += ';';}
+    str += elements[i].name + '=' + escape(elements[i].value);
+  }
+  document.getElementById('charge_storage').value = str;
+  cClick();
+  overlib( OLiframeContent('<% $p %>/edit/part_pkg_taxoverride.html?element_name=tax_override;onclick=taxoverridequickchargemagic;selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK);
+}
+
+function taxoverridequickchargemagic() {
+  var str = document.getElementById('charge_storage').value;
+  if (str.length){str += ';';}
+  str += 'magic=taxoverride;tax_override=';
+  str += document.getElementById('tax_override').value;
+  cClick();
+  overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close');
+
+}
+
+</SCRIPT>
+<FORM NAME='quickcharge'>
+  <INPUT NAME="taxproductnum"  ID="taxproductnum"  TYPE="hidden">
+  <INPUT NAME="tax_override"   ID="tax_override"   TYPE="hidden">
+  <INPUT NAME="charge_storage" ID="charge_storage" TYPE="hidden">
+  <INPUT NAME="taxproductnum_description"  ID="taxproductnum_description" TYPE="hidden">
+</FORM>
+% } 
+
 % my $s = 0;
 % if ( $curuser->access_right('Order customer package') ) { 
   <% $s++ ? ' | ' : '' %>
 %      ) {
 %
   <% $s++ ? ' | ' : '' %>
-  <% popup_link('edit/quick-charge.html?custnum='. $cust_main->custnum, 'One-time charge', 'One-time charge', '#333399', 545) %>
+  <% include('/elements/popup_link.html',
+     { 
+       'action'      => $p. 'edit/quick-charge.html?custnum='. $cust_main->custnum,
+       'label'       => 'One-time charge',
+       'actionlabel' => 'One-time charge',
+       'color'       => '#333399',
+       'width'       => 763,
+     })
+  %>
 % } 
+
 % if ( $curuser->access_right('Bulk change customer packages') ) { 
   <% $s++ ? ' | ' : '' %>
   <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
@@ -72,13 +149,32 @@ Current packages
 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
 <TR>
 
-  <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+  <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
+    <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
+      <TR>
+        <TD COLSPAN=2>
+          <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
+             ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
+          ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><% $part_pkg->pkg %></A>
+          - 
+          <% $part_pkg->comment %>
+        </TD>
+      </TR>
+
+%   if ( $cust_pkg->quantity > 1 ) {
+      <TR>
+        <TD COLSPAN=2>
+          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quantity: 
+          <B><% $cust_pkg->quantity %></B>
+        </TD>
+      </TR>
+%   }
+
+      <TR>
+        <TD COLSPAN=2>
 
-    <A NAME="cust_pkg<% $cust_pkg->pkgnum %>" ID="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
-    <% $part_pkg->pkg %> - <% $part_pkg->comment %>
-    <BR>
+          <FONT SIZE=-1>
 
-    <FONT SIZE=-1>
 % unless ( $cust_pkg->get('cancel') ) { 
 %   my $br = 0;
 %   if ( $curuser->access_right('Change customer package') ) { $br=1;
@@ -104,7 +200,114 @@ Current packages
     (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
 % }
 
-    </FONT>
+          </FONT>
+
+        </TD>
+      </TR>
+
+%   my $editi = $curuser->access_right('Edit customer package invoice details');
+%   my $editc = $curuser->access_right('Edit customer package comments');
+%
+%   if ( $cust_pkg->cust_pkg_detail('I') || $cust_pkg->cust_pkg_detail('C')
+%        || $editi || $editc                                                ) {
+%
+%     my $editlink = $p. 'edit/cust_pkg_detail?pkgnum='. $cust_pkg->pkgnum.
+%                    ';detailtype=';
+
+      <TR>
+
+%       if ( $cust_pkg->cust_pkg_detail('I') ) { 
+          <TD VALIGN="top">
+            <% include('/elements/table-grid.html') %>
+              <TR>
+                <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
+                  <FONT SIZE="-1">
+                    Invoice details
+%                   if ( $editi && ! $cust_pkg->get('cancel') ) {
+                      (<% include('/elements/popup_link.html', { 
+                                    'action'      => $editlink. 'I',
+                                    'label'       => 'edit',
+                                    'actionlabel' => 'Edit invoice details',
+                                    'color'       => '#333399',
+                                    'width'       => 763,
+                                 })
+                       %>)
+%                   }
+                  </FONT>
+                </TH>
+              </TR>
+%             foreach my $cust_pkg_detail ( $cust_pkg->cust_pkg_detail('I') ) {
+                <TR>
+                  <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
+                </TR>
+%             }
+            </TABLE>
+          </TD>
+%       } else {
+          <TD>
+%           if ( $editi && ! $cust_pkg->get('cancel') ) {
+              <FONT SIZE="-1">
+                (&nbsp;<% include('/elements/popup_link.html', { 
+                               'action'      => $editlink. 'I',
+                               'label'       => 'Add&nbsp;invoice&nbsp;details',
+                               'actionlabel' => 'Add invoice details',
+                               'color'       => '#333399',
+                               'width'       => 763,
+                            })
+                  %>&nbsp;)
+              </FONT>
+%           }
+          </TD>
+%       }
+
+%       if ( $cust_pkg->cust_pkg_detail('C') ) { 
+          <TD VALIGN="top">
+            <% include('/elements/table-grid.html') %>
+              <TR>
+                <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
+                  <FONT SIZE="-1">
+                    Comments
+%                   if ( $editc ) {
+                      (<% include('/elements/popup_link.html', { 
+                                    'action'      => $editlink. 'C',
+                                    'label'       => 'edit',
+                                    'actionlabel' => 'Edit comments',
+                                    'color'       => '#333399',
+                                    'width'       => 763,
+                                 })
+                       %>)
+%                   }
+                  </FONT>
+                </TH>
+              </TR>
+%             foreach my $cust_pkg_detail ( $cust_pkg->cust_pkg_detail('C') ) {
+                <TR>
+                  <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
+                </TR>
+%             }
+            </TABLE>
+          </TD>
+%       } else {
+          <TD>
+%           if ( $editc ) {
+              <FONT SIZE="-1">
+                (&nbsp;<% include('/elements/popup_link.html', { 
+                               'action'      => $editlink. 'C',
+                               'label'       => 'Add&nbsp;comments',
+                               'actionlabel' => 'Add comments',
+                               'color'       => '#333399',
+                               'width'       => 763,
+                            })
+                  %>&nbsp;)
+              </FONT>
+%           }
+          </TD>
+%       }
+
+      </TR>
+%   }
+
+    </TABLE>
 
   </TD>
 
@@ -136,11 +339,12 @@ Current packages
 %
 %
 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
+%   my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
 
-    <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000' ) %>
+    <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
 
     <% pkg_status_row_colspan(
-         ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
+         ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
          'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
        )
     %>
@@ -151,21 +355,22 @@ Current packages
 
 %   } else { 
 
-       <% pkg_status_row( $cust_pkg, 'Setup', 'setup' ) %>
-       <% pkg_status_row_changed( $cust_pkg ) %>
-       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
-       <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp' ) %>
+       <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
+       <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
+       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
+       <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf, curuser=>$curuser ) %>
 
 %   } 
 %
 % } else { 
 %
 %   if ( $cust_pkg->get('susp') ) { #status: suspended
+%     my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
 
-    <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
+    <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
 
     <% pkg_status_row_colspan(
-         ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
+         ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
          'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
        )
     %>
@@ -173,13 +378,13 @@ Current packages
 %   unless ( $cust_pkg->get('setup') ) { 
       <% pkg_status_row_colspan('Never billed') %>
 %   } else { 
-      <% pkg_status_row($cust_pkg, 'Setup', 'setup' ) %>
+      <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
 %   } 
 
-    <% pkg_status_row_changed( $cust_pkg ) %>
-    <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
-%   # pkg_status_row($cust_pkg, 'Next bill', 'bill')
-    <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
+    <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
+    <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
+%   # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
+    <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf, curuser=>$curuser ) %>
 
     <TR>
       <TD COLSPAN=<%$colspan%>>
@@ -224,7 +429,7 @@ Current packages
 
           <% pkg_status_row_colspan('One-time&nbsp;charge') %>
 
-          <% pkg_status_row($cust_pkg, 'Billed', 'setup') %>
+          <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
 
 %       } else { 
 %
@@ -246,17 +451,20 @@ Current packages
             %>
 %         } 
 
-          <% pkg_status_row($cust_pkg, 'Setup', 'setup') %>
+          <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
 
 %       } 
 %
 %     } 
+%   my $autosuspend = pkg_autosuspend_time( $cust_pkg );
+%   $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
 
-      <% pkg_status_row_changed( $cust_pkg ) %>
-      <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
-      <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill' ) %>
-      <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn' ) %>
-      <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
+      <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
+      <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
+      <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf, curuser=>$curuser ) %>
+      <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', conf=>$conf) %>
+      <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf, curuser=>$curuser ) %>
+      <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf, curuser=>$curuser ) %>
 
 %     if ( $part_pkg->freq ) { 
 
@@ -269,6 +477,9 @@ Current packages
 %             if ( $curuser->access_right('Suspend customer package later') ) { 
                 (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
 %             } 
+%             if ( $curuser->access_right('Delay suspension events') ) { 
+                (&nbsp;<% pkg_delay_link($cust_pkg) %>&nbsp;)
+%             } 
 %             if ( $curuser->access_right('Cancel customer package immediately') ) { 
                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
 %             } 
@@ -299,10 +510,11 @@ Current packages
       <TR>
         <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
         <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
+        <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
       </TR>
 
       <TR>
-        <TD ALIGN="right" COLSPAN="2" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
+        <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
 
             <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
           </FONT></TD>
@@ -338,7 +550,7 @@ Current packages
 %      ) {
 
       <TR>
-        <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
+        <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
           <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
         </TD>
       </TR>
@@ -389,20 +601,31 @@ sub pkg_status_row {
   $html   .= qq($title&nbsp;);
   $html   .= qq(</B></FONT>) if length($color);
   $html   .= qq(</TD>);
-  $html   .= pkg_datestr($cust_pkg, $field, $conf).'</TR>';
+  $html   .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
 
   $html;
 }
 
 sub pkg_status_row_if {
   my( $cust_pkg, $title, $field, %opt ) = @_;
-  $cust_pkg->get($field) ? pkg_status_row(@_) : '';
+  
+  $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unadjourn_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
+    if ( $field eq 'adjourn' &&
+         $opt{curuser}->access_right('Suspend customer package later')
+       );
+
+  $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unexpire_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
+    if ( $field eq 'expire' &&
+         $opt{curuser}->access_right('Cancel customer package later')
+       );
+
+  $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
 }
 
 sub pkg_status_row_changed {
-  my($cust_pkg) = @_;
+  my( $cust_pkg, %opt ) = @_;
   return '' unless $cust_pkg->change_date;
-  my $html = pkg_status_row( $cust_pkg, 'Package&nbsp;changed', 'change_date' );
+  my $html = pkg_status_row( $cust_pkg, 'Package&nbsp;changed', 'change_date', conf=>$opt{'conf'} );
   my $old = $cust_pkg->old_cust_pkg;
   if ( $old ) {
     my $part_pkg = $old->part_pkg;
@@ -433,9 +656,6 @@ sub pkg_status_row_colspan {
 
 }
 
-</%init>
-<%once>
-
 #subroutines
 
 sub get_packages {
@@ -515,64 +735,89 @@ sub pkg_datestr {
   $strip;
 }
 
-sub pkg_change_link    { pkg_popup_link('misc/change_pkg.cgi?dummy=value',
-                                          'Change&nbsp;package',
-                                          'Change',
-                                          '',
-                                          @_
-                                       );
-                       }
-
-sub pkg_suspend_link   { pkg_popup_link( 'misc/cancel_pkg.html?method=suspend',
-                                         'Suspend&nbsp;now',
-                                         'Suspend',
-                                         '#FF9900',
-                                         @_
-                                       );
-                       }
-
-sub pkg_adjourn_link   { pkg_popup_link( 'misc/cancel_pkg.html?method=adjourn',
-                                         'Suspend&nbsp;later',
-                                         'Adjourn',
-                                         '#CC6600',
-                                         @_
-                                       );
-                       }
+sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
+                               { 'action'      => $p. 'misc/change_pkg.cgi?dummy=value',
+                                 'label'       => 'Change&nbsp;package',
+                                 'actionlabel' => 'Change',
+                                 'cust_pkg'    => shift,
+                               }
+                             )
+                     }
+
+sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
+                                { 'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
+                                  'label'       => 'Suspend&nbsp;now',
+                                  'actionlabel' => 'Suspend',
+                                  'color'       => '#FF9900',
+                                  'cust_pkg'    => shift,
+                                }
+                              )
+                     }
+
+
+sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
+                                { 'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
+                                  'label'       => 'Suspend&nbsp;later',
+                                  'actionlabel' => 'Adjourn',
+                                  'color'       => '#CC6600',
+                                  'cust_pkg'    => shift,
+                                }
+                              )
+                     }
+
+sub pkg_delay_link   { include( '/elements/popup_link-cust_pkg.html',
+                                { 'action'      => $p. 'misc/delay_susp_pkg.html',
+                                  'label'       => 'Delay&nbsp;suspend',
+                                  'actionlabel' => 'Delay suspend for',
+                                  'cust_pkg'    => shift,
+                                }
+                              )
+                     }
 
 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    'Unsuspend',           @_ ); }
-sub pkg_expire_link    { pkg_link('misc/expire_pkg',    'Cancel&nbsp;later',   @_ ); }
 sub pkg_dates_link     { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates',     @_ ); }
-
-sub pkg_cancel_link    { pkg_popup_link( 'misc/cancel_pkg.html?method=cancel',
-                                         'Cancel&nbsp;now',
-                                         'Cancel',
-                                         '#ff0000',
-                                         @_
-                                       );
-                       }
-
-sub pkg_expire_link    { pkg_popup_link( 'misc/cancel_pkg.html?method=expire',
-                                         'Cancel&nbsp;later',
-                                         'Expire', #"Cancel package $num later"
-                                         '#CC0000',
-                                         @_
-                                       );
-                       }
-
-sub svc_recharge_link  { svc_popup_link( 'misc/recharge_svc.html',
-                                         'Recharge',
-                                         'Recharge',
-                                         '#333399',
-                                         @_
-                                       );
-                       }
-
-sub order_pkg_link { cust_popup_link( 'misc/order_pkg.html',
-                                      'Order&nbsp;new&nbsp;package',
-                                      'Order new package',
-                                      '#333399',
-                                      @_
-                                    );
+sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort',               @_ ); }
+sub pkg_unexpire_link  { pkg_link('misc/unexpire_pkg',  'Abort',               @_ ); }
+
+sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
+                               { 'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
+                                 'label'       => 'Cancel&nbsp;now',
+                                 'actionlabel' => 'Cancel',
+                                 'color'       => '#ff0000',
+                                 'cust_pkg'    => shift,
+                               }
+                             )
+                    }
+
+sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
+                               { 'action'      => $p. 'misc/cancel_pkg.html?method=expire',
+                                 'label'       => 'Cancel&nbsp;later',
+                                 'actionlabel' => 'Expire', #"Cancel package $num later"
+                                 'color'       => '#CC0000',
+                                 'cust_pkg'    => shift,
+                               }
+                             )
+                    }
+
+sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
+                                 { 'action'      => $p. 'misc/recharge_svc.html',
+                                   'label'       => 'Recharge',
+                                   'actionlabel' => 'Recharge',
+                                   'color'       => '#333399',
+                                   'cust_svc'    => shift,
+                                 }
+                               )
+                      }
+
+sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
+                              { 'action'      => $p. 'misc/order_pkg.html',
+                                'label'       => 'Order&nbsp;new&nbsp;package',
+                                'actionlabel' => 'Order new package',
+                                'color'       => '#333399',
+                                'cust_main'   => shift,
+                                'closetext'   => 'Close',
+                              }
+                            )
                    }
 
 sub pkg_event_link {
@@ -588,41 +833,34 @@ sub pkg_link {
   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
 }
 
-sub pkg_popup_link {
-  my($action, $label, $actionlabel, $color, $cust_pkg) = @_;
-  $action .= '&pkgnum='. $cust_pkg->pkgnum;
-  $actionlabel .= ' package '. $cust_pkg->pkgnum;
-  popup_link($action, $label, $actionlabel, $color, 768);
-}
-
-sub svc_popup_link {
-  my($action, $label, $actionlabel, $color, $cust_svc) = @_;
-  $action .= '?svcnum='. $cust_svc->svcnum;
-  $actionlabel .= ' service '. $cust_svc->svcnum;
-  popup_link($action, $label, $actionlabel, $color);
-}
-
-sub cust_popup_link {
-  my($action, $label, $actionlabel, $color, $cust_main) = @_;
-  $action .= '?'. $cust_main->custnum;
-  popup_link($action, $label, $actionlabel, $color);
-}
-
-sub popup_link {
-  my($action, $label, $actionlabel, $color, $width) = @_;
-  $color ||= '#333399';
-  $width ||= 540;
-  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, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;">$label</A>!;
-}
-
 sub pkg_customize_link {
   my $cust_pkg = shift or return '';
   my $custnum = $cust_pkg->custnum;
   qq!<A HREF="${p}edit/part_pkg.cgi?!.
-    "keywords=$custnum;".
     "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
     "pkgnum=". $cust_pkg->pkgnum.
     qq!">Customize</A>!;
 }
 
-</%once>
+sub pkg_autosuspend_time {
+  my $cust_pkg = shift or return '';
+  my $days = 7;
+  my $time = time;
+  my $pending_suspend = 0;
+  while ( $days > 0 &&
+          scalar(
+            grep { $_->part_event->action eq 'suspend' }
+            @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
+                                                    testonly => 1,
+                                                  ) }
+          )
+        )
+  {
+    $pending_suspend = 1;
+    $days--;
+  }
+
+  $pending_suspend ? time + ($days + 1) * 86400 : '';
+
+}
+</%init>