X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=site_perl%2Fcust_main.pm;h=842d522167a483ca1e95f38fe81b0b1682a98baa;hb=2aa22dcacc8523311ebe32e4f8c077a227bc0dbb;hp=77ebb2d0414d720d19f254ea742aff5243e900c9;hpb=1f2d8690193476319d61b20b78461eb1a3ff106e;p=freeside.git diff --git a/site_perl/cust_main.pm b/site_perl/cust_main.pm index 77ebb2d04..842d52216 100644 --- a/site_perl/cust_main.pm +++ b/site_perl/cust_main.pm @@ -5,12 +5,15 @@ use vars qw($paymentserversecret $paymentserverport $paymentserverhost); package FS::cust_main; use strict; -use vars qw(@ISA $conf $lpr $processor $xaction $E_NoErr); +use vars qw( @ISA $conf $lpr $processor $xaction $E_NoErr $invoice_from + $smtpmachine ); use Safe; use Carp; use Time::Local; use Date::Format; use Date::Manip; +use Mail::Internet; +use Mail::Header; use Business::CreditCard; use FS::UID qw( getotaker ); use FS::Record qw( qsearchs qsearch ); @@ -31,6 +34,8 @@ use FS::cust_main_invoice; $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; @@ -203,7 +208,8 @@ sub check { my $self = shift; my $error = - $self->ut_number('agentnum') + $self->ut_numbern('custnum') + || $self->ut_number('agentnum') || $self->ut_number('refnum') || $self->ut_textn('company') || $self->ut_text('address1') @@ -254,7 +260,7 @@ sub check { } ); } - $self->zip =~ /^([\w\-]{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"; @@ -355,7 +361,7 @@ If there is an error, returns the error, otherwise returns false. sub bill { my( $self, %options ) = @_; - my $time = $options{'time'} || $^T; + my $time = $options{'time'} || time; my $error; @@ -365,6 +371,7 @@ sub bill { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; # find the packages which are due for billing, find out how much they are # & generate invoice database. @@ -542,7 +549,7 @@ return an error. By default, they don't. sub collect { my( $self, %options ) = @_; - my $invoice_time = $options{'invoice_time'} || $^T; + my $invoice_time = $options{'invoice_time'} || time; my $total_owed = $self->balance; return '' unless $total_owed > 0; #redundant????? @@ -553,6 +560,7 @@ sub collect { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; foreach my $cust_bill ( qsearch('cust_bill', { 'custnum' => $self->custnum, } ) @@ -582,11 +590,32 @@ sub collect { && ( $cust_bill->printed * 2592000 ) <= $since ) { - open(LPR, "|$lpr") or die "Can't open pipe to $lpr: $!"; - print LPR $cust_bill->print_text; #( date ) - close LPR - or die $! ? "Error closing $lpr: $!" - : "Exit status $? from $lpr"; + #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 ), + "Sender: $invoice_from", + "Reply-To: $invoice_from", + "Date: ". time2str("%a, %d %b %Y %X %z", time), + "Subject: Invoice", + ] ); + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ $cust_bill->print_text ], #( date) + ); + $message->smtpsend or die "Can't send invoice email!"; #die? warn? + + } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { + open(LPR, "|$lpr") or die "Can't open pipe to $lpr: $!"; + print LPR $cust_bill->print_text; #( date ) + close LPR + or die $! ? "Error closing $lpr: $!" + : "Exit status $? from $lpr"; + } my %hash = $cust_bill->hash; $hash{'printed'}++; @@ -608,6 +637,7 @@ sub collect { my $error = $cust_pay->insert; return 'Error COMPing invnum #' . $cust_bill->invnum . ':' . $error if $error; + } elsif ( $self->payby eq 'CARD' ) { if ( $options{'batch_card'} ne 'yes' ) { @@ -617,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); @@ -709,6 +740,10 @@ sub collect { return "Unknown payment type ". $self->payby; } + + + + } ''; @@ -760,34 +795,42 @@ sub balance { sprintf( "%.2f", $self->total_owed - $self->total_credited ); } -=item invoicing_list [ ITEM, ITEM, ... ] +=item invoicing_list [ ARRAYREF ] -If arguements are given, sets these email addresses as invoice recipients +If an arguement is given, sets these email addresses as invoice recipients (see L). Errors are not fatal and are not reported (except as warnings), so use check_invoicing_list first. Returns a list of email addresses (with svcnum entries expanded). +Note: You can clear the invoicing list by passing an empty ARRAYREF. You can +check it without disturbing anything by passing nothing. + +This interface may change in the future. + =cut sub invoicing_list { - my( $self, @addresses ) = @_; - if ( @addresses ) { + my( $self, $arrayref ) = @_; + if ( $arrayref ) { my @cust_main_invoice = qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } ); foreach my $cust_main_invoice ( @cust_main_invoice ) { - unless ( grep { $cust_main_invoice->address eq $_ } @addresses ) { - $cust_main_invoice->delete; + #warn $cust_main_invoice->destnum; + unless ( grep { $cust_main_invoice->address eq $_ } @{$arrayref} ) { + #warn $cust_main_invoice->destnum; + my $error = $cust_main_invoice->delete; + warn $error if $error; } } @cust_main_invoice = qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } ); - foreach my $address ( @addresses ) { + foreach my $address ( @{$arrayref} ) { unless ( grep { $address eq $_->address } @cust_main_invoice ) { - my $cust_main_invoice = new FS::cust_main_invoice ( + my $cust_main_invoice = new FS::cust_main_invoice ( { 'custnum' => $self->custnum, 'dest' => $address, - ); + } ); my $error = $cust_main_invoice->insert; warn $error if $error; } @@ -797,7 +840,7 @@ sub invoicing_list { qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } ); } -=item check_invoicing_list ITEM, ITEM +=item check_invoicing_list ARRAYREF Checks these arguements as valid input for the invoicing_list method. If there is an error, returns the error, otherwise returns false. @@ -805,13 +848,16 @@ is an error, returns the error, otherwise returns false. =cut sub check_invoicing_list { - my( $self, @addresses ) = @_; - foreach my $address ( @addresses ) { - my $cust_main_invoice = new FS::cust_main_invoice ( + my( $self, $arrayref ) = @_; + foreach my $address ( @{$arrayref} ) { + my $cust_main_invoice = new FS::cust_main_invoice ( { 'custnum' => $self->custnum, 'dest' => $address, - ); - my $error = $cust_main_invoice->check; + } ); + my $error = $self->custnum + ? $cust_main_invoice->check + : $cust_main_invoice->checkdest + ; return $error if $error; } ''; @@ -821,7 +867,7 @@ sub check_invoicing_list { =head1 VERSION -$Id: cust_main.pm,v 1.8 1998-12-29 11:59:39 ivan Exp $ +$Id: cust_main.pm,v 1.14 1999-03-29 12:06:15 ivan Exp $ =head1 BUGS @@ -877,7 +923,26 @@ 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.8 1998-12-29 11:59:39 ivan +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 + +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 +yet more mod_perl stuff + +Revision 1.9 1999/01/18 09:22:41 ivan +changes to track email addresses for email invoicing + +Revision 1.8 1998/12/29 11:59:39 ivan mostly properly OO, some work still to be done with svc_ stuff Revision 1.7 1998/12/16 09:58:52 ivan