From: Ivan Kohler Date: Mon, 16 Feb 2015 06:55:17 +0000 (-0800) Subject: remove ancient invoice events X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=32693d38eeb1144fbdf255d65f60810122286b9c remove ancient invoice events --- diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 37e3ad243..81671ffad 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -180,7 +180,6 @@ if ( -e $addl_handler_use_file ) { use FS::cust_pay_refund; use FS::cust_svc; use FS::nas; - use FS::part_bill_event; use FS::part_event; use FS::part_event_condition; use FS::part_pkg; diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 54a468067..73b2a7098 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -794,58 +794,6 @@ sub tables_hashref { ], }, - #old "invoice" events, deprecated - 'cust_bill_event' => { - 'columns' => [ - 'eventnum', 'serial', '', '', '', '', - 'invnum', 'int', '', '', '', '', - 'eventpart', 'int', '', '', '', '', - '_date', @date_type, '', '', - 'status', 'varchar', '', $char_d, '', '', - 'statustext', 'text', 'NULL', '', '', '', - ], - 'primary_key' => 'eventnum', - #no... there are retries now #'unique' => [ [ 'eventpart', 'invnum' ] ], - 'unique' => [], - 'index' => [ ['invnum'], ['status'], ['eventpart'], - ['statustext'], ['_date'], - ], - 'foreign_keys' => [ - { columns => [ 'invnum' ], - table => 'cust_bill', - }, - { columns => [ 'eventpart' ], - table => 'part_bill_event', - }, - ], - }, - - #old "invoice" events, deprecated - 'part_bill_event' => { - 'columns' => [ - 'eventpart', 'serial', '', '', '', '', - 'freq', 'varchar', 'NULL', $char_d, '', '', - 'payby', 'char', '', 4, '', '', - 'event', 'varchar', '', $char_d, '', '', - 'eventcode', @perl_type, '', '', - 'seconds', 'int', 'NULL', '', '', '', - 'weight', 'int', '', '', '', '', - 'plan', 'varchar', 'NULL', $char_d, '', '', - 'plandata', 'text', 'NULL', '', '', '', - 'reason', 'int', 'NULL', '', '', '', - 'disabled', 'char', 'NULL', 1, '', '', - ], - 'primary_key' => 'eventpart', - 'unique' => [], - 'index' => [ ['payby'], ['disabled'], ], - 'foreign_keys' => [ - { columns => [ 'reason' ], - table => 'reason', - references => [ 'reasonnum' ], - }, - ], - }, - 'part_event' => { 'columns' => [ 'eventpart', 'serial', '', '', '', '', diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 068d0d1d3..26f10da06 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -26,11 +26,9 @@ use FS::cust_pay; use FS::cust_pkg; use FS::cust_credit_bill; use FS::pay_batch; -use FS::cust_bill_event; use FS::cust_event; use FS::part_pkg; use FS::cust_bill_pay; -use FS::part_bill_event; use FS::payby; use FS::bill_batch; use FS::cust_bill_batch; @@ -285,7 +283,6 @@ sub delete { my $dbh = dbh; foreach my $table (qw( - cust_bill_event cust_event cust_credit_bill cust_bill_pay @@ -565,32 +562,6 @@ sub open_cust_bill_pkg { @open; } -=item cust_bill_event - -Returns the completed invoice events (deprecated, old-style events - see L) for this invoice. - -=cut - -sub cust_bill_event { - my $self = shift; - qsearch( 'cust_bill_event', { 'invnum' => $self->invnum } ); -} - -=item num_cust_bill_event - -Returns the number of completed invoice events (deprecated, old-style events - see L) for this invoice. - -=cut - -sub num_cust_bill_event { - my $self = shift; - my $sql = - "SELECT COUNT(*) FROM cust_bill_event WHERE invnum = ?"; - my $sth = dbh->prepare($sql) or die dbh->errstr. " preparing $sql"; - $sth->execute($self->invnum) or die $sth->errstr. " executing $sql"; - $sth->fetchrow_arrayref->[0]; -} - =item cust_event Returns the new-style customer billing events (see L) for this invoice. diff --git a/FS/FS/cust_bill_event.pm b/FS/FS/cust_bill_event.pm deleted file mode 100644 index adaa13eee..000000000 --- a/FS/FS/cust_bill_event.pm +++ /dev/null @@ -1,378 +0,0 @@ -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::cust_main_Mixin FS::Record); - -$DEBUG = 0; - -=head1 NAME - -FS::cust_bill_event - Object methods for cust_bill_event records - -=head1 SYNOPSIS - - use FS::cust_bill_event; - - $record = new FS::cust_bill_event \%hash; - $record = new FS::cust_bill_event { 'column' => 'value' }; - - $error = $record->insert; - - $error = $new_record->replace($old_record); - - $error = $record->delete; - - $error = $record->check; - -=head1 DESCRIPTION - -An FS::cust_bill_event object represents an complete invoice event. -FS::cust_bill_event inherits from FS::Record. The following fields are -currently supported: - -=over 4 - -=item eventnum - -Primary key - -=item invnum - -Invoice (see L) - -=item eventpart - -Event definition (see L) - -=item _date - -Specified as a UNIX timestamp; see L. Also see -L and L for conversion functions. - -=item status - -Event status: B or B - -=item statustext - -Additional status detail (i.e. error message) - -=back - -=head1 METHODS - -=over 4 - -=item new HASHREF - -Creates a new completed invoice event. To add the compelted invoice event to -the database, see L<"insert">. - -Note that this stores the hash reference, not a distinct copy of the hash it -points to. You can ask the object for a copy with the I method. - -=cut - -# the new method can be inherited from FS::Record, if a table method is defined - -sub table { 'cust_bill_event'; } - -sub cust_linked { $_[0]->cust_main_custnum || $_[0]->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, -otherwise returns false. - -=cut - -# the insert method can be inherited from FS::Record - -=item delete - -Delete this record from the database. - -=cut - -# the delete method can be inherited from FS::Record - -=item replace OLD_RECORD - -Replaces the OLD_RECORD with this one in the database. If there is an error, -returns the error, otherwise returns false. - -=cut - -# the replace method can be inherited from FS::Record - -=item check - -Checks all fields to make sure this is a valid completed invoice event. If -there is an error, returns the error, otherwise returns false. Called by the -insert and replace methods. - -=cut - -# the check method should currently be supplied - FS::Record contains some -# data checking routines - -sub check { - my $self = shift; - - my $error = $self->ut_numbern('eventnum') - || $self->ut_number('invnum') - || $self->ut_number('eventpart') - || $self->ut_number('_date') - || $self->ut_enum('status', [qw( done failed )]) - || $self->ut_anything('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 } ); - - $self->SUPER::check; -} - -=item part_bill_event - -Returns the invoice event definition (see L) for this -completed invoice event. - -=cut - -sub part_bill_event { - my $self = shift; - qsearchs( 'part_bill_event', { 'eventpart' => $self->eventpart } ); -} - -=item cust_bill - -Returns the invoice (see L) 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 to B, 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); -} - -=item retryable - -Changes the statustext of this event to B, 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); -} - -=item search_sql_where HASHREF - -Class method which returns an SQL WHERE fragment to search for parameters -specified in HASHREF. Valid parameters are - -=over 4 - -=item agentnum - -=item beginning - -An epoch date setting a lower bound for _date values - -=item ending - -An epoch date setting a upper bound for _date values - -=item failed - -Limits the search to failed events if true - -=item payby - -Requires that the search be JOIN'd to part_bill_event # Bug? - -=item invnum - -=item currentuser - -Specifies the user for agent virtualization - -=back - -=cut - -sub search_sql_where { - my ($class, $params) = @_; - my @search = (); - - push @search, "agentnum = ". $params->{agentnum} if $params->{agentnum}; - - push @search, "cust_bill_event._date >= ". $params->{beginning} - if $params->{beginning}; - push @search, "cust_bill_event._date <= ". $params->{ending} - if $params->{ending}; - - push @search, "statustext != ''", - "statustext IS NOT NULL", - "statustext != 'N/A'" - if $params->{failed}; - - push @search, "part_bill_event.payby = '". $params->{payby}. "'" - if $params->{payby}; - - push @search, "cust_bill_event.invnum = '". $params->{invnum}. "'" - if $params->{invnum}; - - my $currentuser = $params->{currentuser} || $params->{CurrentUser}; - if ($currentuser) { - my $access_user = qsearchs('access_user', { username => $currentuser }); - if ($access_user) { - push @search, $access_user->agentnums_sql; - }else{ - push @search, "1=0"; - } - }else{ - push @search, $FS::CurrentUser::CurrentUser->agentnums_sql; - } - - join(' AND ', @search ); - -} - -=back - -=head1 SUBROUTINES - -=over 4 - -=item reprint - -=cut - -sub process_reprint { - process_re_X('print', @_); -} - -=item reemail - -=cut - -sub process_reemail { - process_re_X('email', @_); -} - -=item refax - -=cut - -sub process_refax { - process_re_X('fax', @_); -} - -use Data::Dumper; -sub process_re_X { - my( $method, $job ) = ( shift, shift ); - - my $param = shift; - warn Dumper($param) if $DEBUG; - - re_X( - $method, - $param, - $job, - ); - -} - -sub re_X { - my($method, $param, $job) = @_; - - my $where = FS::cust_bill_event->search_sql_where($param); - $where = " WHERE plan LIKE 'send%'". ( $where ? " AND $where" : "" ); - - my $from = 'LEFT JOIN part_bill_event USING ( eventpart )'. - 'LEFT JOIN cust_bill USING ( invnum )'. - 'LEFT JOIN cust_main USING ( custnum )'; - - my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from ); - - my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo - foreach my $cust_bill_event ( @cust_bill_event ) { - - $cust_bill_event->cust_bill->$method( - $cust_bill_event->part_bill_event->templatename - ); - - if ( $job ) { #progressbar foo - $num++; - if ( time - $min_sec > $last ) { - my $error = $job->update_statustext( - int( 100 * $num / scalar(@cust_bill_event) ) - ); - die $error if $error; - $last = time; - } - } - - } - - #this doesn't work, but it would be nice - #if ( $job ) { #progressbar foo - # my $error = $job->update_statustext( - # scalar(@cust_bill_event). " invoices re-${method}ed" - # ); - # die $error if $error; - #} - -} - -=back - -=head1 BUGS - -Far too early in the morning. - -=head1 SEE ALSO - -L, L, L, schema.html from the -base documentation. - -=cut - -1; - diff --git a/FS/FS/part_bill_event.pm b/FS/FS/part_bill_event.pm deleted file mode 100644 index 4e7aa52f2..000000000 --- a/FS/FS/part_bill_event.pm +++ /dev/null @@ -1,368 +0,0 @@ -package FS::part_bill_event; - -use strict; -use vars qw( @ISA $DEBUG @EXPORT_OK ); -use Carp qw(cluck confess); -use FS::Record qw( dbh qsearch qsearchs ); -use FS::Conf; -use FS::cust_main; -use FS::cust_bill; - -@ISA = qw( FS::Record ); -@EXPORT_OK = qw( due_events ); -$DEBUG = 0; - -=head1 NAME - -FS::part_bill_event - Object methods for part_bill_event records - -=head1 SYNOPSIS - - use FS::part_bill_event; - - $record = new FS::part_bill_event \%hash; - $record = new FS::part_bill_event { 'column' => 'value' }; - - $error = $record->insert; - - $error = $new_record->replace($old_record); - - $error = $record->delete; - - $error = $record->check; - - $error = $record->do_event( $direct_object ); - - @events = due_events ( { 'record' => $event_triggering_record, - 'payby' => $payby, - 'event_time => $_date, - 'extra_sql => $extra } ); - -=head1 DESCRIPTION - -An FS::part_bill_event object represents a deprecated, old-style invoice event -definition - a callback which is triggered when an invoice is a certain amount -of time overdue. FS::part_bill_event inherits from FS::Record. The following -fields are currently supported: - -=over 4 - -=item eventpart - primary key - -=item payby - CARD, DCRD, CHEK, DCHK, LECB, BILL, or COMP - -=item event - event name - -=item eventcode - event action - -=item seconds - how long after the invoice date events of this type are triggered - -=item weight - ordering for events with identical seconds - -=item plan - eventcode plan - -=item plandata - additional plan data - -=item reason - an associated reason for this event to fire - -=item disabled - Disabled flag, empty or `Y' - -=back - -=head1 NOTE - -Old-style invoice events are only useful for legacy migrations - if you are -looking for current events see L. - -=head1 METHODS - -=over 4 - -=item new HASHREF - -Creates a new invoice event definition. To add the invoice event definition to -the database, see L<"insert">. - -Note that this stores the hash reference, not a distinct copy of the hash it -points to. You can ask the object for a copy with the I method. - -=cut - -# the new method can be inherited from FS::Record, if a table method is defined - -sub table { 'part_bill_event'; } - -=item insert - -Adds this record to the database. If there is an error, returns the error, -otherwise returns false. - -=cut - -# the insert method can be inherited from FS::Record - -=item delete - -Delete this record from the database. - -=cut - -# the delete method can be inherited from FS::Record - -=item replace OLD_RECORD - -Replaces the OLD_RECORD with this one in the database. If there is an error, -returns the error, otherwise returns false. - -=cut - -# the replace method can be inherited from FS::Record - -=item check - -Checks all fields to make sure this is a valid invoice event definition. If -there is an error, returns the error, otherwise returns false. Called by the -insert and replace methods. - -=cut - -# the check method should currently be supplied - FS::Record contains some -# data checking routines - -sub check { - my $self = shift; - - $self->weight(0) unless $self->weight; - - my $conf = new FS::Conf; - if ( $conf->exists('safe-part_bill_event') ) { - my $error = $self->ut_anything('eventcode'); - return $error if $error; - - my $c = $self->eventcode; - - #yay, these regexen will go away with the event refactor - - $c =~ /^\s*\$cust_main\->(suspend|cancel|invoicing_list_addpost|bill|collect)\(\);\s*("";)?\s*$/ - - or $c =~ /^\s*\$cust_bill\->(comp|realtime_(card|ach|lec)|batch_card|send)\((%options)*\);\s*$/ - - or $c =~ /^\s*\$cust_bill\->send(_if_newest)?\(\'[\w\-\s]+\'\s*(,\s*(\d+|\[\s*\d+(,\s*\d+)*\s*\])\s*,\s*'[\w\@\.\-\+]*'\s*)?\);\s*$/ - -# or $c =~ /^\s*\$cust_main\->apply_payments; \$cust_main->apply_credits; "";\s*$/ - or $c =~ /^\s*\$cust_main\->apply_payments_and_credits; "";\s*$/ - - or $c =~ /^\s*\$cust_main\->charge\( \s*\d*\.?\d*\s*,\s*\'[\w \!\@\#\$\%\&\(\)\-\+\;\:\"\,\.\?\/]*\'\s*\);\s*$/ - - or $c =~ /^\s*\$cust_main\->suspend_(if|unless)_pkgpart\([\d\,\s]*\);\s*$/ - - or $c =~ /^\s*\$cust_bill\->cust_suspend_if_balance_over\([\d\.\s]*\);\s*$/ - - or do { - #log - return "illegal eventcode: $c"; - }; - - } - - my $error = $self->ut_numbern('eventpart') - || $self->ut_enum('payby', [qw( CARD DCLN DCRD CHEK DCHK LECB BILL COMP )] ) - || $self->ut_text('event') - || $self->ut_anything('eventcode') - || $self->ut_number('seconds') - || $self->ut_enum('disabled', [ '', 'Y' ] ) - || $self->ut_number('weight') - || $self->ut_textn('plan') - || $self->ut_anything('plandata') - || $self->ut_numbern('reason') - ; - #|| $self->ut_snumber('seconds') - return $error if $error; - - #quelle kludge - if ( $self->plandata =~ /^(agent_)?templatename\s+(.*)$/m ) { - my $name= $2; - - foreach my $file (qw( template - latex latexnotes latexreturnaddress latexfooter - latexsmallfooter - html htmlnotes htmlreturnaddress htmlfooter - )) - { - unless ( $conf->exists("invoice_${file}_$name") ) { - $conf->set( - "invoice_${file}_$name" => - join("\n", $conf->config("invoice_$file") ) - ); - } - } - } - - if ($self->reason){ - my $reasonr = qsearchs('reason', {'reasonnum' => $self->reason}); - return "Unknown reason" unless $reasonr; - } - - $self->SUPER::check; -} - -=item templatename - -Returns the alternate invoice template name, if any, or false if there is -no alternate template for this invoice event. - -=cut - -sub templatename { - my $self = shift; - if ( $self->plan =~ /^send_(alternate|agent)$/ - && $self->plandata =~ /^(agent_)?templatename (.*)$/m - ) - { - $2; - } else { - ''; - } -} - -=item due_events - -Returns the list of events due, if any, or false if there is none. -Requires record and payby, but event_time and extra_sql are optional. - -=cut - -sub due_events { - my ($record, $payby, $event_time, $extra_sql) = @_; - - #cluck "DEPRECATED: FS::part_bill_event::due_events called on $record"; - confess "DEPRECATED: FS::part_bill_event::due_events called on $record"; - - my $interval = 0; - if ($record->_date){ - $event_time = time unless $event_time; - $interval = $event_time - $record->_date; - } - sort { $a->seconds <=> $b->seconds - || $a->weight <=> $b->weight - || $a->eventpart <=> $b->eventpart } - grep { ref($record) ne 'FS::cust_bill' || $_->eventcode !~ /honor_dundate/ - || $event_time > $record->cust_main->dundate - } - grep { $_->seconds <= ( $interval ) - && ! qsearch( 'cust_bill_event', { - 'invnum' => $record->get($record->dbdef_table->primary_key), - 'eventpart' => $_->eventpart, - 'status' => 'done', - } ) - } - qsearch( { - 'table' => 'part_bill_event', - 'hashref' => { 'payby' => $payby, - 'disabled' => '', }, - 'extra_sql' => $extra_sql, - } ); - - -} - -=item do_event - -Performs the event and returns any errors that occur. -Requires a record on which to perform the event. -Should only be performed inside a transaction. - -=cut - -sub do_event { - my ($self, $object, %options) = @_; - - #cluck "DEPRECATED: FS::part_bill_event::do_event called on $self"; - confess "DEPRECATED: FS::part_bill_event::do_event called on $self"; - - warn " calling event (". $self->eventcode. ") for " . $object->table . " " , - $object->get($object->dbdef_table->primary_key) . "\n" if $DEBUG > 1; - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - - # for "callback" -- heh - my $cust_main = $object->cust_main; - my $cust_bill; - if ($object->table eq 'cust_bill'){ - $cust_bill = $object; - } - my $cust_pay_batch; - if ($object->table eq 'cust_pay_batch'){ - $cust_pay_batch = $object; - } - - my $error; - { - local $SIG{__DIE__}; # don't want Mason __DIE__ handler active - $error = eval $self->eventcode; - } - - my $status = ''; - my $statustext = ''; - if ( $@ ) { - $status = 'failed'; - $statustext = $@; - } elsif ( $error ) { - $status = 'done'; - $statustext = $error; - } else { - $status = 'done'; - } - - #add cust_bill_event - my $cust_bill_event = new FS::cust_bill_event { -# 'invnum' => $object->get($object->dbdef_table->primary_key), - 'invnum' => $object->invnum, - 'eventpart' => $self->eventpart, - '_date' => time, - 'status' => $status, - 'statustext' => $statustext, - }; - $error = $cust_bill_event->insert; - if ( $error ) { - my $e = 'WARNING: Event run but database not updated - '. - 'error inserting cust_bill_event, invnum #'. $object->invnum . - ', eventpart '. $self->eventpart.": $error"; - warn $e; - return $e; - } - ''; -} - -=item reasontext - -Returns the text of any reason associated with this event. - -=cut - -sub reasontext { - my $self = shift; - my $r = qsearchs('reason', { 'reasonnum' => $self->reason }); - if ($r){ - $r->reason; - }else{ - ''; - } -} - -=back - -=head1 BUGS - -The whole "eventcode" idea is bunk. This should be refactored with subclasses -like part_pkg/ and part_export/ - -=head1 SEE ALSO - -L, L, L, schema.html from the -base documentation. - -=cut - -1; - diff --git a/FS/MANIFEST b/FS/MANIFEST index b7d347b98..0542dfde2 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -86,7 +86,6 @@ FS/cust_main_Mixin.pm FS/cust_main_county.pm FS/cust_main_invoice.pm FS/cust_pay.pm -FS/cust_bill_event.pm FS/cust_bill_pay.pm FS/cust_pay_batch.pm FS/cust_pay_refund.pm @@ -110,7 +109,6 @@ FS/h_svc_domain.pm FS/h_svc_external.pm FS/h_svc_forward.pm FS/h_svc_www.pm -FS/part_bill_event.pm FS/payinfo_Mixin.pm FS/export_svc.pm FS/export_device.pm @@ -246,7 +244,6 @@ t/UID.t t/Msgcat.t t/SearchCache.t t/cust_bill.t -t/cust_bill_event.t t/cust_bill_pay.t t/cust_bill_pkg.t t/cust_bill_pkg_detail.t @@ -280,7 +277,6 @@ t/cust_tax_exempt.t t/cust_tax_exempt_pkg.t t/domain_record.t t/nas.t -t/part_bill_event.t t/export_svc.t t/export_device.t t/part_export.t diff --git a/FS/t/cust_bill_event.t b/FS/t/cust_bill_event.t deleted file mode 100644 index 0e2ca3e24..000000000 --- a/FS/t/cust_bill_event.t +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { $| = 1; print "1..1\n" } -END {print "not ok 1\n" unless $loaded;} -use FS::cust_bill_event; -$loaded=1; -print "ok 1\n"; diff --git a/FS/t/part_bill_event.t b/FS/t/part_bill_event.t deleted file mode 100644 index 5626a9f97..000000000 --- a/FS/t/part_bill_event.t +++ /dev/null @@ -1,5 +0,0 @@ -BEGIN { $| = 1; print "1..1\n" } -END {print "not ok 1\n" unless $loaded;} -use FS::part_bill_event; -$loaded=1; -print "ok 1\n";