X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fbill_batch.pm;h=239341cf3fe3a6596ece36cb03c6bb925d2c19a2;hb=091ece4edf3e59b5246d66e2de950e9b234cfaf3;hp=3afe20915907f3b294e70ea93c6445cff14e3c22;hpb=2fd5c89c44d9dfffecc3f93bb13e2e0854db38b5;p=freeside.git diff --git a/FS/FS/bill_batch.pm b/FS/FS/bill_batch.pm index 3afe20915..239341cf3 100644 --- a/FS/FS/bill_batch.pm +++ b/FS/FS/bill_batch.pm @@ -2,9 +2,11 @@ package FS::bill_batch; use strict; use vars qw( @ISA $me $DEBUG ); +use CAM::PDF; +use FS::Conf; use FS::Record qw( qsearch qsearchs dbh ); +use FS::agent; use FS::cust_bill_batch; -use CAM::PDF; @ISA = qw( FS::Record ); $me = '[ FS::bill_batch ]'; @@ -37,6 +39,8 @@ inherits from FS::Record. The following fields are currently supported: =item batchnum - primary key +=item agentnum - empty for global batches or agent (see L) + =item status - either 'O' (open) or 'R' (resolved/closed). =item pdf - blob field for temporarily storing the invoice as a PDF. @@ -61,6 +65,8 @@ sub print_pdf { qsearch('cust_bill_batch', { batchnum => $self->batchnum }); 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) { @@ -73,6 +79,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++; @@ -80,6 +93,7 @@ sub print_pdf { die $error if $error; } } + $job->update_statustext(100, 'Combining invoices') if $job; return $pdf_out->toPDF; } @@ -96,26 +110,38 @@ sub close { return $self->replace; } -=back +sub check { + my $self = shift; -=head1 CLASS METHODS + my $error = + $self->ut_numbern('batchnum') + || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum') + || $self->ut_enum('status', [ 'O', 'R' ] ) + ; + return $error if $error; -=item get_open_batch + $self->SUPER::check; +} -Returns the currently open batch. There should only be one at a time. +=item agent + +Returns the agent (see L) for this invoice batch. =cut -sub get_open_batch { - my $class = shift; - my $batch = qsearchs('bill_batch', { status => 'O' }); - return $batch if $batch; - $batch = FS::bill_batch->new({status => 'O'}); - my $error = $batch->insert; - die $error if $error; - return $batch; +sub agent { + my $self = shift; + qsearchs( 'agent', { 'agentnum' => $self->agentnum } ); } +=back + +=head1 SUBROUTINES + +=item process_print_pdf + +=cut + use Storable 'thaw'; use Data::Dumper; use MIME::Base64; @@ -128,13 +154,17 @@ 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; die $error if $error; } - =back =head1 BUGS