X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=cba28bc9f0914b24a569bbecbddb937740c2c40c;hp=53ecf5b8e2407c6d6531a68509dd3efe52ad74b0;hb=5e8073ffe5707504751b8df36f645b325a895f87;hpb=5e76ae4e7a11bd28478ed68eef8124fb7ff0767c diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 53ecf5b8e..cba28bc9f 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -8,6 +8,7 @@ use base qw( FS::cust_main::Packages FS::cust_main::Status FS::cust_main::Billing_Discount FS::otaker_Mixin FS::payinfo_Mixin FS::cust_main_Mixin FS::geocode_Mixin + FS::o2m_Common FS::Record ); use vars qw( $DEBUG $me $conf @@ -465,7 +466,7 @@ sub insert { $self->signupdate(time) unless $self->signupdate; - $self->censusyear($conf->config('census_year')) if $self->censustract; + $self->censusyear($conf->config('census_year')||'2012') if $self->censustract; $self->auto_agent_custid() if $conf->config('cust_main-auto_agent_custid') && ! $self->agent_custid; @@ -1534,9 +1535,13 @@ sub replace { if ( $self->censustract ne '' and $self->censustract ne $old->censustract ) { # update censusyear whenever tract code changes - $self->censusyear($conf->config('census_year')); + $self->censusyear($conf->config('census_year')||'2012'); } + return "Invoicing locale is required" + if $old->locale + && ! $self->locale + && $conf->exists('cust_main-require_locale'); local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -1847,7 +1852,7 @@ sub check { return $error if $error; } - if ( $conf->exists('cust_main-require_phone') + if ( $conf->exists('cust_main-require_phone', $self->agentnum) && ! length($self->daytime) && ! length($self->night) && ! length($self->mobile) ) { @@ -2032,14 +2037,15 @@ sub check { my $payinfo = $self->payinfo; $payinfo =~ s/[^\d\@\.]//g; - if ( $conf->exists('cust_main-require-bank-branch') ) { - $payinfo =~ /^(\d+)\@(\d+)\.(\d+)$/ or return 'invalid echeck account@branch.bank'; + if ( $conf->config('echeck-country') eq 'CA' ) { + $payinfo =~ /^(\d+)\@(\d{5})\.(\d{3})$/ + or return 'invalid echeck account@branch.bank'; $payinfo = "$1\@$2.$3"; - } elsif ( $conf->exists('echeck-nonus') ) { - $payinfo =~ /^(\d+)\@(\d+)$/ or return 'invalid echeck account@aba'; + } elsif ( $conf->config('echeck-country') eq 'US' ) { + $payinfo =~ /^(\d+)\@(\d{9})$/ or return 'invalid echeck account@aba'; $payinfo = "$1\@$2"; } else { - $payinfo =~ /^(\d+)\@(\d{9})$/ or return 'invalid echeck account@aba'; + $payinfo =~ /^(\d+)\@(\d+)$/ or return 'invalid echeck account@routing'; $payinfo = "$1\@$2"; } $self->payinfo($payinfo); @@ -2137,6 +2143,11 @@ sub check { $self->payname($1); } + return "Please select an invoicing locale" + if ! $self->locale + && ! $self->custnum + && $conf->exists('cust_main-require_locale'); + foreach my $flag (qw( tax spool_cdr squelch_cdr archived email_csv_cdr )) { $self->$flag() =~ /^(Y?)$/ or return "Illegal $flag: ". $self->$flag(); $self->$flag($1); @@ -3213,7 +3224,7 @@ sub check_invoicing_list { } return "Email address required" - if $conf->exists('cust_main-require_invoicing_list_email') + if $conf->exists('cust_main-require_invoicing_list_email', $self->agentnum) && ! grep { $_ !~ /^([A-Z]+)$/ } @$arrayref; ''; @@ -3960,11 +3971,35 @@ cust_main-default_agent_custid is set and it has a value, custnum otherwise. sub display_custnum { my $self = shift; + + my $prefix = $conf->config('cust_main-custnum-display_prefix', $self->agentnum) || ''; + if ( my $special = $conf->config('cust_main-custnum-display_special') ) { + if ( $special eq 'CoStAg' ) { + $prefix = uc( join('', + $self->country, + ($self->state =~ /^(..)/), + $prefix || ($self->agent->agent =~ /^(..)/) + ) ); + } + elsif ( $special eq 'CoStCl' ) { + $prefix = uc( join('', + $self->country, + ($self->state =~ /^(..)/), + ($self->classnum ? $self->cust_class->classname =~ /^(..)/ : '__') + ) ); + } + # add any others here if needed + } + + my $length = $conf->config('cust_main-custnum-display_length'); if ( $conf->exists('cust_main-default_agent_custid') && $self->agent_custid ){ return $self->agent_custid; - } elsif ( $conf->config('cust_main-custnum-display_prefix') ) { - return $conf->config('cust_main-custnum-display_prefix'). - sprintf('%08d', $self->custnum) + } elsif ( $prefix ) { + $length = 8 if !defined($length); + return $prefix . + sprintf('%0'.$length.'d', $self->custnum) + } elsif ( $length ) { + return sprintf('%0'.$length.'d', $self->custnum); } else { return $self->custnum; } @@ -5035,6 +5070,12 @@ sub process_censustract_update { # then it's a tract code $cust_main->set('censustract', $new_tract); $cust_main->set('censusyear', $new_year); + + local($ignore_expired_card) = 1; + local($ignore_illegal_zip) = 1; + local($ignore_banned_card) = 1; + local($skip_fuzzyfiles) = 1; + local($import) = 1; #prevent automatic geocoding (need its own variable?) my $error = $cust_main->replace; die $error if $error; } @@ -5053,7 +5094,7 @@ sub _upgrade_data { #class method 'UPDATE cust_main SET signupdate = (SELECT signupdate FROM h_cust_main WHERE signupdate IS NOT NULL AND h_cust_main.custnum = cust_main.custnum ORDER BY historynum DESC LIMIT 1) WHERE signupdate IS NULL', ); # fix yyyy-m-dd formatted paydates - if ( driver_name =~ /^mysql$/i ) { + if ( driver_name =~ /^mysql/i ) { push @statements, "UPDATE cust_main SET paydate = CONCAT( SUBSTRING(paydate FROM 1 FOR 5), '0', SUBSTRING(paydate FROM 6) ) WHERE SUBSTRING(paydate FROM 7 FOR 1) = '-'"; } @@ -5062,6 +5103,10 @@ sub _upgrade_data { #class method "UPDATE cust_main SET paydate = SUBSTRING(paydate FROM 1 FOR 5) || '0' || SUBSTRING(paydate FROM 6) WHERE SUBSTRING(paydate FROM 7 FOR 1) = '-'"; } + push @statements, #fix the weird BILL with a cc# in payinfo problem + #DCRD to be safe + "UPDATE cust_main SET payby = 'DCRD' WHERE payby = 'BILL' and length(payinfo) = 16 and payinfo ". regexp_sql. q( '^[0-9]*$' ); + foreach my $sql ( @statements ) { my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr;