suspend later just like expire (#1487)
authorjeff <jeff>
Tue, 26 Jun 2007 15:37:19 +0000 (15:37 +0000)
committerjeff <jeff>
Tue, 26 Jun 2007 15:37:19 +0000 (15:37 +0000)
13 files changed:
FS/FS/AccessRight.pm
FS/FS/Cron/bill.pm
FS/FS/Cron/notify.pm
FS/FS/Schema.pm
FS/FS/cust_main.pm
FS/FS/cust_pkg.pm
httemplate/edit/REAL_cust_pkg.cgi
httemplate/edit/process/REAL_cust_pkg.cgi
httemplate/misc/cancel_pkg.html
httemplate/misc/process/cancel_pkg.html
httemplate/search/cust_pkg.cgi
httemplate/search/report_cust_pkg.html
httemplate/view/cust_main/packages.html

index f67614a..7a8bfc2 100644 (file)
@@ -106,6 +106,7 @@ assigned to users and/or groups.
   'Edit customer package dates',
   'Customize customer package',
   'Suspend customer package',
+  'Suspend customer package later',
   'Unsuspend customer package',
   'Cancel customer package immediately',
   'Cancel customer package later',
index 9926fea..b6925d0 100644 (file)
@@ -34,6 +34,7 @@ sub bill {
               and (    setup is null or setup =  0
                     or bill  is null or bill  <= $time 
                     or ( expire is not null and expire <= $^T )
+                    or ( adjourn is not null and adjourn <= $^T )
                   )
         )
 END
@@ -91,8 +92,10 @@ END
     }
     # $^T not $time because -d is for pre-printing invoices
     foreach my $cust_pkg (
-      grep { $_->part_pkg->is_prepaid
-             && $_->bill && $_->bill < $^T && ! $_->susp
+      grep { (    $_->part_pkg->is_prepaid && $_->bill && $_->bill < $^T
+               || $_->adjourn && $_->adjourn <= $^T
+             )
+             && ! $_->susp
            }
            $cust_main->ncancelled_pkgs
     ) {
index 3710650..622f15f 100644 (file)
@@ -42,6 +42,11 @@ sub notify_flat_delay {
                                 or  cust_pkg.expire > $time
                                   + cast(part_pkg_option.optionvalue as integer)
                                     * 86400
+/*                            and ( cust_pkg.adjourn is null
+                                or  cust_pkg.adjourn > $time
+-- Should notify suspended ones   + cast(part_pkg_option.optionvalue as integer)
+                                    * 86400
+*/
                                   )
                         )
           )
