X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fbill_batch.pm;h=d4f2aec294401c5ec2276abb00f1d53606ea48ed;hb=3a7f3a2e81cc7423ba9a08fd4b28b3b5f4f227a2;hp=ec5c194562c9e204817eca8e029106ccc3670bdf;hpb=982ded2d929bdcdfa72efa810273f3bc753bf036;p=freeside.git diff --git a/FS/FS/bill_batch.pm b/FS/FS/bill_batch.pm index ec5c19456..d4f2aec29 100644 --- a/FS/FS/bill_batch.pm +++ b/FS/FS/bill_batch.pm @@ -1,16 +1,13 @@ package FS::bill_batch; +use base qw(FS::Record); use strict; -use vars qw( @ISA $me $DEBUG ); +use vars qw( $me $DEBUG ); use CAM::PDF; use FS::Conf; -use FS::Record qw( qsearch qsearchs dbh ); -use FS::agent; -use FS::cust_bill_batch; -@ISA = qw( FS::Record ); $me = '[ FS::bill_batch ]'; -$DEBUG=0; +$DEBUG = 0; sub table { 'bill_batch' } @@ -61,10 +58,11 @@ sub print_pdf { my $self = shift; my $job = shift; $job->update_statustext(0) if $job; - my @invoices = sort { $a->invnum <=> $b->invnum } - qsearch('cust_bill_batch', { batchnum => $self->batchnum }); + my @invoices = sort { $a->invnum <=> $b->invnum } $self->cust_bill_batch; return "No invoices in batch ".$self->batchnum.'.' if !@invoices; + my $duplex = FS::Conf->exists('invoice_print_pdf-duplex'); + my $pdf_out; my $num = 0; foreach my $invoice (@invoices) { @@ -77,6 +75,13 @@ sub print_pdf { else { $pdf_out = CAM::PDF->new($part); } + if ( $duplex ) { + my $n = $pdf_out->numPages; + if ( $n % 2 == 1 ) { + # then insert a blank page so we end on an even number + $pdf_out->duplicatePage($n, 1); + } + } if($job) { # update progressbar $num++; @@ -84,6 +89,7 @@ sub print_pdf { die $error if $error; } } + $job->update_statustext(100, 'Combining invoices') if $job; return $pdf_out->toPDF; } @@ -117,13 +123,6 @@ sub check { Returns the agent (see L) for this invoice batch. -=cut - -sub agent { - my $self = shift; - qsearchs( 'agent', { 'agentnum' => $self->agentnum } ); -} - =back =head1 SUBROUTINES @@ -144,6 +143,11 @@ sub process_print_pdf { my $batch = FS::bill_batch->by_key($param->{batchnum}); die "batch '$param->{batchnum}' not found!\n" if !$batch; + if ( $param->{'close'} ) { + my $error = $batch->close; + die $error if $error; + } + my $pdf = $batch->print_pdf($job); $batch->pdf($pdf); my $error = $batch->replace;