unbork summary page invoices
[freeside.git] / FS / FS / cust_main_invoice.pm
index 03863b8..71148ca 100644 (file)
@@ -91,7 +91,7 @@ sub replace {
 
 Checks all fields to make sure this is a valid invoice destination.  If there is
 an error, returns the error, otherwise returns false.  Called by the insert
-and repalce methods.
+and replace methods.
 
 =cut
 
@@ -132,11 +132,11 @@ sub checkdest {
   } elsif ( $self->dest =~ /^(\d+)$/ ) {
     return "Unknown local account (specified by svcnum: ". $self->dest. ")"
       unless qsearchs( 'svc_acct', { 'svcnum' => $self->dest } );
-  } elsif ( $self->dest =~ /^([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)$/ ) {
+  } elsif ( $self->dest =~ /^\s*([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ) {
     my($user, $domain) = ($1, $2);
     $self->dest("$1\@$2");
   } else {
-    return gettext("illegal_email_invoice_address");
+    return gettext("illegal_email_invoice_address"). ': '. $self->dest;
   }
 
   ''; #no error
@@ -159,6 +159,17 @@ sub address {
   }
 }
 
+=item cust_main
+
+Returns the parent customer object (see L<FS::cust_main>).
+
+=cut
+
+sub cust_main {
+  my $self = shift;
+  qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
+}
+
 =back
 
 =head1 BUGS