two-sided printing of invoice batches, #29927
authorMark Wells <mark@freeside.biz>
Sun, 10 Aug 2014 00:39:27 +0000 (17:39 -0700)
committerMark Wells <mark@freeside.biz>
Sun, 10 Aug 2014 00:39:41 +0000 (17:39 -0700)
FS/FS/Conf.pm
FS/FS/bill_batch.pm
FS/FS/cust_bill.pm

index 35b88ea..3d7ffe7 100644 (file)
@@ -1527,6 +1527,13 @@ and customer address. Include units.',
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'invoice_print_pdf-duplex',
+    'section'     => 'invoicing',
+    'description' => 'Insert blank pages so that spooled invoices are each an even number of pages.  Use this for double-sided printing.',
+    'type'        => 'checkbox',
+  },
+
   { 
     'key'         => 'invoice_default_terms',
     'section'     => 'invoicing',
index 1a46db0..239341c 100644 (file)
@@ -65,6 +65,8 @@ sub print_pdf {
                  qsearch('cust_bill_batch', { batchnum => $self->batchnum });
   return "No invoices in batch ".$self->batchnum.'.' if !@invoices;
 
+  my $duplex = FS::Conf->exists('invoice_print_pdf-duplex');
+
   my $pdf_out;
   my $num = 0;
   foreach my $invoice (@invoices) {
@@ -77,6 +79,13 @@ sub print_pdf {
     else {
       $pdf_out = CAM::PDF->new($part);
     }
+    if ( $duplex ) {
+      my $n = $pdf_out->numPages;
+      if ( $n % 2 == 1 ) {
+        # then insert a blank page so we end on an even number
+        $pdf_out->duplicatePage($n, 1);
+      }
+    }
     if($job) {
       # update progressbar
       $num++;
index 7f1290f..31422f0 100644 (file)
@@ -1565,6 +1565,8 @@ sub fax_invoice {
 Place this invoice into the open batch (see C<FS::bill_batch>).  If there 
 isn't an open batch, one will be created.
 
+HASHREF may contain any options to be passed to C<print_pdf>.
+
 =cut
 
 sub batch_invoice {