freeside/FS/FS Conf.pm,1.122,1.123 Misc.pm,1.5,1.6 cust_bill.pm,1.106,1.107 cust_main.pm,1.176,1.177 cust_main_invoice.pm,1.15,1.16 cust_pay.pm,1.37,1.38 cust_pkg.pm,1.57,1.58 svc_acct.pm,1.170,1.171

Kristian Hoffmann khoff at pouncequick.420.am
Mon Mar 21 14:14:10 PST 2005


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv1286/FS/FS

Modified Files:
	Conf.pm Misc.pm cust_bill.pm cust_main.pm cust_main_invoice.pm 
	cust_pay.pm cust_pkg.pm svc_acct.pm 
Log Message:
Added support for FAX invoice destinations using a HylaFAX server.
Faxing plain text invoices is not supported.


Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- cust_pkg.pm	2 Mar 2005 00:47:22 -0000	1.57
+++ cust_pkg.pm	21 Mar 2005 22:13:36 -0000	1.58
@@ -423,7 +423,7 @@
   $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(

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- Conf.pm	18 Mar 2005 19:21:28 -0000	1.122
+++ Conf.pm	21 Mar 2005 22:13:36 -0000	1.123
@@ -1433,6 +1433,13 @@
     '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;

Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- svc_acct.pm	24 Feb 2005 14:22:02 -0000	1.170
+++ svc_acct.pm	21 Mar 2005 22:13:36 -0000	1.171
@@ -296,7 +296,7 @@
     #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,

Index: cust_main_invoice.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main_invoice.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cust_main_invoice.pm	26 Nov 2004 09:39:52 -0000	1.15
+++ cust_main_invoice.pm	21 Mar 2005 22:13:36 -0000	1.16
@@ -43,7 +43,7 @@
 
 =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 @@
   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 @@
 
 =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
 

Index: Misc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Misc.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Misc.pm	17 Mar 2005 21:41:35 -0000	1.5
+++ Misc.pm	21 Mar 2005 22:13:36 -0000	1.6
@@ -5,7 +5,7 @@
 use Exporter;
 
 @ISA = qw( Exporter );
- at EXPORT_OK = qw( send_email );
+ at EXPORT_OK = qw( send_email send_fax );
 
 =head1 NAME
 
@@ -50,6 +50,7 @@
 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 @@
 
 }
 
+=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;
@@ -190,6 +262,8 @@
 =head1 SEE ALSO
 
 L<FS::UID>, L<FS::CGI>, L<FS::Record>, the base documentation.
+
+L<Fax::Hylafax::Client>
 
 =cut
 

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- cust_bill.pm	18 Mar 2005 19:21:28 -0000	1.106
+++ cust_bill.pm	21 Mar 2005 22:13:36 -0000	1.107
@@ -9,7 +9,7 @@
 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 @@
   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 @@
   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 @@
     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 @@
 
   }
 
-  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;
+    }
+
   }
 
   '';

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- cust_main.pm	19 Mar 2005 00:12:24 -0000	1.176
+++ cust_main.pm	21 Mar 2005 22:13:36 -0000	1.177
@@ -2655,6 +2655,11 @@
 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,

Index: cust_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay.pm,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- cust_pay.pm	12 Mar 2005 14:31:47 -0000	1.37
+++ cust_pay.pm	21 Mar 2005 22:13:36 -0000	1.38
@@ -167,7 +167,7 @@
 
   #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 @@
       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;




More information about the freeside-commits mailing list