X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=fd1ccd772996443108959052c2be4ee249af23db;hb=1290c097176adcd62d48b1250233d53adb4b50a5;hp=cf5bd33143625d0a4ae359c3b3625f80b99da583;hpb=fc0715ded1a4c1ace11f1ad1df7600f726206afc;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index cf5bd3314..fd1ccd772 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -26,6 +26,7 @@ use FS::queue; use FS::part_pkg; use FS::part_bill_event; use FS::cust_bill_event; +use FS::Msgcat qw(gettext); @ISA = qw( FS::Record ); @@ -99,7 +100,7 @@ FS::Record. The following fields are currently supported: =item agentnum - agent (see L) -=item refnum - referral (see L) +=item refnum - Advertising source (see L) =item first - name @@ -531,14 +532,14 @@ sub check { || $self->ut_numbern('referral_custnum') ; #barf. need message catalogs. i18n. etc. - $error .= "Please select a referral." + $error .= "Please select a advertising source." if $error =~ /^Illegal or empty \(numeric\) refnum: /; return $error if $error; return "Unknown agent" unless qsearchs( 'agent', { 'agentnum' => $self->agentnum } ); - return "Unknown referral" + return "Unknown refnum" unless qsearchs( 'part_referral', { 'refnum' => $self->refnum } ); return "Unknown referring custnum ". $self->referral_custnum @@ -586,8 +587,9 @@ sub check { ); if ( defined $self->dbdef_table->column('ship_last') ) { - if ( grep { $self->getfield($_) ne $self->getfield("ship_$_") } @addfields - && grep { $self->getfield("ship_$_") ne '' } @addfields + if ( scalar ( grep { $self->getfield($_) ne $self->getfield("ship_$_") } + @addfields ) + && scalar ( grep { $self->getfield("ship_$_") ne '' } @addfields ) ) { my $error = @@ -642,12 +644,13 @@ sub check { my $payinfo = $self->payinfo; $payinfo =~ s/\D//g; $payinfo =~ /^(\d{13,16})$/ - or return "Illegal credit card number: ". $self->payinfo; + or return gettext('invalid_catd'); # . ": ". $self->payinfo; $payinfo = $1; $self->payinfo($payinfo); validate($payinfo) - or return "Illegal credit card number: ". $self->payinfo; - return "Unknown card type" if cardtype($self->payinfo) eq "Unknown"; + or return gettext('invalid_catd'); # . ": ". $self->payinfo; + return gettext('unknown_card_type') + if cardtype($self->payinfo) eq "Unknown"; } elsif ( $self->payby eq 'BILL' ) { @@ -689,7 +692,7 @@ sub check { $self->payname( $self->first. " ". $self->getfield('last') ); } else { $self->payname =~ /^([\w \,\.\-\']+)$/ - or return "Illegal billing name: ". $self->payname; + or return gettext('illegal_name'). " payname: ". $self->payname; $self->payname($1); } @@ -816,6 +819,17 @@ sub cancel { grep { $_->cancel } $self->ncancelled_pkgs; } +=item agent + +Returns the agent (see L) for this customer. + +=cut + +sub agent { + my $self = shift; + qsearchs( 'agent', { 'agent' => $self->agentnum } ); +} + =item bill OPTIONS Generates invoices (see L) for this customer. Usually used in @@ -1101,7 +1115,7 @@ sub collect { my $dbh = dbh; my $balance = $self->balance; - warn "collect: balance $balance" if $Debug; + warn "collect customer". $self->custnum. ": balance $balance" if $Debug; unless ( $balance > 0 ) { #redundant????? $dbh->rollback if $oldAutoCommit; #hmm return ''; @@ -1134,45 +1148,57 @@ sub collect { grep { $_->seconds <= ( $invoice_time - $cust_bill->_date ) && ! qsearchs( 'cust_bill_event', { 'invnum' => $cust_bill->invnum, - 'eventpart' => $_->eventpart } ) + 'eventpart' => $_->eventpart, + 'status' => 'done', + } ) } qsearch('part_bill_event', { 'payby' => $self->payby, 'disabled' => '', } ) ) { - #run callback - my $cust_main = $self; #for callback - my $error = eval $part_bill_event->eventcode; - if ( $error ) { + last unless $cust_bill->owed > 0; #don't run subsequent events if owed=0 - warn "Error running invoice event (". $part_bill_event->eventcode. - "): $error"; + warn "calling invoice event (". $part_bill_event->eventcode. ")\n" + if $Debug; + my $cust_main = $self; #for callback + my $error = eval $part_bill_event->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' => $cust_bill->invnum, - 'eventpart' => $part_bill_event->eventpart, - '_date' => $invoice_time, - }; - $cust_bill_event->insert; - if ( $error ) { - #$dbh->rollback if $oldAutoCommit; - #return "error: $error"; - - # gah, even with transactions. - $dbh->commit if $oldAutoCommit; #well. - my $e = 'WARNING: Event run but database not updated - '. - 'error inserting cust_bill_event, invnum #'. $cust_bill->invnum. - ', eventpart '. $part_bill_event->eventpart. - ": $error"; - warn $e; - return $e; - } - + #add cust_bill_event + my $cust_bill_event = new FS::cust_bill_event { + 'invnum' => $cust_bill->invnum, + 'eventpart' => $part_bill_event->eventpart, + '_date' => $invoice_time, + 'status' => $status, + 'statustext' => $statustext, + }; + $error = $cust_bill_event->insert; + if ( $error ) { + #$dbh->rollback if $oldAutoCommit; + #return "error: $error"; + + # gah, even with transactions. + $dbh->commit if $oldAutoCommit; #well. + my $e = 'WARNING: Event run but database not updated - '. + 'error inserting cust_bill_event, invnum #'. $cust_bill->invnum. + ', eventpart '. $part_bill_event->eventpart. + ": $error"; + warn $e; + return $e; } + } }