don't re-my var, quiet warning
[freeside.git] / FS / FS / cust_bill_event.pm
index 146a30e..ddd6762 100644 (file)
@@ -3,6 +3,7 @@ package FS::cust_bill_event;
 use strict;
 use vars qw( @ISA );
 use FS::Record qw( qsearch qsearchs );
+use FS::cust_bill;
 use FS::part_bill_event;
 
 @ISA = qw(FS::Record);
@@ -43,6 +44,10 @@ currently supported:
 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
+=item status - event status: B<done> or B<failed>
+
+=item statustext - additional status detail (i.e. error message)
+
 =back
 
 =head1 METHODS
@@ -111,13 +116,13 @@ sub check {
     || $self->ut_textn('statustext')
   ;
 
-  return "Unknown invnum"
+  return "Unknown invnum ". $self->invnum
     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
 
-  return "Unknown eventpart"
+  return "Unknown eventpart ". $self->eventpart
     unless qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
 
-  ''; #no error
+  $self->SUPER::check;
 }
 
 =item part_bill_event
@@ -132,6 +137,32 @@ sub part_bill_event {
   qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } );
 }
 
+=item cust_bill
+
+Returns the invoice (see L<FS::cust_bill>) for this completed invoice event.
+
+=cut
+
+sub cust_bill {
+  my $self = shift;
+  qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
+}
+
+=item retry
+
+Changes the status of this event from B<done> to B<failed>, allowing it to be
+retried.
+
+=cut
+
+sub retry {
+  my $self = shift;
+  return '' unless $self->status eq 'done';
+  my $old = ref($self)->new( { $self->hash } );
+  $self->status('failed');
+  $self->replace($old);
+}
+
 =back
 
 =head1 BUGS