show credit balance on invoices, #11564
[freeside.git] / FS / FS / cust_main_invoice.pm
index 48f47e0..ec01842 100644 (file)
@@ -1,7 +1,7 @@
 package FS::cust_main_invoice;
 
 use strict;
-use vars qw(@ISA $conf);
+use vars qw(@ISA);
 use Exporter;
 use FS::Record qw( qsearchs );
 use FS::Conf;
@@ -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
 
@@ -127,12 +127,16 @@ sub checkdest {
   my $error = $self->ut_text('dest');
   return $error if $error;
 
+  my $conf = new FS::Conf;
+
   if ( $self->dest =~ /^(POST|FAX)$/ ) {
     #contemplate our navel
   } 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 ( $conf->exists('emailinvoice-apostrophe')
+              ? $self->dest =~ /^\s*([\w\.\-\&\+\']+)\@(([\w\.\-]+\.)+\w+)\s*$/
+              : $self->dest =~ /^\s*([\w\.\-\&\+]+)\@(([\w\.\-]+\.)+\w+)\s*$/ ){
     my($user, $domain) = ($1, $2);
     $self->dest("$1\@$2");
   } else {
@@ -159,6 +163,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