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;
9 @ISA = qw( FS::Record );
10 $me = '[ FS::bill_batch ]';
13 sub table { 'bill_batch' }
15 sub nohistory_fields { 'pdf' }
19 FS::bill_batch - Object methods for bill_batch records
25 $open_batch = FS::bill_batch->get_open_batch;
27 my $pdf = $open_batch->print_pdf;
29 $error = $open_batch->close;
33 An FS::bill_batch object represents a batch of invoices. FS::bill_batch
34 inherits from FS::Record. The following fields are currently supported:
38 =item batchnum - primary key
40 =item status - either 'O' (open) or 'R' (resolved/closed).
42 =item pdf - blob field for temporarily storing the invoice as a PDF.
52 Typeset the entire batch as a PDF file. Returns the PDF as a string.
59 $job->update_statustext(0) if $job;
60 my @invoices = sort { $a->invnum <=> $b->invnum }
61 qsearch('cust_bill_batch', { batchnum => $self->batchnum });
62 return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
66 foreach my $invoice (@invoices) {
67 my $part = $invoice->cust_bill->print_pdf({$invoice->options});
68 die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
71 $pdf_out->appendPDF(CAM::PDF->new($part));
74 $pdf_out = CAM::PDF->new($part);
79 my $error = $job->update_statustext(int(100 * $num/scalar(@invoices)));
83 $job->update_statustext(100, 'Combining invoices') if $job;
85 return $pdf_out->toPDF;
90 Set the status of the batch to 'R' (resolved).
97 return $self->replace;
106 Returns the currently open batch. There should only be one at a time.
112 my $batch = qsearchs('bill_batch', { status => 'O' });
113 return $batch if $batch;
114 $batch = FS::bill_batch->new({status => 'O'});
115 my $error = $batch->insert;
116 die $error if $error;
124 sub process_print_pdf {
126 my $param = thaw(decode_base64(shift));
127 warn Dumper($param) if $DEBUG;
128 die "no batchnum specified!\n" if ! exists($param->{batchnum});
129 my $batch = FS::bill_batch->by_key($param->{batchnum});
130 die "batch '$param->{batchnum}' not found!\n" if !$batch;
132 if ( $param->{'close'} ) {
133 my $error = $batch->close;
134 die $error if $error;
137 my $pdf = $batch->print_pdf($job);
139 my $error = $batch->replace;
140 die $error if $error;
150 L<FS::Record>, schema.html from the base documentation.