- if (@pdf_file_names) {
- my $data = $job_obj->data_as_hash;
-
- eval {
- $self->{merged_pdf} = $ctrl->merge_pdfs(file_names => \@pdf_file_names);
- unlink @pdf_file_names;
-
- if (!$printer_id) {
- my $file_name = 'mass_invoice' . $job_obj->id . '.pdf';
- my $sfile = SL::SessionFile->new($file_name, mode => 'w');
- $sfile->fh->print($self->{merged_pdf});
- $sfile->fh->close;
-
- $data->{pdf_file_name} = $file_name;
- }
-
- 1;
-
- } or do {
- push @{ $data->{print_errors} }, { message => $@ };
- };
-
- $job_obj->update_attributes(data_as_hash => $data);
- }
-}
-
-sub print_pdfs {
- my ($self) = @_;
-
- my $job_obj = $self->{job_obj};
- my $data = $job_obj->data_as_hash;
- my $printer_id = $data->{printer_id};
- my $copy_printer_id = $data->{copy_printer_id};
-
- return if !$printer_id;
-
- my $out;
-
- foreach my $local_printer_id ($printer_id, $copy_printer_id) {
- next unless $local_printer_id;
- my $printer = SL::DB::Printer->new(id => $local_printer_id)->load;
- my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command);
- if (!open $out, '|-', $command) {
- push @{ $data->{print_errors} }, { message => $::locale->text('Could not execute printer command: #1', $!) };
- $job_obj->update_attributes(data_as_hash => $data);
- return;
- }
- binmode $out;
- print $out $self->{merged_pdf};
- close $out;
- }
-