1 package FS::cust_bill_event;
4 use vars qw( @ISA $DEBUG );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cust_main_Mixin;
8 use FS::part_bill_event;
10 @ISA = qw(FS::cust_main_Mixin FS::Record);
16 FS::cust_bill_event - Object methods for cust_bill_event records
20 use FS::cust_bill_event;
22 $record = new FS::cust_bill_event \%hash;
23 $record = new FS::cust_bill_event { 'column' => 'value' };
25 $error = $record->insert;
27 $error = $new_record->replace($old_record);
29 $error = $record->delete;
31 $error = $record->check;
35 An FS::cust_bill_event object represents an complete invoice event.
36 FS::cust_bill_event inherits from FS::Record. The following fields are
41 =item eventnum - primary key
43 =item invnum - invoice (see L<FS::cust_bill>)
45 =item eventpart - event definition (see L<FS::part_bill_event>)
47 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
48 L<Time::Local> and L<Date::Parse> for conversion functions.
50 =item status - event status: B<done> or B<failed>
52 =item statustext - additional status detail (i.e. error message)
62 Creates a new completed invoice event. To add the compelted invoice event to
63 the database, see L<"insert">.
65 Note that this stores the hash reference, not a distinct copy of the hash it
66 points to. You can ask the object for a copy with the I<hash> method.
70 # the new method can be inherited from FS::Record, if a table method is defined
72 sub table { 'cust_bill_event'; }
74 sub cust_linked { $_[0]->cust_main_custnum; }
75 sub cust_unlinked_msg {
77 "WARNING: can't find cust_main.custnum ". $self->custnum.
78 ' (cust_bill.invnum '. $self->invnum. ')';
83 Adds this record to the database. If there is an error, returns the error,
84 otherwise returns false.
88 # the insert method can be inherited from FS::Record
92 Delete this record from the database.
96 # the delete method can be inherited from FS::Record
98 =item replace OLD_RECORD
100 Replaces the OLD_RECORD with this one in the database. If there is an error,
101 returns the error, otherwise returns false.
105 # the replace method can be inherited from FS::Record
109 Checks all fields to make sure this is a valid completed invoice event. If
110 there is an error, returns the error, otherwise returns false. Called by the
111 insert and replace methods.
115 # the check method should currently be supplied - FS::Record contains some
116 # data checking routines
121 my $error = $self->ut_numbern('eventnum')
122 || $self->ut_number('invnum')
123 || $self->ut_number('eventpart')
124 || $self->ut_number('_date')
125 || $self->ut_enum('status', [qw( done failed )])
126 || $self->ut_textn('statustext')
129 return "Unknown eventpart ". $self->eventpart
130 unless my $part_bill_event =
131 qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
133 return "Unknown invnum ". $self->invnum
134 unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
139 =item part_bill_event
141 Returns the invoice event definition (see L<FS::part_bill_event>) for this
142 completed invoice event.
146 sub part_bill_event {
148 qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } );
153 Returns the invoice (see L<FS::cust_bill>) for this completed invoice event.
159 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
164 Changes the status of this event from B<done> to B<failed>, allowing it to be
171 return '' unless $self->status eq 'done';
172 my $old = ref($self)->new( { $self->hash } );
173 $self->status('failed');
174 $self->replace($old);
179 Changes the statustext of this event to B<retriable>, rendering it
180 retriable (should retry be called).
186 return '' unless $self->status eq 'done';
187 my $old = ref($self)->new( { $self->hash } );
188 $self->statustext('retriable');
189 $self->replace($old);
202 sub process_reprint {
203 process_re_X('print', @_);
210 sub process_reemail {
211 process_re_X('email', @_);
219 process_re_X('fax', @_);
222 use Storable qw(thaw);
226 my( $method, $job ) = ( shift, shift );
228 my $param = thaw(decode_base64(shift));
229 warn Dumper($param) if $DEBUG;
233 $param->{'beginning'},
242 my($method, $beginning, $ending, $failed, $job) = @_;
244 my $where = " WHERE plan LIKE 'send%'".
245 " AND cust_bill_event._date >= $beginning".
246 " AND cust_bill_event._date <= $ending";
247 $where .= " AND statustext != '' AND statustext IS NOT NULL"
250 my $from = 'LEFT JOIN part_bill_event USING ( eventpart )';
252 my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from );
254 my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
255 foreach my $cust_bill_event ( @cust_bill_event ) {
257 $cust_bill_event->cust_bill->$method(
258 $cust_bill_event->part_bill_event->templatename
261 if ( $job ) { #progressbar foo
263 if ( time - $min_sec > $last ) {
264 my $error = $job->update_statustext(
265 int( 100 * $num / scalar(@cust_bill_event) )
267 die $error if $error;
274 #this doesn't work, but it would be nice
275 #if ( $job ) { #progressbar foo
276 # my $error = $job->update_statustext(
277 # scalar(@cust_bill_event). " invoices re-${method}ed"
279 # die $error if $error;
288 Far too early in the morning.
292 L<FS::part_bill_event>, L<FS::cust_bill>, L<FS::Record>, schema.html from the