1 package FS::bill_batch;
2 use base qw(FS::Record);
5 use vars qw( $me $DEBUG );
9 $me = '[ FS::bill_batch ]';
12 sub table { 'bill_batch' }
14 sub nohistory_fields { 'pdf' }
18 FS::bill_batch - Object methods for bill_batch records
24 $open_batch = FS::bill_batch->get_open_batch;
26 my $pdf = $open_batch->print_pdf;
28 $error = $open_batch->close;
32 An FS::bill_batch object represents a batch of invoices. FS::bill_batch
33 inherits from FS::Record. The following fields are currently supported:
37 =item batchnum - primary key
39 =item agentnum - empty for global batches or agent (see L<FS::agent>)
41 =item status - either 'O' (open) or 'R' (resolved/closed).
43 =item pdf - blob field for temporarily storing the invoice as a PDF.
53 Typeset the entire batch as a PDF file. Returns the PDF as a string.
60 $job->update_statustext(0) if $job;
61 my @invoices = sort { $a->invnum <=> $b->invnum } $self->cust_bill_batch;
62 return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
64 my $conf = FS::Conf->new;
65 my $duplex = $conf->exists('invoice_print_pdf-duplex');
69 foreach my $invoice (@invoices) {
70 my $part = $invoice->cust_bill->print_pdf({$invoice->options});
71 die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
74 $pdf_out->appendPDF(CAM::PDF->new($part));
77 $pdf_out = CAM::PDF->new($part);
80 my $n = $pdf_out->numPages;
82 # then insert a blank page so we end on an even number
83 $pdf_out->duplicatePage($n, 1);
89 my $error = $job->update_statustext(int(100 * $num/scalar(@invoices)));
93 $job->update_statustext(100, 'Combining invoices') if $job;
95 return $pdf_out->toPDF;
100 Set the status of the batch to 'R' (resolved).
107 return $self->replace;
114 $self->ut_numbern('batchnum')
115 || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
116 || $self->ut_enum('status', [ 'O', 'R' ] )
118 return $error if $error;
125 Returns the agent (see L<FS::agent>) for this invoice batch.
131 =item process_print_pdf
137 sub process_print_pdf {
140 warn Dumper($param) if $DEBUG;
141 die "no batchnum specified!\n" if ! exists($param->{batchnum});
142 my $batch = FS::bill_batch->by_key($param->{batchnum});
143 die "batch '$param->{batchnum}' not found!\n" if !$batch;
145 if ( $param->{'close'} ) {
146 my $error = $batch->close;
147 die $error if $error;
150 my $pdf = $batch->print_pdf($job);
152 my $error = $batch->replace;
153 die $error if $error;
162 L<FS::Record>, schema.html from the base documentation.