Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / cust_main.pm
index 427112a..f102d97 100644 (file)
@@ -464,8 +464,6 @@ sub insert {
     }
   }
 
-  $self->_loc_change();
-
   warn "  inserting $self\n"
     if $DEBUG > 1;
 
@@ -1338,8 +1336,6 @@ sub replace {
     $self->set($l.'num', $new_loc->locationnum);
   } #for $l
 
-  $self->_loc_change($old);
-
   # replace the customer record
   my $error = $self->SUPER::replace($old);
 
@@ -1642,6 +1638,11 @@ sub check {
     $self->ss("$1-$2-$3");
   }
 
+  #turn off invoice_ship_address if ship & bill are the same
+  if ($self->bill_locationnum eq $self->ship_locationnum) {
+    $self->invoice_ship_address('');
+  }
+
   # cust_main_county verification now handled by cust_location check
 
   $error =
@@ -1855,7 +1856,7 @@ sub check {
   return "You are not permitted to create complimentary accounts."
     if ! $self->custnum
     && $self->complimentary eq 'Y'
-    && ! $FS::CurrentUser->CurrentUser->access_right('Complimentary customer');
+    && ! $FS::CurrentUser::CurrentUser->access_right('Complimentary customer');
 
   if ( $self->paydate eq '' || $self->paydate eq '-' ) {
     return "Expiration date required"
@@ -1922,6 +1923,21 @@ sub check {
   $self->SUPER::check;
 }
 
+=item replace_check
+
+Additional checks for replace only.
+
+=cut
+
+sub replace_check {
+  my ($new,$old) = @_;
+  #preserve old value if global config is set
+  if ($old && $conf->exists('invoice-ship_address')) {
+    $new->invoice_ship_address($old->invoice_ship_address);
+  }
+  return '';
+}
+
 =item addr_fields 
 
 Returns a list of fields which have ship_ duplicates.
@@ -1999,6 +2015,17 @@ sub cust_payby {
   });
 }
 
+sub has_cust_payby_auto {
+  my $self = shift;
+  scalar( qsearch({ 
+    'table'     => 'cust_payby',
+    'hashref'   => { 'custnum' => $self->custnum, },
+    'extra_sql' => " AND payby IN ( 'CARD', 'CHEK' ) ",
+    'order_by'  => 'LIMIT 1',
+  }) );
+
+}
+
 =item unsuspend
 
 Unsuspends all unflagged suspended packages (see L</unflagged_suspended_pkgs>
@@ -4782,22 +4809,6 @@ sub process_bill_and_collect {
   $cust_main->bill_and_collect( %$param );
 }
 
-#hook for insert/replace
-#runs after locations have been set
-#but before custnum has been set (for insert)
-sub _loc_change {
-  my $self = shift;
-  my $old = shift;
-  #turn off invoice_ship_address if ship & bill are the same
-  if ($self->bill_locationnum eq $self->ship_locationnum) {
-    $self->invoice_ship_address('');
-  }
-  #preserve old value if global config is set (replace only)
-  elsif ($old && $conf->exists('invoice-ship_address')) {
-    $self->invoice_ship_address($old->invoice_ship_address);
-  }
-}
-
 #starting to take quite a while for big dbs
 #   (JRNL: journaled so it only happens once per database)
 # - seq scan of h_cust_main (yuck), but not going to index paycvv, so