1 package SL::Helper::MassPrintCreatePDF;
6 our @EXPORT_OK = qw(create_massprint_pdf merge_massprint_pdf create_pdfs print_pdfs);
10 use SL::Helper::CreatePDF qw(:all);
11 use SL::Helper::File qw(store_pdf append_general_pdf_attachments);
14 my ($self, %params) = @_;
16 foreach my $document (@{ $params{documents} }) {
17 $params{document} = $document;
18 push @pdf_file_names, $self->create_massprint_pdf(%params);
21 return @pdf_file_names;
24 sub create_massprint_pdf {
25 my ($self, %params) = @_;
26 my $form = Form->new('');
29 return => 'file_name',
31 ## find_template may return a list !
32 $create_params{template} = $self->find_template(name => $params{variables}->{formname}, printer_id => $params{printer_id});
33 $form->{cwd}= POSIX::getcwd();
35 $form->{$_} = $params{variables}->{$_} for keys %{ $params{variables} };
37 $create_params{variable_content_types} = $form->get_variable_content_types();
38 $params{document}->flatten_to_form($form, format_amounts => 1);
39 # flatten_to_form sets payment_terms from customer/vendor - we do not want that here
41 delete $form->{payment_terms} if !$form->{payment_id};
43 $form->prepare_for_printing;
44 $form->{attachment_filename} = $form->generate_attachment_filename;
46 my $pdf_filename = $self->create_pdf(%create_params);
48 if ( $::instance_conf->get_doc_storage && ! $form->{preview}) {
49 $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type} );
50 $form->{tmpfile} = $pdf_filename;
51 $form->{id} = $params{document}->id;
52 $self->store_pdf($form);
54 $form->{id} = $params{document}->id;
55 if ( ! $form->{preview} ) {
56 if ( ref($params{document}) eq 'SL::DB::DeliveryOrder' ) {
57 $form->{snumbers} = "ordnumber_" . $params{document}->donumber;
60 $form->{snumbers} = "unknown";
62 $form->{addition} = "PRINTED";
63 $form->{what_done} = $::form->{type};
69 sub merge_massprint_pdf {
70 my ($self, %params) = @_;
71 return unless $params{file_names} && $params{type};
73 my $job_obj = $self->{job_obj};
74 my $data = $job_obj->data_as_hash;
75 my @pdf_file_names = @{$params{file_names}};
78 my $file_name = 'mass_'.$params{type}.'_'.$job_obj->id . '.pdf';
79 my $sfile = SL::SessionFile->new($file_name, mode => 'w', session_id => $data->{session_id});
81 $data->{pdf_file_name} = $sfile->file_name;
83 $self->merge_pdfs(file_names => \@pdf_file_names, bothsided => $data->{bothsided}, out_path => $data->{pdf_file_name});
84 unlink @pdf_file_names;
89 push @{ $data->{print_errors} }, { message => $@ };
92 $job_obj->update_attributes(data_as_hash => $data);
98 my $job_obj = $self->{job_obj};
99 my $data = $job_obj->data_as_hash;
100 my $printer_id = $data->{printer_id};
101 my $copy_printer_id = $data->{copy_printer_id};
103 return if !$printer_id;
107 foreach my $local_printer_id ($printer_id, $copy_printer_id) {
108 next unless $local_printer_id;
110 ->new(id => $local_printer_id)
112 ->print_document(file_name => $data->{pdf_file_name});
125 SL::Helper::MassPrint_CreatePDF
130 This Helper used bei Background Processing for Mass Printing.
131 The redundant way to fill data for createPDF is concentrated into this helper.
132 There are some additional settings for printing which are missed in CreatePDF Helper
133 and also the appending of generic PDF-Documents.
135 (This extension may be included in the CreatePDF Helper).
140 L<SL::Helper::CreatePDF>
144 =head2 C<create_massprint_pdf PARAMS>
146 a tempory $form is used to set
150 =item 1. content types
152 =item 2. flatten_to_form
154 =item 3. prepare_for_printing
160 before printing is done
165 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>