1 package FS::bill_batch;
4 use vars qw( @ISA $me $DEBUG );
7 use FS::Record qw( qsearch qsearchs dbh );
9 use FS::cust_bill_batch;
11 @ISA = qw( FS::Record );
12 $me = '[ FS::bill_batch ]';
15 sub table { 'bill_batch' }
17 sub nohistory_fields { 'pdf' }
21 FS::bill_batch - Object methods for bill_batch records
27 $open_batch = FS::bill_batch->get_open_batch;
29 my $pdf = $open_batch->print_pdf;
31 $error = $open_batch->close;
35 An FS::bill_batch object represents a batch of invoices. FS::bill_batch
36 inherits from FS::Record. The following fields are currently supported:
40 =item batchnum - primary key
42 =item agentnum - empty for global batches or agent (see L<FS::agent>)
44 =item status - either 'O' (open) or 'R' (resolved/closed).
46 =item pdf - blob field for temporarily storing the invoice as a PDF.
56 Typeset the entire batch as a PDF file. Returns the PDF as a string.
63 $job->update_statustext(0) if $job;
64 my @invoices = sort { $a->invnum <=> $b->invnum }
65 qsearch('cust_bill_batch', { batchnum => $self->batchnum });
66 return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
68 my $conf = FS::Conf->new;
69 my $duplex = $conf->exists('invoice_print_pdf-duplex');
73 foreach my $invoice (@invoices) {
74 my $part = $invoice->cust_bill->print_pdf({$invoice->options});
75 die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
78 $pdf_out->appendPDF(CAM::PDF->new($part));
81 $pdf_out = CAM::PDF->new($part);
84 my $n = $pdf_out->numPages;
86 # then insert a blank page so we end on an even number
87 $pdf_out->duplicatePage($n, 1);
93 my $error = $job->update_statustext(int(100 * $num/scalar(@invoices)));
97 $job->update_statustext(100, 'Combining invoices') if $job;
99 return $pdf_out->toPDF;
104 Set the status of the batch to 'R' (resolved).
111 return $self->replace;
118 $self->ut_numbern('batchnum')
119 || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
120 || $self->ut_enum('status', [ 'O', 'R' ] )
122 return $error if $error;
129 Returns the agent (see L<FS::agent>) for this invoice batch.
135 qsearchs( 'agent', { 'agentnum' => $self->agentnum } );
142 =item process_print_pdf
150 sub process_print_pdf {
152 my $param = thaw(decode_base64(shift));
153 warn Dumper($param) if $DEBUG;
154 die "no batchnum specified!\n" if ! exists($param->{batchnum});
155 my $batch = FS::bill_batch->by_key($param->{batchnum});
156 die "batch '$param->{batchnum}' not found!\n" if !$batch;
158 if ( $param->{'close'} ) {
159 my $error = $batch->close;
160 die $error if $error;
163 my $pdf = $batch->print_pdf($job);
165 my $error = $batch->replace;
166 die $error if $error;
175 L<FS::Record>, schema.html from the base documentation.