use FS::part_svc and FS::svc_acct_pop to avoid warnings
[freeside.git] / site_perl / cust_main.pm
index 5a83741..768d772 100644 (file)
@@ -5,7 +5,8 @@ use vars qw($paymentserversecret $paymentserverport $paymentserverhost);
 package FS::cust_main;
 
 use strict;
-use vars qw(@ISA $conf $lpr $processor $xaction $E_NoErr $invoice_from);
+use vars qw( @ISA $conf $lpr $processor $xaction $E_NoErr $invoice_from
+             $smtpmachine );
 use Safe;
 use Carp;
 use Time::Local;
@@ -34,6 +35,7 @@ $FS::UID::callback{'FS::cust_main'} = sub {
   $conf = new FS::Conf;
   $lpr = $conf->config('lpr');
   $invoice_from = $conf->config('invoice_from');
+  $smtpmachine = $conf->config('smtpmachine');
 
   if ( $conf->exists('cybercash3.2') ) {
     require CCMckLib3_2;
@@ -258,7 +260,7 @@ sub check {
       } );
   }
 
-  $self->zip =~ /^([\w\-]{5,10})$/ or return "Illegal zip";
+  $self->zip =~ /^\s*(\w[\w\-\s]{3,8}\w)\s*$/ or return "Illegal zip";
   $self->zip($1);
 
   $self->payby =~ /^(CARD|BILL|COMP)$/ or return "Illegal payby";
@@ -591,6 +593,8 @@ sub collect {
         #my @print_text = $cust_bill->print_text; #( date )
         my @invoicing_list = $self->invoicing_list;
         if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice
+          $ENV{SMTPHOSTS} = $smtpmachine;
+          $ENV{MAILADDRESS} = $invoice_from;
           my $header = new Mail::Header ( [
             "From: $invoice_from",
             "To: ". join(', ', grep { $_ ne 'POST' } @invoicing_list ),
@@ -643,8 +647,9 @@ sub collect {
         if ( $processor =~ /^cybercash/ ) {
 
           #fix exp. date for cybercash
-          $self->paydate =~ /^(\d+)\/\d*(\d{2})$/;
-          my $exp = "$1/$2";
+          #$self->paydate =~ /^(\d+)\/\d*(\d{2})$/;
+          $self->paydate =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
+          my $exp = "$2/$1";
 
           my $paybatch = $cust_bill->invnum. 
                          '-' . time2str("%y%m%d%H%M%S", time);
@@ -808,8 +813,13 @@ This interface may change in the future.
 sub invoicing_list {
   my( $self, $arrayref ) = @_;
   if ( $arrayref ) {
-    my @cust_main_invoice = 
-      qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+    my @cust_main_invoice;
+    if ( $self->custnum ) {
+      @cust_main_invoice = 
+        qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+    } else {
+      @cust_main_invoice = ();
+    }
     foreach my $cust_main_invoice ( @cust_main_invoice ) {
       #warn $cust_main_invoice->destnum;
       unless ( grep { $cust_main_invoice->address eq $_ } @{$arrayref} ) {
@@ -818,8 +828,12 @@ sub invoicing_list {
         warn $error if $error;
       }
     }
-    @cust_main_invoice =
-      qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+    if ( $self->custnum ) {
+      @cust_main_invoice = 
+        qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+    } else {
+      @cust_main_invoice = ();
+    }
     foreach my $address ( @{$arrayref} ) {
       unless ( grep { $address eq $_->address } @cust_main_invoice ) {
         my $cust_main_invoice = new FS::cust_main_invoice ( {
@@ -831,8 +845,12 @@ sub invoicing_list {
       } 
     }
   }
-  map { $_->address }
-    qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+  if ( $self->custnum ) {
+    map { $_->address }
+      qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } );
+  } else {
+    ();
+  }
 }
 
 =item check_invoicing_list ARRAYREF
@@ -862,7 +880,7 @@ sub check_invoicing_list {
 
 =head1 VERSION
 
-$Id: cust_main.pm,v 1.11 1999-02-23 08:09:27 ivan Exp $
+$Id: cust_main.pm,v 1.16 1999-04-07 14:32:19 ivan Exp $
 
 =head1 BUGS
 
@@ -918,7 +936,23 @@ enable cybercash, cybercash v3 support, don't need to import
 FS::UID::{datasrc,checkruid} ivan@sisd.com 98-sep-19-21
 
 $Log: cust_main.pm,v $
-Revision 1.11  1999-02-23 08:09:27  ivan
+Revision 1.16  1999-04-07 14:32:19  ivan
+more &invoicing_list logic to skip searches when there is no custnum
+
+Revision 1.15  1999/04/07 13:41:54  ivan
+in &invoicing_list, don't search if there's no custnum yet
+
+Revision 1.14  1999/03/29 12:06:15  ivan
+buglet in email invoices fixed
+
+Revision 1.13  1999/02/28 20:09:03  ivan
+allow spaces in zip codes, for (at least) canada.  pointed out by
+Clayton Gray <clgray@bcgroup.net>
+
+Revision 1.12  1999/02/27 21:24:22  ivan
+parse paydate correctly for cybercash
+
+Revision 1.11  1999/02/23 08:09:27  ivan
 beginnings of one-screen new customer entry and some other miscellania
 
 Revision 1.10  1999/01/25 12:26:09  ivan