[freeside-commits] freeside/FS/FS Conf.pm, 1.429, 1.430 cust_bill.pm, 1.316, 1.317
Erik Levinson
levinse at wavetail.420.am
Tue Feb 15 22:21:31 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv14289/FS/FS
Modified Files:
Conf.pm cust_bill.pm
Log Message:
add barcodes to invoices, PDF part, RT10698
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.429
retrieving revision 1.430
diff -u -w -d -r1.429 -r1.430
--- Conf.pm 15 Feb 2011 19:02:09 -0000 1.429
+++ Conf.pm 16 Feb 2011 06:21:28 -0000 1.430
@@ -669,6 +669,13 @@
},
{
+ 'key' => 'invoice-barcode',
+ 'section' => 'billing',
+ 'description' => 'Display a barcode on HTML and PDF invoices',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'encryption',
'section' => 'billing',
'description' => 'Enable encryption of credit cards.',
Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.316
retrieving revision 1.317
diff -u -w -d -r1.316 -r1.317
--- cust_bill.pm 5 Feb 2011 06:03:50 -0000 1.316
+++ cust_bill.pm 16 Feb 2011 06:21:28 -0000 1.317
@@ -13,6 +13,7 @@
use HTML::Entities;
use Locale::Country;
use Storable qw( freeze thaw );
+use GD::Barcode;
use FS::UID qw( datasrc );
use FS::Misc qw( send_email send_fax generate_ps generate_pdf do_print );
use FS::Record qw( qsearch qsearchs dbh );
@@ -37,6 +38,7 @@
use FS::payby;
use FS::bill_batch;
use FS::cust_bill_batch;
+use Cwd;
@ISA = qw( FS::cust_main_Mixin FS::Record );
@@ -2152,6 +2154,40 @@
close $lh;
$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 $eps_file = $png_file;
+ $eps_file =~ s/\.png$/.eps/g;
+ $png_file =~ /(barcode.*png)/;
+ $png_file = $1;
+ $eps_file =~ /(barcode.*eps)/;
+ $eps_file = $1;
+
+ my $curr_dir = cwd();
+ chdir($dir);
+ # 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
+ or die "sam2p failed: $!\n";
+ unlink($png_file);
+ chdir($curr_dir);
+
+ $params{'barcode_file'} = $eps_file;
+ }
+
my @filled_in = $self->print_generic( %params );
my $fh = new File::Temp( TEMPLATE => 'invoice.'. $self->invnum. '.XXXXXXXX',
@@ -2163,7 +2199,7 @@
close $fh;
$fh->filename =~ /^(.*).tex$/ or die "unparsable filename: ". $fh->filename;
- return ($1, $params{'logo_file'});
+ return ($1, $params{'logo_file'}, $params{'barcode_file'});
}
@@ -2526,6 +2562,8 @@
$invoice_data{'logo_file'} = $params{'logo_file'}
if $params{'logo_file'};
+ $invoice_data{'barcode_file'} = $params{'barcode_file'}
+ if $params{'barcode_file'};
my( $pr_total, @pr_cust_bill ) = $self->previous; #previous balance
# my( $cr_total, @cr_cust_credit ) = $self->cust_credit; #credits
@@ -3172,9 +3210,10 @@
sub print_ps {
my $self = shift;
- my ($file, $lfile) = $self->print_latex(@_);
+ my ($file, $logofile, $barcodefile) = $self->print_latex(@_);
my $ps = generate_ps($file);
- unlink($lfile);
+ unlink($logofile);
+ unlink($barcodefile);
$ps;
}
@@ -3200,9 +3239,10 @@
sub print_pdf {
my $self = shift;
- my ($file, $lfile) = $self->print_latex(@_);
+ my ($file, $logofile, $barcodefile) = $self->print_latex(@_);
my $pdf = generate_pdf($file);
- unlink($lfile);
+ unlink($logofile);
+ unlink($barcodefile);
$pdf;
}
More information about the freeside-commits
mailing list