X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_event.pm;h=b5436d0a4d4d5d6b6b8f17c19045268fc06a389b;hp=52b5911dc0911731d92af290d009ec739e64cc2b;hb=7516e3da0f17eeecba27219ef96a8b5f46af2083;hpb=18f1fb3831bd99520f02a5ebe717344f71dc866f diff --git a/FS/FS/cust_event.pm b/FS/FS/cust_event.pm index 52b5911dc..b5436d0a4 100644 --- a/FS/FS/cust_event.pm +++ b/FS/FS/cust_event.pm @@ -1,15 +1,15 @@ package FS::cust_event; +use base qw( FS::cust_main_Mixin FS::Record ); use strict; -use base qw( FS::cust_main_Mixin FS::Record ); -use vars qw( @ISA $DEBUG $me ); +use vars qw( $DEBUG $me ); use Carp qw( croak confess ); use FS::Record qw( qsearch qsearchs dbdef ); -use FS::part_event; #for cust_X use FS::cust_main; use FS::cust_pkg; use FS::cust_bill; +use FS::svc_acct; $DEBUG = 0; $me = '[FS::cust_event]'; @@ -73,7 +73,7 @@ points to. You can ask the object for a copy with the I method. sub table { 'cust_event'; } -sub cust_linked { $_[0]->cust_main_custnum; } +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; @@ -138,7 +138,7 @@ sub check { $dbdef_eventtable->primary_key ) || $self->ut_number('_date') - || $self->ut_enum('status', [qw( new locked done failed )]) + || $self->ut_enum('status', [qw( new locked done failed initial)]) || $self->ut_anything('statustext') ; return $error if $error; @@ -150,13 +150,6 @@ sub check { Returns the event definition (see L) for this completed event. -=cut - -sub part_event { - my $self = shift; - qsearchs( 'part_event', { 'eventpart' => $self->eventpart } ); -} - =item cust_X Returns the customer, package, invoice or batched payment (see @@ -190,6 +183,11 @@ sub test_conditions { my $object = $self->cust_X; my @conditions = $part_event->part_event_condition; $opt{'cust_event'} = $self; + $opt{'time'} = $self->_date + or die "test_conditions called without cust_event._date\n"; + # this MUST be set, or all hell breaks loose in event conditions. + # it MUST be in the same time as in the cust_event object, or + # future time-dependent events will trigger incorrectly. #no unsatisfied conditions #! grep ! $_->condition( $object, %opt ), @conditions; @@ -212,6 +210,8 @@ Runs the event action. sub do_event { my $self = shift; + my %opt = @_; # currently only 'time' + my $time = $opt{'time'} || time; my $part_event = $self->part_event; @@ -222,9 +222,6 @@ sub do_event { " (". $part_event->action. ") $for\n" if $DEBUG; - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $error; { local $SIG{__DIE__}; # don't want Mason __DIE__ handler active @@ -245,7 +242,7 @@ sub do_event { } #replace or add myself - $self->_date(time); + $self->_date($time); $self->status($status); $self->statustext($statustext); @@ -294,7 +291,7 @@ sub retriable { $self->replace($old); } -=item join_cust_sql +=item join_sql =cut @@ -305,9 +302,13 @@ sub join_sql { JOIN part_event USING ( eventpart ) LEFT JOIN cust_bill ON ( eventtable = 'cust_bill' AND tablenum = invnum ) LEFT JOIN cust_pkg ON ( eventtable = 'cust_pkg' AND tablenum = pkgnum ) + + LEFT JOIN cust_svc ON ( eventtable = 'svc_acct' AND tablenum = svcnum ) + LEFT JOIN cust_pkg AS cust_pkg_for_svc ON ( cust_svc.pkgnum = cust_pkg_for_svc.pkgnum ) LEFT JOIN cust_main ON ( ( eventtable = 'cust_main' AND tablenum = cust_main.custnum ) OR ( eventtable = 'cust_bill' AND cust_bill.custnum = cust_main.custnum ) OR ( eventtable = 'cust_pkg' AND cust_pkg.custnum = cust_main.custnum ) + OR ( eventtable = 'svc_acct' AND cust_pkg_for_svc.custnum = cust_main.custnum ) ) "; @@ -328,6 +329,8 @@ specified in HASHREF. Valid parameters are =item pkgnum +=item svcnum + =item failed =item beginning @@ -390,6 +393,11 @@ sub search_sql_where { "tablenum = '$1'"; } + if ( $param->{'svcnum'} =~ /^(\d+)$/ ) { + push @search, "part_event.eventtable = 'svc_acct'", + "tablenum = '$1'"; + } + my $where = 'WHERE '. join(' AND ', @search ); join(' AND ', @search ); @@ -426,13 +434,9 @@ sub process_refax { process_re_X('fax', @_); } -use Storable qw(thaw); use Data::Dumper; -use MIME::Base64; sub process_re_X { - my( $method, $job ) = ( shift, shift ); - - my $param = thaw(decode_base64(shift)); + my( $method, $job, $param ) = @_; warn Dumper($param) if $DEBUG; re_X( @@ -471,9 +475,15 @@ sub re_X { my $cust_X = $cust_event->cust_X; # cust_bill next unless $cust_X->can($method); - $cust_X->$method( $cust_event->part_event->templatename - || $cust_X->agent_template - ); + my $part_event = $cust_event->part_event; + my $template = $part_event->templatename + || $cust_X->agent_template; + my $modenum = $part_event->option('modenum') || ''; + my $invoice_from = $part_event->option('agent_invoice_from') || ''; + $cust_X->set('mode' => $modenum); + $cust_X->$method( { template => $template, + modenum => $modenum, + invoice_from => $invoice_from } ); if ( $job ) { #progressbar foo $num++;