projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
RT# 78190 Remove debug statements
[freeside.git]
/
FS
/
FS
/
bill_batch.pm
diff --git
a/FS/FS/bill_batch.pm
b/FS/FS/bill_batch.pm
index
136db0d
..
827c102
100644
(file)
--- a/
FS/FS/bill_batch.pm
+++ b/
FS/FS/bill_batch.pm
@@
-1,13
+1,13
@@
package FS::bill_batch;
package FS::bill_batch;
+use base qw(FS::Record);
use strict;
use strict;
-use vars qw(
@ISA
$me $DEBUG );
-use
FS::Record qw( qsearch qsearchs dbh )
;
-use FS::
cust_bill_batch
;
+use vars qw( $me $DEBUG );
+use
CAM::PDF
;
+use FS::
Conf
;
-@ISA = qw( FS::Record );
$me = '[ FS::bill_batch ]';
$me = '[ FS::bill_batch ]';
-$DEBUG
=
0;
+$DEBUG
=
0;
sub table { 'bill_batch' }
sub table { 'bill_batch' }
@@
-36,6
+36,8
@@
inherits from FS::Record. The following fields are currently supported:
=item batchnum - primary key
=item batchnum - primary key
+=item agentnum - empty for global batches or agent (see L<FS::agent>)
+
=item status - either 'O' (open) or 'R' (resolved/closed).
=item pdf - blob field for temporarily storing the invoice as a PDF.
=item status - either 'O' (open) or 'R' (resolved/closed).
=item pdf - blob field for temporarily storing the invoice as a PDF.
@@
-53,35
+55,44
@@
Typeset the entire batch as a PDF file. Returns the PDF as a string.
=cut
sub print_pdf {
=cut
sub print_pdf {
- eval 'use CAM::PDF';
- warn "Failed to load CAM::PDF: '$@'\n" if $@;
-
my $self = shift;
my $job = shift;
$job->update_statustext(0) if $job;
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 });
- return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
+ my @cust_bill_batch = sort { $a->invnum <=> $b->invnum }
+ $self->cust_bill_batch;
+ return "No invoices in batch ".$self->batchnum.'.' if !@cust_bill_batch;
+
+ my $conf = FS::Conf->new;
+ my $duplex = $conf->exists('invoice_print_pdf-duplex');
my $pdf_out;
my $num = 0;
my $pdf_out;
my $num = 0;
- foreach my $invoice (@invoices) {
- my $part = $invoice->cust_bill->print_pdf({$invoice->options});
- die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
+ foreach my $cust_bill_batch (@cust_bill_batch) {
+ my $part =
+ $cust_bill_batch->cust_bill->print_pdf({$cust_bill_batch->options});
+ die 'Failed creating PDF from invoice '.$cust_bill_batch->invnum.'\n'
+ if !$part;
if($pdf_out) {
$pdf_out->appendPDF(CAM::PDF->new($part));
if($pdf_out) {
$pdf_out->appendPDF(CAM::PDF->new($part));
- }
- else {
+ } else {
$pdf_out = CAM::PDF->new($part);
}
$pdf_out = CAM::PDF->new($part);
}
- if($job) {
+ 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++;
# update progressbar
$num++;
- my $error = $job->update_statustext(int(100 * $num/scalar(@
invoices
)));
+ my $error = $job->update_statustext(int(100 * $num/scalar(@
cust_bill_batch
)));
die $error if $error;
}
}
die $error if $error;
}
}
+ $job->update_statustext(100, 'Combining invoices') if $job;
return $pdf_out->toPDF;
}
return $pdf_out->toPDF;
}
@@
-98,45
+109,52
@@
sub close {
return $self->replace;
}
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
-=cut
+Returns the agent (see L<FS::agent>) for this invoice batch.
-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;
-}
+=back
+
+=head1 SUBROUTINES
+
+=item process_print_pdf
+
+=cut
-use Storable 'thaw';
use Data::Dumper;
use Data::Dumper;
-use MIME::Base64;
sub process_print_pdf {
my $job = shift;
sub process_print_pdf {
my $job = shift;
- my $param =
thaw(decode_base64(shift))
;
+ my $param =
shift
;
warn Dumper($param) if $DEBUG;
die "no batchnum specified!\n" if ! exists($param->{batchnum});
my $batch = FS::bill_batch->by_key($param->{batchnum});
die "batch '$param->{batchnum}' not found!\n" if !$batch;
warn Dumper($param) if $DEBUG;
die "no batchnum specified!\n" if ! exists($param->{batchnum});
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;
}
my $pdf = $batch->print_pdf($job);
$batch->pdf($pdf);
my $error = $batch->replace;
die $error if $error;
}
-
=back
=head1 BUGS
=back
=head1 BUGS