Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / cust_pay_batch.pm
index d4d40b5..8f31e4d 100644 (file)
@@ -49,7 +49,7 @@ following fields are currently supported:
 
 =item batchnum - indentifies group in batch
 
-=item payby - CARD/CHEK/LECB/BILL/COMP
+=item payby - CARD/CHEK
 
 =item payinfo
 
@@ -129,6 +129,8 @@ and replace methods.
 sub check {
   my $self = shift;
 
+  my $conf = new FS::Conf;
+
   my $error = 
       $self->ut_numbern('paybatchnum')
     || $self->ut_numbern('trancode') #deprecated
@@ -137,7 +139,9 @@ sub check {
     || $self->ut_number('custnum')
     || $self->ut_text('address1')
     || $self->ut_textn('address2')
-    || $self->ut_text('city')
+    || ($conf->exists('cust_main-no_city_in_address') 
+        ? $self->ut_textn('city') 
+        : $self->ut_text('city'))
     || $self->ut_textn('state')
   ;
 
@@ -154,7 +158,7 @@ sub check {
 
   if ( $self->exp eq '' ) {
     return "Expiration date required"
-      unless $self->payby =~ /^(CHEK|DCHK|LECB|WEST)$/;
+      unless $self->payby =~ /^(CHEK|DCHK|WEST)$/;
     $self->exp('');
   } else {
     if ( $self->exp =~ /^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})$/ ) {
@@ -246,39 +250,6 @@ sub retriable {
   confess "deprecated method cust_pay_batch->retriable called; try removing ".
           "the once condition and adding an every condition?";
 
-  my $self = shift;
-
-  local $SIG{HUP} = 'IGNORE';        #Hmm
-  local $SIG{INT} = 'IGNORE';
-  local $SIG{QUIT} = 'IGNORE';
-  local $SIG{TERM} = 'IGNORE';
-  local $SIG{TSTP} = 'IGNORE';
-  local $SIG{PIPE} = 'IGNORE';
-
-  my $oldAutoCommit = $FS::UID::AutoCommit;
-  local $FS::UID::AutoCommit = 0;
-  my $dbh = dbh;
-
-  my $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
-    or return "event $self->eventnum references nonexistant invoice $self->invnum";
-
-  warn "cust_pay_batch->retriable working with self of " . $self->paybatchnum . " and invnum of " . $self->invnum;
-  my @cust_bill_event =
-    sort { $a->part_bill_event->seconds <=> $b->part_bill_event->seconds }
-      grep {
-        $_->part_bill_event->eventcode =~ /\$cust_bill->batch_card/
-         && $_->status eq 'done'
-         && ! $_->statustext
-       }
-      $cust_bill->cust_bill_event;
-  # complain loudly if scalar(@cust_bill_event) > 1 ?
-  my $error = $cust_bill_event[0]->retriable;
-  if ($error ) {
-    # gah, even with transactions.
-    $dbh->commit if $oldAutoCommit; #well.
-    return "error marking invoice event retriable: $error";
-  }
-  '';
 }
 
 =item approve OPTIONS
@@ -298,15 +269,15 @@ sub approve {
   my %opt = @_;
   my $paybatchnum = $new->paybatchnum;
   my $old = qsearchs('cust_pay_batch', { paybatchnum => $paybatchnum })
-    or return "paybatchnum $paybatchnum not found";
+    or return "cannot approve, paybatchnum $paybatchnum not found";
   # leave these restrictions in place until TD EFT is converted over
   # to B::BP
-  return "paybatchnum $paybatchnum already resolved ('".$old->status."')" 
+  return "cannot approve paybatchnum $paybatchnum, already resolved ('".$old->status."')" 
     if $old->status;
   $new->status('Approved');
   my $error = $new->replace($old);
   if ( $error ) {
-    return "error updating status of paybatchnum $paybatchnum: $error\n";
+    return "error approving paybatchnum $paybatchnum: $error\n";
   }
   my $cust_pay = new FS::cust_pay ( {
       'custnum'   => $new->custnum,
@@ -352,7 +323,7 @@ sub decline {
 
   my $paybatchnum = $new->paybatchnum;
   my $old = qsearchs('cust_pay_batch', { paybatchnum => $paybatchnum })
-    or return "paybatchnum $paybatchnum not found";
+    or return "cannot decline, paybatchnum $paybatchnum not found";
   if ( $old->status ) {
     # Handle the case where payments are rejected after the batch has been 
     # approved.  FS::pay_batch::import_results won't allow results to be 
@@ -379,7 +350,7 @@ sub decline {
     }
     else {
       # normal case: refuse to do anything
-      return "paybatchnum $paybatchnum already resolved ('".$old->status."')";
+      return "cannot decline paybatchnum $paybatchnum, already resolved ('".$old->status."')";
     }
   } # !$old->status
   $new->status('Declined');
@@ -387,7 +358,7 @@ sub decline {
   $new->failure_status($failure_status);
   my $error = $new->replace($old);
   if ( $error ) {
-    return "error updating status of paybatchnum $paybatchnum: $error\n";
+    return "error declining paybatchnum $paybatchnum: $error\n";
   }
   my $due_cust_event = $new->cust_main->due_cust_event(
     'eventtable'  => 'cust_pay_batch',