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.
57 warn "Failed to load CAM::PDF: '$@'\n" if $@;
61 $job->update_statustext(0) if $job;
62 my @invoices = sort { $a->invnum <=> $b->invnum }
63 qsearch('cust_bill_batch', { batchnum => $self->batchnum });
64 return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
68 foreach my $invoice (@invoices) {
69 my $part = $invoice->cust_bill->print_pdf({$invoice->options});
70 die 'Failed creating PDF from invoice '.$invoice->invnum.'\n' if !$part;
73 $pdf_out->appendPDF(CAM::PDF->new($part));
76 $pdf_out = CAM::PDF->new($part);
81 my $error = $job->update_statustext(int(100 * $num/scalar(@invoices)));
86 return $pdf_out->toPDF;
91 Set the status of the batch to 'R' (resolved).
98 return $self->replace;
107 Returns the currently open batch. There should only be one at a time.
113 my $batch = qsearchs('bill_batch', { status => 'O' });
114 return $batch if $batch;
115 $batch = FS::bill_batch->new({status => 'O'});
116 my $error = $batch->insert;
117 die $error if $error;
125 sub process_print_pdf {
127 my $param = thaw(decode_base64(shift));
128 warn Dumper($param) if $DEBUG;
129 die "no batchnum specified!\n" if ! exists($param->{batchnum});
130 my $batch = FS::bill_batch->by_key($param->{batchnum});
131 die "batch '$param->{batchnum}' not found!\n" if !$batch;
133 my $pdf = $batch->print_pdf($job);
135 my $error = $batch->replace;
136 die $error if $error;
146 L<FS::Record>, schema.html from the base documentation.