1 package FS::bill_batch;
4 use vars qw( @ISA $me $DEBUG );
5 use FS::Record qw( qsearch qsearchs dbh );
6 use FS::cust_bill_batch;
8 @ISA = qw( FS::Record );
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 status - either 'O' (open) or 'R' (resolved/closed).
41 =item pdf - blob field for temporarily storing the invoice as a PDF.
51 Typeset the entire batch as a PDF file. Returns the PDF as a string.
58 die "CAM::PDF not installed\n" if $@ =~ /^Can't locate/;
59 die "Failed to load CAM::PDF: '$@'\n";
64 $job->update_statustext(0) if $job;
65 my @invoices = sort { $a->invnum <=> $b->invnum }
66 qsearch('cust_bill_batch', { batchnum => $self->batchnum });
67 return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
71 foreach my $invoice (@invoices) {
72 my $part = $invoice->cust_bill->print_pdf({$invoice->options});
73 die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
76 $pdf_out->appendPDF(CAM::PDF->new($part));
79 $pdf_out = CAM::PDF->new($part);
84 my $error = $job->update_statustext(int(100 * $num/scalar(@invoices)));
89 return $pdf_out->toPDF;
94 Set the status of the batch to 'R' (resolved).
101 return $self->replace;
110 Returns the currently open batch. There should only be one at a time.
116 my $batch = qsearchs('bill_batch', { status => 'O' });
117 return $batch if $batch;
118 $batch = FS::bill_batch->new({status => 'O'});
119 my $error = $batch->insert;
120 die $error if $error;
128 sub process_print_pdf {
130 my $param = thaw(decode_base64(shift));
131 warn Dumper($param) if $DEBUG;
132 die "no batchnum specified!\n" if ! exists($param->{batchnum});
133 my $batch = FS::bill_batch->by_key($param->{batchnum});
134 die "batch '$param->{batchnum}' not found!\n" if !$batch;
136 my $pdf = $batch->print_pdf($job);
138 my $error = $batch->replace;
139 die $error if $error;
149 L<FS::Record>, schema.html from the base documentation.