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;
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;
104 $self->ut_numbern('batchnum')
105 || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
106 || $self->ut_enum('status', [ 'O', 'R' ] )
108 return $error if $error;
115 Returns the agent (see L<FS::agent>) for this invoice batch.
121 =item process_print_pdf
129 sub process_print_pdf {
131 my $param = thaw(decode_base64(shift));
132 warn Dumper($param) if $DEBUG;
133 die "no batchnum specified!\n" if ! exists($param->{batchnum});
134 my $batch = FS::bill_batch->by_key($param->{batchnum});
135 die "batch '$param->{batchnum}' not found!\n" if !$batch;
137 if ( $param->{'close'} ) {
138 my $error = $batch->close;
139 die $error if $error;
142 my $pdf = $batch->print_pdf($job);
144 my $error = $batch->replace;
145 die $error if $error;
154 L<FS::Record>, schema.html from the base documentation.