show user who created (cancel/suspend) reason and possibly fix a lingering spurious...
authorjeff <jeff>
Wed, 16 Apr 2008 18:32:34 +0000 (18:32 +0000)
committerjeff <jeff>
Wed, 16 Apr 2008 18:32:34 +0000 (18:32 +0000)
FS/FS/cust_pkg.pm
FS/FS/cust_pkg_reason.pm
httemplate/view/cust_main/packages.html

index d6d2dad..2e23cce 100644 (file)
@@ -710,6 +710,22 @@ sub last_bill {
   $cust_bill_pkg ? $cust_bill_pkg->sdate : $self->setup || 0;
 }
 
+=item last_cust_pkg_reason
+
+Returns the most recent FS::reason associated with the package.
+
+=cut
+
+sub last_cust_pkg_reason {
+  my $self = shift;
+  qsearchs( {
+              'table' => 'cust_pkg_reason',
+              'hashref' => { 'pkgnum' => $self->pkgnum, },
+              'extra_sql'=> "AND date <= ". time,
+              'order_by' => 'ORDER BY date DESC LIMIT 1',
+           } );
+}
+
 =item last_reason
 
 Returns the most recent FS::reason associated with the package.
@@ -717,13 +733,8 @@ Returns the most recent FS::reason associated with the package.
 =cut
 
 sub last_reason {
-  my $self = shift;
-  my $cust_pkg_reason = qsearchs( {
-                                    'table' => 'cust_pkg_reason',
-                                   'hashref' => { 'pkgnum' => $self->pkgnum, },
-                                   'extra_sql'=> 'ORDER BY date DESC LIMIT 1',
-                                 } );
-  qsearchs ( 'reason', { 'reasonnum' => $cust_pkg_reason->reasonnum } )
+  my $cust_pkg_reason = shift->last_cust_pkg_reason;
+  $cust_pkg_reason->reason
     if $cust_pkg_reason;
 }
 
index 2f92740..24808f9 100644 (file)
@@ -106,6 +106,29 @@ sub check {
   $self->SUPER::check;
 }
 
+=item reason
+
+Returns the reason (see L<FS::reason>) associated with this cust_pkg_reason.
+
+=cut
+
+sub reason {
+  my $self = shift;
+  qsearchs( 'reason', { 'reasonnum' => $self->reasonnum } );
+}
+
+=item reasontext
+
+Returns the text of the reason (see L<FS::reason>) associated with this
+cust_pkg_reason.
+
+=cut
+
+sub reasontext {
+  my $reason = shift->reason;
+  $reason ? $reason->reason : '';
+}
+
 =back
 
 =head1 BUGS
index 0d36f5b..0ef9e6c 100755 (executable)
@@ -125,15 +125,22 @@ Current packages
 %
 %
 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
+%   my $cpr = $cust_pkg->last_cust_pkg_reason;
 
     <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000' ) %>
 
     <% pkg_status_row_colspan(
-         ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
+         ( ( $cpr && ( $cpr->date == $cust_pkg->get('cancel') ||
+                       $cpr->date == $cust_pkg->expire
+                     )
+           ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
          'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
        )
     %>
 
+
+    <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
+
 %   unless ( $cust_pkg->get('setup') ) { 
 
         <% pkg_status_row_colspan('Never billed') %>
@@ -150,11 +157,15 @@ Current packages
 % } else { 
 %
 %   if ( $cust_pkg->get('susp') ) { #status: suspended
+%     my $cpr = $cust_pkg->last_cust_pkg_reason;
 
     <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
 
     <% pkg_status_row_colspan(
-         ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
+         ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
+                       $cpr->date == $cust_pkg->adjourn
+                     )
+           ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
          'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
        )
     %>