1 package FS::cust_bill_event;
4 use vars qw( @ISA $DEBUG );
5 use FS::Record qw( qsearch qsearchs );
7 use FS::part_bill_event;
15 FS::cust_bill_event - Object methods for cust_bill_event records
19 use FS::cust_bill_event;
21 $record = new FS::cust_bill_event \%hash;
22 $record = new FS::cust_bill_event { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::cust_bill_event object represents an complete invoice event.
35 FS::cust_bill_event inherits from FS::Record. The following fields are
40 =item eventnum - primary key
42 =item invnum - invoice (see L<FS::cust_bill>)
44 =item eventpart - event definition (see L<FS::part_bill_event>)
46 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">. Also see
47 L<Time::Local> and L<Date::Parse> for conversion functions.
49 =item status - event status: B<done> or B<failed>
51 =item statustext - additional status detail (i.e. error message)
61 Creates a new completed invoice event. To add the compelted invoice event to
62 the database, see L<"insert">.
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to. You can ask the object for a copy with the I<hash> method.
69 # the new method can be inherited from FS::Record, if a table method is defined
71 sub table { 'cust_bill_event'; }
75 Adds this record to the database. If there is an error, returns the error,
76 otherwise returns false.
80 # the insert method can be inherited from FS::Record
84 Delete this record from the database.
88 # the delete method can be inherited from FS::Record
90 =item replace OLD_RECORD
92 Replaces the OLD_RECORD with this one in the database. If there is an error,
93 returns the error, otherwise returns false.
97 # the replace method can be inherited from FS::Record
101 Checks all fields to make sure this is a valid completed invoice event. If
102 there is an error, returns the error, otherwise returns false. Called by the
103 insert and replace methods.
107 # the check method should currently be supplied - FS::Record contains some
108 # data checking routines
113 my $error = $self->ut_numbern('eventnum')
114 || $self->ut_number('invnum')
115 || $self->ut_number('eventpart')
116 || $self->ut_number('_date')
117 || $self->ut_enum('status', [qw( done failed )])
118 || $self->ut_textn('statustext')
121 return "Unknown invnum ". $self->invnum
122 unless qsearchs( 'cust_bill' ,{ 'invnum' => $self->invnum } );
124 return "Unknown eventpart ". $self->eventpart
125 unless qsearchs( 'part_bill_event' ,{ 'eventpart' => $self->eventpart } );
130 =item part_bill_event
132 Returns the invoice event definition (see L<FS::part_bill_event>) for this
133 completed invoice event.
137 sub part_bill_event {
139 qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } );
144 Returns the invoice (see L<FS::cust_bill>) for this completed invoice event.
150 qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
155 Changes the status of this event from B<done> to B<failed>, allowing it to be
162 return '' unless $self->status eq 'done';
163 my $old = ref($self)->new( { $self->hash } );
164 $self->status('failed');
165 $self->replace($old);
178 sub process_reprint {
179 process_re_X('print', @_);
186 sub process_reemail {
187 process_re_X('email', @_);
195 process_re_X('fax', @_);
198 use Storable qw(thaw);
202 my( $method, $job ) = ( shift, shift );
204 my $param = thaw(decode_base64(shift));
205 warn Dumper($param) if $DEBUG;
209 $param->{'beginning'},
218 my($method, $beginning, $ending, $failed, $job) = @_;
220 my $where = " WHERE plan LIKE 'send%'".
221 " AND cust_bill_event._date >= $beginning".
222 " AND cust_bill_event._date <= $ending";
223 $where .= " AND statustext != '' AND statustext IS NOT NULL"
226 my $from = 'LEFT JOIN part_bill_event USING ( eventpart )';
228 my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from );
230 my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
231 foreach my $cust_bill_event ( @cust_bill_event ) {
233 $cust_bill_event->cust_bill->$method(
234 $cust_bill_event->part_bill_event->templatename
237 if ( $job ) { #progressbar foo
239 if ( time - $min_sec > $last ) {
240 my $error = $job->update_statustext(
241 int( 100 * $num / scalar(@cust_bill_event) )
243 die $error if $error;
250 #this doesn't work, but it would be nice
251 #if ( $job ) { #progressbar foo
252 # my $error = $job->update_statustext(
253 # scalar(@cust_bill_event). " invoices re-${method}ed"
255 # die $error if $error;
264 Far too early in the morning.
268 L<FS::part_bill_event>, L<FS::cust_bill>, L<FS::Record>, schema.html from the