index 7f5149b..5ff549d 100644 (file)
@@ -651,6 +651,7 @@ sub tables_hashref {
         'bill',      @date_type, '', '', 
         'last_bill', @date_type, '', '', 
         'susp',      @date_type, '', '', 
+        'adjourn',   @date_type, '', '', 
         'cancel',    @date_type, '', '', 
         'expire',    @date_type, '', '', 
         'manual_flag', 'char', 'NULL', 1, '', '', 
index 641b8cd..51aa4d5 100644 (file)
@@ -4725,7 +4725,7 @@ sub batch_import {
     my %svc_acct = ();
     foreach my $field ( @fields ) {
 
-      if ( $field =~ /^cust_pkg\.(pkgpart|setup|bill|susp|expire|cancel)$/ ) {
+      if ( $field =~ /^cust_pkg\.(pkgpart|setup|bill|susp|adjourn|expire|cancel)$/ ) {
 
         #$cust_pkg{$1} = str2time( shift @$columns );
         if ( $1 eq 'pkgpart' ) {
index 055b87b..45a5380 100644 (file)
@@ -111,6 +111,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item last_bill - last bill date
 
+=item adjourn - date
+
 =item susp - date
 
 =item expire - date
@@ -124,7 +126,7 @@ unsuspension of this package when using the B<unsuspendauto> config file.
 
 =back
 
-Note: setup, bill, susp, expire and cancel are specified as UNIX timestamps;
+Note: setup, bill, adjourn, susp, expire and cancel are specified as UNIX timestamps;
 see L<perlfunc/"time">.  Also see L<Time::Local> and L<Date::Parse> for
 conversion functions.
 
@@ -264,7 +266,7 @@ the customer ever purchased the item.  Instead, see the cancel method.
 Replaces the OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
 
-Currently, custnum, setup, bill, susp, expire, and cancel may be changed.
+Currently, custnum, setup, bill, adjourn, susp, expire, and cancel may be changed.
 
 Changing pkgpart may have disasterous effects.  See the order subroutine.
 
@@ -310,13 +312,15 @@ sub replace {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  if ($options{'reason'} && $new->expire && $old->expire ne $new->expire) {
-    my $error = $new->insert_reason( 'reason' => $options{'reason'},
-                                     'date'      => $new->expire,
-                                   );
-    if ( $error ) {
-      dbh->rollback if $oldAutoCommit;
-      return "Error inserting cust_pkg_reason: $error";
+  foreach my $method ( qw(adjourn expire) ) {  # How many reasons?
+    if ($options{'reason'} && $new->$method && $old->$method ne $new->$method) {
+      my $error = $new->insert_reason( 'reason' => $options{'reason'},
+                                       'date'      => $new->$method,
+                                     );
+      if ( $error ) {
+        dbh->rollback if $oldAutoCommit;
+        return "Error inserting cust_pkg_reason: $error";
+      }
     }
   }
 
@@ -377,6 +381,8 @@ sub check {
     || $self->ut_numbern('bill')
     || $self->ut_numbern('susp')
     || $self->ut_numbern('cancel')
+    || $self->ut_numbern('adjourn')
+    || $self->ut_numbern('expire')
   ;
   return $error if $error;
 
@@ -601,7 +607,8 @@ sub suspend {
 =item unsuspend [ OPTION => VALUE ... ]
 
 Unsuspends all services (see L<FS::cust_svc> and L<FS::part_svc>) in this
-package, then unsuspends the package itself (clears the susp field).
+package, then unsuspends the package itself (clears the susp field and the
+adjourn field if it is in the past).
 
 Available options are: I<adjust_next_bill>.
 
@@ -666,6 +673,7 @@ sub unsuspend {
       && $inactive > 0 && ( $hash{'bill'} || $hash{'setup'} );
 
     $hash{'susp'} = '';
+    $hash{'adjourn'} = '' if $hash{'adjourn'} < time;
     my $new = new FS::cust_pkg ( \%hash );
     $error = $new->replace( $self, options => { $self->options } );
     if ( $error ) {
index 69bbb9b..7a9e030 100755 (executable)
@@ -50,8 +50,9 @@
 %
 %
 %#print info
-%my($susp,$cancel,$expire)=(
+%my($susp,$adjourn,$cancel,$expire)=(
 %  $cust_pkg->getfield('susp'),
+%  $cust_pkg->getfield('adjourn'),
 %  $cust_pkg->getfield('cancel'),
 %  $cust_pkg->getfield('expire'),
 %);
       <IMG SRC="../images/calendar.png" ID="bill_button" STYLE="cursor: pointer" TITLE="Select date">
     </TD>
   </TR>
+  <TR>
+    <TD ALIGN="right">Adjournment date</TD>
+    <TD>
+      <INPUT TYPE="text" NAME="adjourn" SIZE=32 ID="adjourn_text" VALUE="<% ( $adjourn ? time2str($format, $adjourn) : "" ) %>">
+      <IMG SRC="../images/calendar.png" ID="adjourn_button" STYLE="cursor: pointer" TITLE="Select date">
+      <BR><FONT SIZE=-1>(will <b>suspend</b> this package when the date is reached)</FONT>
+    </TD>
+  </TR>
 % if ( $susp ) { 
 
     <TR>
index 26e234f..9255672 100755 (executable)
@@ -7,6 +7,7 @@
 %$hash{'bill'} = $cgi->param('bill') ? str2time($cgi->param('bill')) : '';
 %$hash{'last_bill'} =
 %  $cgi->param('last_bill') ? str2time($cgi->param('last_bill')) : '';
+%$hash{'adjourn'} = $cgi->param('adjourn') ? str2time($cgi->param('adjourn')) : '';
 %$hash{'expire'} = $cgi->param('expire') ? str2time($cgi->param('expire')) : '';
 %
 %my $new;
index e610006..b085d22 100755 (executable)
@@ -23,9 +23,9 @@
 <% ucfirst($method) . " $pkgnum: " .$part_pkg->pkg. ' - ' .$part_pkg->comment %>
 <% ntable("#cccccc", 2) %>
 
-% if ($method eq 'expire') {
+% if ($method eq 'expire' || $method eq 'adjourn') {
 <TR>
-  <TD>Cancel package on </TD>
+  <TD><% $submit =~ /^(\w*)\s/ %> package on </TD>
     <TD><INPUT TYPE="text" NAME="date" ID="expire_date" VALUE="<% $date %>">
         <IMG SRC="<% $p %>images/calendar.png" ID="expire_button" STYLE="cursor:pointer" TITLE="Select date">
         <BR><I>m/d/y</I>
@@ -77,7 +77,10 @@ if ($method eq 'cancel') {
   $submit    = "Cancel Later";
 }elsif ($method eq 'suspend') {
   $class = 'S';
-  $submit    = "Suspend";
+  $submit    = "Suspend Now";
+}elsif ($method eq 'adjourn') {
+  $class = 'S';
+  $submit    = "Suspend Later";
 }else{
   die "illegal query ". $cgi->keywords;
 }
index cd533be..50b1110 100755 (executable)
@@ -1,7 +1,7 @@
 <%init>
 #untaint method
 my $method = $cgi->param('method');
-$method =~ /^(cancel|expire|suspend)$/ || die "Illegal method";
+$method =~ /^(cancel|expire|suspend|adjourn)$/ || die "Illegal method";
 $method = $1;
 
 #untaint pkgnum
@@ -15,7 +15,7 @@ $reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum";
 $reasonnum = $1;
 
 my $date = time;
-if ($method eq 'expire'){
+if ($method eq 'expire' || $method eq 'adjourn'){
   #untaint date
   $date = $cgi->param('date');
   str2time($cgi->param('date')) =~ /^(\d+)$/ || die "Illegal date";
@@ -47,9 +47,9 @@ if ($reasonnum == -1) {
 }
 
 unless ($error) {
-  if ($method eq 'expire'){
+  if ($method eq 'expire' || $method eq 'adjourn'){
     my %hash = $cust_pkg->hash;
-    $hash{'expire'}=$date;
+    $hash{$method}=$date;
     my $new = new FS::cust_pkg (\%hash);
     $error = $new->replace($cust_pkg, 'reason' => $reasonnum);
   }else{
@@ -68,6 +68,7 @@ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
  my %past = ( 'cancel'  => 'cancelled',
               'expire'  => 'expired',
               'suspend' => 'suspended',
+              'adjourn' => 'adjourned',
             );
 </%init>
 <% header("Package $past{$method}") %>
index 4fd5e9d..941a2e7 100755 (executable)
@@ -12,6 +12,7 @@
                                      'Setup',
                                      'Last bill',
                                      'Next bill',
+                                     'Adjourn',
                                      'Susp.',
                                      'Expire',
                                      'Cancel',
@@ -43,7 +44,7 @@
                     #sub { time2str('%b %d %Y', shift->expire); },
                     #sub { time2str('%b %d %Y', shift->get('cancel')); },
                     ( map { time_or_blank($_) }
-                          qw( setup last_bill bill susp expire cancel ) ),
+                          qw( setup last_bill bill adjourn susp expire cancel ) ),
 
                     \&FS::UI::Web::cust_fields,
                     #sub { '<table border=0 cellspacing=0 cellpadding=0 STYLE="border:none">'.
@@ -210,14 +211,14 @@ my $orderby = '';
 #false laziness w/report_cust_pkg.html
 my %disable = (
   'all'             => {},
-  'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
+  'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
   'active'          => { 'susp'=>1, 'cancel'=>1 },
   'suspended'       => { 'cancel' => 1 },
   'cancelled'       => {},
   ''                => {},
 );
 
-foreach my $field (qw( setup last_bill bill susp expire cancel )) {
+foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) {
 
   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
 
index 1412816..57180c1 100755 (executable)
@@ -26,7 +26,7 @@
 
           if ( what.options[what.selectedIndex].value == '<% $status %>' ) {
 
-%           foreach my $field (qw( setup last_bill bill susp expire cancel )) {
+%           foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) {
 %             if ( $disable{$status}->{$field} ) {
 
                 what.form.<% $field %>_beginning_text.disabled = true;
@@ -68,7 +68,7 @@
                )
     %>
 
-%   foreach my $field (qw( setup last_bill bill susp expire cancel )) {
+%   foreach my $field (qw( setup last_bill bill adjourn susp expire cancel )) {
 
       <TR>
         <TD ALIGN="right" VALIGN="center"><% $label{$field} %></TD>
@@ -116,6 +116,7 @@ my %label = (
   'setup'     => 'Setup',
   'last_bill' => 'Last bill',
   'bill'      => 'Next bill',
+  'adjourn'   => 'Adjourns',
   'susp'      => 'Suspended',
   'expire'    => 'Expires',
   'cancel'    => 'Cancelled',
@@ -124,7 +125,7 @@ my %label = (
 #false laziness w/cust_pkg.cgi
 my %disable = (
   'all'             => {},
-  'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
+  'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
   'active'          => { 'susp'=>1, 'cancel'=>1 },
   'suspended'       => { 'cancel' => 1 },
   'cancelled'       => {},
index 98acb86..5890726 100755 (executable)
@@ -299,6 +299,13 @@ Current packages
         <% pkg_datestr($cust_pkg, 'bill', $conf) %>
       </TR>
 % } 
+% if ( $cust_pkg->get('adjourn') ) { 
+
+      <TR>
+        <TD WIDTH="<%$width%>" ALIGN="right">Adjourns&nbsp;</TD>
+        <% pkg_datestr($cust_pkg, 'adjourn', $conf) %>
+      </TR>
+% } 
 % if ( $cust_pkg->get('expire') ) { 
 
       <TR>
@@ -315,6 +322,10 @@ Current packages
 
               (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
 % } 
+% if ( $curuser->access_right('Suspend customer package later') ) { 
+
+              (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
+% } 
 % if ( $curuser->access_right('Cancel customer package immediately') ) { 
 
               (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
@@ -489,7 +500,7 @@ Current packages
 %sub pkg_change_link    { pkg_link('misc/change_pkg',    'Change&nbsp;package', @_ ); }
 %
 %sub pkg_suspend_link   { pkg_popup_link( 'misc/cancel_pkg.html?method=suspend',
-%                                         'Suspend',
+%                                         'Suspend&nbsp;now',
 %                                         'Suspend',
 %                                         @_
 %                                       );
@@ -505,6 +516,13 @@ Current packages
 %                                         @_
 %                                       );
 %                       }
+%sub pkg_adjourn_link   { pkg_popup_link( 'misc/cancel_pkg.html?method=adjourn',
+%                                         'Suspend&nbsp;later',
+%                                         'Adjourn',
+%                                         @_
+%                                       );
+%                       }
+%
 %sub pkg_expire_link    { pkg_popup_link( 'misc/cancel_pkg.html?method=expire',
 %                                         'Cancel&nbsp;later',
 %                                         'Expire', #"Cancel package $num later"