[freeside-commits] freeside/FS/FS cust_bill.pm, 1.299.2.16, 1.299.2.17

Erik Levinson levinse at wavetail.420.am
Tue Feb 15 23:39:03 PST 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv18719/FS/FS

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	cust_bill.pm 
Log Message:
add barcodes to invoices, HTML part, RT10698

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.299.2.16
retrieving revision 1.299.2.17
diff -u -w -d -r1.299.2.16 -r1.299.2.17
--- cust_bill.pm	16 Feb 2011 06:21:31 -0000	1.299.2.16
+++ cust_bill.pm	16 Feb 2011 07:39:01 -0000	1.299.2.17
@@ -961,6 +961,19 @@
       'Content-ID' => "<$content_id>",
     ;
 
+    my $barcode;
+    if($conf->exists('invoice-barcode')){
+	my $barcode_content_id = join('.', rand()*(2**32), $$, time). "\@$from";
+	$barcode = build MIME::Entity
+	  'Type'       => 'image/png',
+	  'Encoding'   => 'base64',
+	  'Data'       => $self->invoice_barcode(0),
+	  'Filename'   => 'barcode.png',
+	  'Content-ID' => "<$barcode_content_id>",
+	;
+	$opt{'barcode_cid'} = $barcode_content_id;
+    }
+
     $alternative->attach(
       'Type'        => 'text/html',
       'Encoding'    => 'quoted-printable',
@@ -1033,7 +1046,12 @@
       #   image/png
 
       $return{'content-type'} = 'multipart/related';
+      if($conf->exists('invoice-barcode')){
+	  $return{'mimeparts'} = [ $alternative, $image, $barcode, @otherparts ];
+      }
+      else {
       $return{'mimeparts'} = [ $alternative, $image, @otherparts ];
+      }
       $return{'type'} = 'multipart/alternative'; #Content-Type of first part...
       #$return{'disposition'} = 'inline';
 
@@ -2124,19 +2142,7 @@
   $params{'logo_file'} = $lh->filename;
 
   if($conf->exists('invoice-barcode')){
-      my $gdbar = new GD::Barcode('Code39',$self->invnum);
-      die "can't create barcode: " . $GD::Barcode::errStr unless $gdbar;
-      my $gd = $gdbar->plot(Height => 20);
-      my $bh = new File::Temp( TEMPLATE => 'barcode.'. $self->invnum. '.XXXXXXXX',
-                           DIR      => $dir,
-                           SUFFIX   => '.png',
-                           UNLINK   => 0,
-                         ) or die "can't open temp file: $!\n";
-      print $bh $gd->png or die "cannot write barcode to file: $!\n";
-
-      my $png_file = $bh->filename;
-      close $bh;
-
+      my $png_file = $self->invoice_barcode($dir);
       my $eps_file = $png_file;
       $eps_file =~ s/\.png$/.eps/g;
       $png_file =~ /(barcode.*png)/;
@@ -2149,7 +2155,7 @@
       # after painfuly long experimentation, it was determined that sam2p won't
       #	accept : and other chars in the path, no matter how hard I tried to
       # escape them, hence the chdir (and chdir back, just to be safe)
-      system('sam2p', $png_file, 'EPS:', $eps_file ) == 0
+      system('sam2p', '-j:quiet', $png_file, 'EPS:', $eps_file ) == 0
 	or die "sam2p failed: $!\n";
       unlink($png_file);
       chdir($curr_dir);
@@ -2172,6 +2178,35 @@
 
 }
 
+=item invoice_barcode DIR_OR_FALSE
+
+Generates an invoice barcode PNG. If DIR_OR_FALSE is a true value,
+it is taken as the temp directory where the PNG file will be generated and the
+PNG file name is returned. Otherwise, the PNG image itself is returned.
+
+=cut
+
+sub invoice_barcode {
+    my ($self, $dir) = (shift,shift);
+    
+    my $gdbar = new GD::Barcode('Code39',$self->invnum);
+	die "can't create barcode: " . $GD::Barcode::errStr unless $gdbar;
+    my $gd = $gdbar->plot(Height => 30);
+
+    if($dir) {
+	my $bh = new File::Temp( TEMPLATE => 'barcode.'. $self->invnum. '.XXXXXXXX',
+			   DIR      => $dir,
+			   SUFFIX   => '.png',
+			   UNLINK   => 0,
+			 ) or die "can't open temp file: $!\n";
+	print $bh $gd->png or die "cannot write barcode to file: $!\n";
+	my $png_file = $bh->filename;
+	close $bh;
+	return $png_file;
+    }
+    return $gd->png;
+}
+
 =item print_generic OPTION => VALUE ...
 
 Internal method - returns a filled-in template for this invoice as a scalar.
@@ -2533,6 +2568,10 @@
     if $params{'logo_file'};
   $invoice_data{'barcode_file'} = $params{'barcode_file'}
     if $params{'barcode_file'};
+  $invoice_data{'barcode_img'} = $params{'barcode_img'}
+    if $params{'barcode_img'};
+  $invoice_data{'barcode_cid'} = $params{'barcode_cid'}
+    if $params{'barcode_cid'};
 
   my( $pr_total, @pr_cust_bill ) = $self->previous; #previous balance
 #  my( $cr_total, @cr_cust_credit ) = $self->cust_credit; #credits



More information about the freeside-commits mailing list