summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlevinse <levinse>2011-02-16 07:39:04 +0000
committerlevinse <levinse>2011-02-16 07:39:04 +0000
commitbc03d12fffd22153b5035bc021450387bacc17b8 (patch)
tree64b94104c0306f0efd485fbf104df51bb006cab7
parentb3c2e70e63eb8f7ab2543a4d400f72bd5044a9f9 (diff)
add barcodes to invoices, HTML part, RT10698
-rw-r--r--FS/FS/cust_bill.pm71
-rw-r--r--conf/invoice_html8
-rwxr-xr-xhttemplate/view/cust_bill-barcode.cgi18
-rwxr-xr-xhttemplate/view/cust_bill.cgi2
4 files changed, 83 insertions, 16 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index af388d3a6..84ef08962 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -989,6 +989,19 @@ sub generate_email {
'Filename' => 'logo.png',
'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',
@@ -1062,7 +1075,12 @@ sub generate_email {
# image/png
$return{'content-type'} = 'multipart/related';
- $return{'mimeparts'} = [ $alternative, $image, @otherparts ];
+ 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';
@@ -2155,19 +2173,7 @@ sub print_latex {
$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)/;
@@ -2180,7 +2186,7 @@ sub print_latex {
# 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);
@@ -2203,6 +2209,35 @@ sub print_latex {
}
+=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.
@@ -2564,6 +2599,10 @@ sub print_generic {
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
@@ -3277,7 +3316,7 @@ sub print_html {
}
$params{'format'} = 'html';
-
+
$self->print_generic( %params );
}
diff --git a/conf/invoice_html b/conf/invoice_html
index 2073d7ff4..fc553d5d5 100644
--- a/conf/invoice_html
+++ b/conf/invoice_html
@@ -78,6 +78,14 @@
: ''
%>
<td align="right">
+ <%=
+ if($barcode_cid) {
+ $OUT .= qq! <img src="cid:$barcode_cid"><br> !;
+ }
+ elsif($barcode_img) {
+ $OUT .= qq! <img src="cust_bill-barcode.cgi?invnum=$invnum;template=$template"><br> !;
+ }
+ %>
Terms: <%= $terms %><BR>
<%= $po_line %>
</td>
diff --git a/httemplate/view/cust_bill-barcode.cgi b/httemplate/view/cust_bill-barcode.cgi
new file mode 100755
index 000000000..dd8f8b814
--- /dev/null
+++ b/httemplate/view/cust_bill-barcode.cgi
@@ -0,0 +1,18 @@
+<% $png %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
+
+my $conf = new FS::Conf;
+
+die 'invalid query' unless $cgi->param('invnum');
+
+my $cust_bill = qsearchs('cust_bill', { 'invnum' => $cgi->param('invnum') } )
+or die 'unknown invnum';
+
+my $png = $cust_bill->invoice_barcode(0);
+
+http_header('Content-Type' => 'image/png' );
+
+</%init>
diff --git a/httemplate/view/cust_bill.cgi b/httemplate/view/cust_bill.cgi
index 0928d04bc..3d3fb7028 100755
--- a/httemplate/view/cust_bill.cgi
+++ b/httemplate/view/cust_bill.cgi
@@ -125,6 +125,8 @@ my %opt = (
'notice_name' => $notice_name,
);
+$opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
+
my @payby = grep /\w/, $conf->config('payby');
#@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH WEST COMP ))
@payby = (qw( CARD DCRD CHEK DCHK LECB BILL CASH COMP ))