prepaid download/upload tracking
[freeside.git] / FS / FS / cust_bill_event.pm
index 7b98139..4496bed 100644 (file)
@@ -3,10 +3,11 @@ package FS::cust_bill_event;
 use strict;
 use vars qw( @ISA $DEBUG );
 use FS::Record qw( qsearch qsearchs );
+use FS::cust_main_Mixin;
 use FS::cust_bill;
 use FS::part_bill_event;
 
-@ISA = qw(FS::Record);
+@ISA = qw(FS::cust_main_Mixin FS::Record);
 
 $DEBUG = 0;
 
@@ -70,6 +71,13 @@ points to.  You can ask the object for a copy with the I<hash> method.
 
 sub table { 'cust_bill_event'; }
 
+sub cust_linked { $_[0]->cust_main_custnum; } 
+sub cust_unlinked_msg {
+  my $self = shift;
+  "WARNING: can't find cust_main.custnum ". $self->custnum.
+  ' (cust_bill.invnum '. $self->invnum. ')';
+}
+
 =item insert
 
 Adds this record to the database.  If there is an error, returns the error,
@@ -118,12 +126,13 @@ sub check {
     || $self->ut_textn('statustext')
   ;
 
+  return "Unknown eventpart ". $self->eventpart
+    unless my $part_bill_event =
+      qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
+
   return "Unknown invnum ". $self->invnum
     unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
 
-  return "Unknown eventpart ". $self->eventpart
-    unless qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
-
   $self->SUPER::check;
 }
 
@@ -165,6 +174,21 @@ sub retry {
   $self->replace($old);
 }
 
+=item retryable
+
+Changes the statustext of this event to B<retriable>, rendering it 
+retriable (should retry be called).
+
+=cut
+
+sub retriable {
+  my $self = shift;
+  return '' unless $self->status eq 'done';
+  my $old = ref($self)->new( { $self->hash } );
+  $self->statustext('retriable');
+  $self->replace($old);
+}
+
 =back
 
 =head1 SUBROUTINES