[freeside-commits] freeside/FS/FS Conf.pm, 1.397.2.28, 1.397.2.29 cust_bill.pm, 1.299.2.15, 1.299.2.16
Erik Levinson
levinse at wavetail.420.am
Tue Feb 15 22:21:33 PST 2011
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv14291/FS/FS
Modified Files:
Tag: FREESIDE_2_1_BRANCH
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.397.2.28
retrieving revision 1.397.2.29
diff -u -w -d -r1.397.2.28 -r1.397.2.29
--- Conf.pm 15 Feb 2011 19:02:13 -0000 1.397.2.28
+++ Conf.pm 16 Feb 2011 06:21:31 -0000 1.397.2.29
@@ -662,6 +662,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.299.2.15
retrieving revision 1.299.2.16
diff -u -w -d -r1.299.2.15 -r1.299.2.16
--- cust_bill.pm 5 Feb 2011 06:03:46 -0000 1.299.2.15
+++ cust_bill.pm 16 Feb 2011 06:21:31 -0000 1.299.2.16
@@ -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 );
@@ -2121,6 +2123,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',
@@ -2132,7 +2168,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'});
}
@@ -2495,6 +2531,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
@@ -3141,9 +3179,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;
}
@@ -3169,9 +3208,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