package FS::cust_main;
use strict;
-use vars qw( @ISA @EXPORT_OK $conf $DEBUG $import @encrypted_fields);
+use vars qw( @ISA @EXPORT_OK $DEBUG $conf @encrypted_fields
+ $import $skip_fuzzyfiles );
use vars qw( $realtime_bop_decline_quiet ); #ugh
use Safe;
use Carp;
use FS::Record qw( qsearchs qsearch dbdef );
use FS::Misc qw( send_email );
use FS::cust_pkg;
+use FS::cust_svc;
use FS::cust_bill;
use FS::cust_bill_pkg;
use FS::cust_pay;
#$DEBUG = 1;
$import = 0;
+$skip_fuzzyfiles = 0;
@encrypted_fields = ('payinfo', 'paycvv');
}
}
- $error = $self->queue_fuzzyfiles_update;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "updating fuzzy search cache: $error";
+ unless ( $import || $skip_fuzzyfiles ) {
+ $error = $self->queue_fuzzyfiles_update;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "updating fuzzy search cache: $error";
+ }
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
);
$cust_main->order_pkgs( \%hash, \'0', 'noexport'=>1 );
+Services can be new, in which case they are inserted, or existing unaudited
+services, in which case they are linked to the newly-created package.
+
Currently available options are: I<depend_jobnum> and I<noexport>.
If I<depend_jobnum> is set, all provisioning jobs will have a dependancy
return "inserting cust_pkg (transaction rolled back): $error";
}
foreach my $svc_something ( @{$cust_pkgs->{$cust_pkg}} ) {
- $svc_something->pkgnum( $cust_pkg->pkgnum );
- if ( $seconds && $$seconds && $svc_something->isa('FS::svc_acct') ) {
- $svc_something->seconds( $svc_something->seconds + $$seconds );
- $$seconds = 0;
+ if ( $svc_something->svcnum ) {
+ my $old_cust_svc = $svc_something->cust_svc;
+ my $new_cust_svc = new FS::cust_svc { $old_cust_svc->hash };
+ $new_cust_svc->pkgnum( $cust_pkg->pkgnum);
+ $error = $new_cust_svc->replace($old_cust_svc);
+ } else {
+ $svc_something->pkgnum( $cust_pkg->pkgnum );
+ if ( $seconds && $$seconds && $svc_something->isa('FS::svc_acct') ) {
+ $svc_something->seconds( $svc_something->seconds + $$seconds );
+ $$seconds = 0;
+ }
+ $error = $svc_something->insert(%svc_options);
}
- $error = $svc_something->insert(%svc_options);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
#return "inserting svc_ (transaction rolled back): $error";
}
}
- $error = $self->queue_fuzzyfiles_update;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "updating fuzzy search cache: $error";
+ unless ( $import || $skip_fuzzyfiles ) {
+ $error = $self->queue_fuzzyfiles_update;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "updating fuzzy search cache: $error";
+ }
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
return "Unknown refnum"
unless qsearchs( 'part_referral', { 'refnum' => $self->refnum } );
- return "Unknown referring custnum ". $self->referral_custnum
+ return "Unknown referring custnum: ". $self->referral_custnum
unless ! $self->referral_custnum
|| qsearchs( 'cust_main', { 'custnum' => $self->referral_custnum } );
) {
$self->payname( $self->first. " ". $self->getfield('last') );
} else {
- $self->payname =~ /^([\w \,\.\-\']+)$/
+ $self->payname =~ /^([\w \,\.\-\'\&]+)$/
or return gettext('illegal_name'). " payname: ". $self->payname;
$self->payname($1);
}
sub bill {
my( $self, %options ) = @_;
return '' if $self->payby eq 'COMP';
- warn "bill customer ". $self->custnum if $DEBUG;
+ warn "bill customer ". $self->custnum. "\n" if $DEBUG;
my $time = $options{'time'} || time;
#NO!! next if $cust_pkg->cancel;
next if $cust_pkg->getfield('cancel');
- warn " bill package ". $cust_pkg->pkgnum if $DEBUG;
+ warn " bill package ". $cust_pkg->pkgnum. "\n" if $DEBUG;
#? to avoid use of uninitialized value errors... ?
$cust_pkg->setfield('bill', '')
my $setup = 0;
if ( !$cust_pkg->setup || $options{'resetup'} ) {
- warn " bill setup" if $DEBUG;
+ warn " bill setup\n" if $DEBUG;
$setup = eval { $cust_pkg->calc_setup( $time ) };
if ( $@ ) {
( $cust_pkg->getfield('bill') || 0 ) <= $time
) {
- warn " bill recur" if $DEBUG;
+ warn " bill recur\n" if $DEBUG;
# XXX shared with $recur_prog
$sdate = $cust_pkg->bill || $cust_pkg->setup || $time;
$self->select_for_update; #mutex
my $balance = $self->balance;
- warn "collect customer ". $self->custnum. ": balance $balance" if $DEBUG;
+ warn "collect customer ". $self->custnum. ": balance $balance\n" if $DEBUG;
unless ( $balance > 0 ) { #redundant?????
$dbh->rollback if $oldAutoCommit; #hmm
return '';
last if $self->balance <= 0;
- warn "invnum ". $cust_bill->invnum. " (owed ". $cust_bill->owed. ")"
+ warn "invnum ". $cust_bill->invnum. " (owed ". $cust_bill->owed. ")\n"
if $DEBUG;
foreach my $part_bill_event (
|| ( $conf->exists('emailinvoiceonly') && ! @invoicing_list ) ) {
push @invoicing_list, $self->all_emails;
}
- my $email = $invoicing_list[0];
+
+ my $email = ($conf->exists('business-onlinepayment-email-override'))
+ ? $conf->config('business-onlinepayment-email-override')
+ : $invoicing_list[0];
my $payinfo = exists($options{'payinfo'})
? $options{'payinfo'}
$cust_pay = qsearchs('cust_pay', { paynum=>$options{'paynum'} } )
or return "Unknown paynum $options{'paynum'}";
$amount ||= $cust_pay->paid;
- $cust_pay->paybatch =~ /^(\w+):(\w*)(:(\w+))?$/
+ $cust_pay->paybatch =~ /^(\w+):([\w-]*)(:(\w+))?$/
or return "Can't parse paybatch for paynum $options{'paynum'}: ".
$cust_pay->paybatch;
( $pay_processor, $auth, $order_number ) = ( $1, $2, $4 );
sub check_invoicing_list {
my( $self, $arrayref ) = @_;
foreach my $address ( @{$arrayref} ) {
+
+ if ($address eq 'FAX' and $self->getfield('fax') eq '') {
+ return 'Can\'t add FAX invoice destination with a blank FAX number.';
+ }
+
my $cust_main_invoice = new FS::cust_main_invoice ( {
'custnum' => $self->custnum,
'dest' => $address,