diff options
author | khoff <khoff> | 2005-03-21 22:13:39 +0000 |
---|---|---|
committer | khoff <khoff> | 2005-03-21 22:13:39 +0000 |
commit | 18c025613fa052cf4ba8d484f1296cc2a1719a24 (patch) | |
tree | 334919583d3ecdd78413ad7405b6092e62f614ad /FS | |
parent | 30189fa2e5987bafeb4714a83b7f130c568b221c (diff) |
Added support for FAX invoice destinations using a HylaFAX server.
Faxing plain text invoices is not supported.
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/ClientAPI/MyAccount.pm | 2 | ||||
-rw-r--r-- | FS/FS/Conf.pm | 7 | ||||
-rw-r--r-- | FS/FS/Misc.pm | 76 | ||||
-rw-r--r-- | FS/FS/cust_bill.pm | 46 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_main_invoice.pm | 6 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 4 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_export/http.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_export/infostreet.pm | 2 | ||||
-rw-r--r-- | FS/FS/part_export/shellcommands.pm | 2 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 2 |
12 files changed, 130 insertions, 26 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index d18a6e4ff..478973396 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -131,7 +131,7 @@ sub customer_info { } $return{'invoicing_list'} = - join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ); + join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list ); $return{'postal_invoicing'} = 0 < ( grep { $_ eq 'POST' } $cust_main->invoicing_list ); diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index e21e58322..4a9762672 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1433,6 +1433,13 @@ httemplate/docs/config.html 'select_enum' => [ 'Cache::SharedMemoryCache', 'Cache::FileCache', ], # '_Database' ], }, + { + 'key' => 'hylafax', + 'section' => '', + 'description' => 'Options for a HylaFAX server to enable the FAX invoice destination. They should be in the form of a space separated list of arguments to the Fax::Hylafax::Client::sendfax subroutine. You probably shouldn\'t override things like \'docfile\'. *Note* Only supported when using typeset invoices (see the invoice_latex configuration option).', + 'type' => [qw( checkbox textarea )], + }, + ); 1; diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 71fe7e712..a7cd47176 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -5,7 +5,7 @@ use vars qw ( @ISA @EXPORT_OK ); use Exporter; @ISA = qw( Exporter ); -@EXPORT_OK = qw( send_email ); +@EXPORT_OK = qw( send_email send_fax ); =head1 NAME @@ -50,6 +50,7 @@ use Date::Format; use Mail::Header; use Mail::Internet 1.44; use MIME::Entity; +use Fax::Hylafax::Client; use FS::UID; FS::UID->install_callback( sub { @@ -111,6 +112,77 @@ sub send_email { } +=item send_fax OPTION => VALUE ... + +Options: + +I<dialstring> - (required) 10-digit phone number w/ area code + +I<docdata> - (required) Array ref containing PostScript or TIFF Class F document + +-or- + +I<docfile> - (required) Filename of PostScript TIFF Class F document + +...any other options will be passed to L<Fax::Hylafax::Client::sendfax> + + +=cut + +sub send_fax { + + my %options = @_; + + die 'HylaFAX support has not been configured.' + unless $conf->exists('hylafax'); + + my %hylafax_opts = map { split /\s+/ } $conf->config('hylafax'); + + die 'Called send_fax without a \'dialstring\'.' + unless exists($options{'dialstring'}); + + if (exists($options{'docdata'}) and ref($options{'docdata'}) eq 'ARRAY') { + my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $fh = new File::Temp( + TEMPLATE => 'faxdoc.'. $options{'dialstring'} . '.XXXXXXXX', + DIR => $dir, + UNLINK => 0, + ) or die "can't open temp file: $!\n"; + + $options{docfile} = $fh->filename; + + print $fh @{$options{'docdata'}}; + close $fh; + + delete $options{'docdata'}; + } + + die 'Called send_fax without a \'docfile\' or \'docdata\'.' + unless exists($options{'docfile'}); + + #FIXME: Need to send canonical dialstring to HylaFAX, but this only + # works in the US. + + $options{'dialstring'} =~ s/[^\d\+]//g; + if ($options{'dialstring'} =~ /^\d{10}$/) { + $options{dialstring} = '+1' . $options{'dialstring'}; + } else { + return 'Invalid dialstring ' . $options{'dialstring'} . '.'; + } + + my $faxjob = &Fax::Hylafax::Client::sendfax(%options, %hylafax_opts); + + if ($faxjob->success) { + warn "Successfully queued fax to '$options{dialstring}' with jobid " . + $faxjob->jobid; + } else { + return 'Error while sending FAX: ' . $faxjob->trace; + } + + return ''; + +} + package Mail::Internet; use Mail::Address; @@ -191,6 +263,8 @@ This package exists. L<FS::UID>, L<FS::CGI>, L<FS::Record>, the base documentation. +L<Fax::Hylafax::Client> + =cut 1; diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index e70bb3247..10b4928cb 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -9,7 +9,7 @@ use File::Temp 0.14; use String::ShellQuote; use FS::UID qw( datasrc ); use FS::Record qw( qsearch qsearchs ); -use FS::Misc qw( send_email ); +use FS::Misc qw( send_email send_fax ); use FS::cust_main; use FS::cust_bill_pkg; use FS::cust_credit; @@ -378,7 +378,7 @@ sub generate_email { if (ref($args{'to'} eq 'ARRAY')) { @invoicing_list = @{$args{'to'}}; } else { - @invoicing_list = grep { $_ ne 'POST' } $self->cust_main->invoicing_list; + @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $self->cust_main->invoicing_list; } return ( @@ -418,7 +418,7 @@ sub send { my @print_text = $self->print_text('', $template); my @invoicing_list = $self->cust_main->invoicing_list; - if ( grep { $_ ne 'POST' } @invoicing_list or !@invoicing_list ) { #email + if ( grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list or !@invoicing_list ) { #email #better to notify this person than silence @invoicing_list = ($invoice_from) unless @invoicing_list; @@ -426,7 +426,7 @@ sub send { my $error = send_email( $self->generate_email( 'from' => $invoice_from, - 'to' => [ grep { $_ ne 'POST' } @invoicing_list ], + 'to' => [ grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ], 'print_text' => [ @print_text ], ) ); @@ -435,16 +435,34 @@ sub send { } - if ( grep { $_ eq 'POST' } @invoicing_list ) { #postal - @print_text = $self->print_ps('', $template) - if $conf->config('invoice_latex'); - my $lpr = $conf->config('lpr'); - open(LPR, "|$lpr") - or die "Can't open pipe to $lpr: $!\n"; - print LPR @print_text; - close LPR - or die $! ? "Error closing $lpr: $!\n" - : "Exit status $? from $lpr\n"; + if ( grep { $_ =~ /^(POST|FAX)$/ } @invoicing_list ) { + my $lpr_data; + if ($conf->config('invoice_latex')) { + $lpr_data = [ $self->print_ps('', $template) ]; + } else { + $lpr_data = \@print_text; + } + + if ( grep { $_ eq 'POST' } @invoicing_list ) { #postal + my $lpr = $conf->config('lpr'); + open(LPR, "|$lpr") + or die "Can't open pipe to $lpr: $!\n"; + print LPR @{$lpr_data}; + close LPR + or die $! ? "Error closing $lpr: $!\n" + : "Exit status $? from $lpr\n"; + } + + if ( grep { $_ eq 'FAX' } @invoicing_list ) { #fax + unless ($conf->exists('invoice_latex')) { + die 'FAX invoice destination not supported with plain text invoices.' + } + my $dialstring = $self->cust_main->getfield('fax'); + #Check $dialstring? + my $error = send_fax(docdata => $lpr_data, dialstring => $dialstring); + die $error if $error; + } + } ''; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 8246b93f5..4fcb22681 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2655,6 +2655,11 @@ is an error, returns the error, otherwise returns false. sub check_invoicing_list { my( $self, $arrayref ) = @_; foreach my $address ( @{$arrayref} ) { + + if ($address eq 'FAX' and $self->getfield('fax') eq '') { + return 'Can\'t add FAX invoice destination with a blank FAX number.'; + } + my $cust_main_invoice = new FS::cust_main_invoice ( { 'custnum' => $self->custnum, 'dest' => $address, diff --git a/FS/FS/cust_main_invoice.pm b/FS/FS/cust_main_invoice.pm index 3cabd3a64..03863b83f 100644 --- a/FS/FS/cust_main_invoice.pm +++ b/FS/FS/cust_main_invoice.pm @@ -43,7 +43,7 @@ FS::Record. The following fields are currently supported: =item custnum - customer (see L<FS::cust_main>) -=item dest - Invoice destination: If numeric, a svcnum (see L<FS::svc_acct>), if string, a literal email address, or `POST' to enable mailing (the default if no cust_main_invoice records exist) +=item dest - Invoice destination: If numeric, a svcnum (see L<FS::svc_acct>), if string, a literal email address, `POST' to enable mailing (the default if no cust_main_invoice records exist), or `FAX' to enable faxing via a HylaFAX server. =back @@ -127,7 +127,7 @@ sub checkdest { my $error = $self->ut_text('dest'); return $error if $error; - if ( $self->dest eq 'POST' ) { + if ( $self->dest =~ /^(POST|FAX)$/ ) { #contemplate our navel } elsif ( $self->dest =~ /^(\d+)$/ ) { return "Unknown local account (specified by svcnum: ". $self->dest. ")" @@ -144,7 +144,7 @@ sub checkdest { =item address -Returns the literal email address for this record (or `POST'). +Returns the literal email address for this record (or `POST' or `FAX'). =cut diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 80d4a140b..fa97ba9eb 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -167,7 +167,7 @@ sub insert { #my $cust_main = $self->cust_main; if ( $conf->exists('payment_receipt_email') - && grep { $_ ne 'POST' } $cust_main->invoicing_list + && grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list ) { my $receipt_template = new Text::Template ( @@ -178,7 +178,7 @@ sub insert { return ''; }; - my @invoicing_list = grep { $_ ne 'POST' } $cust_main->invoicing_list; + my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list; my $payby = $self->payby; my $payinfo = $self->payinfo; diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index e3724a3ef..f5c1de3e2 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -423,7 +423,7 @@ sub cancel { $dbh->commit or die $dbh->errstr if $oldAutoCommit; my $conf = new FS::Conf; - my @invoicing_list = grep { $_ ne 'POST' } $self->cust_main->invoicing_list; + my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $self->cust_main->invoicing_list; if ( !$options{'quiet'} && $conf->exists('emailcancel') && @invoicing_list ) { my $conf = new FS::Conf; my $error = send_email( diff --git a/FS/FS/part_export/http.pm b/FS/FS/part_export/http.pm index 0be2a0f36..55d832966 100644 --- a/FS/FS/part_export/http.pm +++ b/FS/FS/part_export/http.pm @@ -18,7 +18,7 @@ tie my %options, 'Tie::IxHash', type => 'textarea', default => join("\n", 'DomainName $svc_x->domain', - 'Email ( grep { $_ ne "POST" } $svc_x->cust_svc->cust_pkg->cust_main->invoicing_list)[0]', + 'Email ( grep { $_ !~ /^(POST|FAX)$/ } $svc_x->cust_svc->cust_pkg->cust_main->invoicing_list)[0]', 'test 1', 'reseller $svc_x->cust_svc->cust_pkg->part_pkg->pkg =~ /reseller/i', ), diff --git a/FS/FS/part_export/infostreet.pm b/FS/FS/part_export/infostreet.pm index 309e7ce6f..ef16c7c54 100644 --- a/FS/FS/part_export/infostreet.pm +++ b/FS/FS/part_export/infostreet.pm @@ -67,7 +67,7 @@ sub _export_insert { $_ => $cust_main->getfield( $infostreet2cust_main{$_} ); } keys %infostreet2cust_main ); - my @emails = grep { $_ ne 'POST' } $cust_main->invoicing_list; + my @emails = grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list; $contact_info{'email'} = $emails[0] if @emails; #this one is kinda noment-specific diff --git a/FS/FS/part_export/shellcommands.pm b/FS/FS/part_export/shellcommands.pm index 4f201cf9c..665ec473f 100644 --- a/FS/FS/part_export/shellcommands.pm +++ b/FS/FS/part_export/shellcommands.pm @@ -216,7 +216,7 @@ sub _export_command { my $cust_pkg = $svc_acct->cust_svc->cust_pkg; if ( $cust_pkg ) { - $email = ( grep { $_ ne 'POST' } $cust_pkg->cust_main->invoicing_list )[0]; + $email = ( grep { $_ !~ /^(POST|FAX)$/ } $cust_pkg->cust_main->invoicing_list )[0]; } else { $email = ''; } diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 35596e34b..109ea1d45 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -296,7 +296,7 @@ sub insert { #welcome email my $to = ''; if ( $welcome_template && $cust_pkg ) { - my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ); + my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list ); if ( $to ) { my $wqueue = new FS::queue { 'svcnum' => $self->svcnum, |