1 package SL::Helper::MassPrintCreatePDF;
8 our @EXPORT_OK = qw(create_massprint_pdf merge_massprint_pdf create_pdfs print_pdfs);
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 record => $params{document},
30 return => 'file_name',
32 ## find_template may return a list !
33 $create_params{template} = $self->find_template(name => $params{variables}->{formname}, printer_id => $params{printer_id});
34 $form->{cwd}= POSIX::getcwd();
36 $form->{$_} = $params{variables}->{$_} for keys %{ $params{variables} };
38 $create_params{variable_content_types} = $form->get_variable_content_types();
39 $params{document}->flatten_to_form($form, format_amounts => 1);
40 # flatten_to_form sets payment_terms from customer/vendor - we do not want that here
42 delete $form->{payment_terms} if !$form->{payment_id};
43 for my $i (1 .. $form->{rowcount}) {
44 $form->{"sellprice_$i"} = $form->{"fxsellprice_$i"};
47 $form->prepare_for_printing;
49 $form->{language} = '_' . $form->{language};
50 $form->{attachment_filename} = $form->generate_attachment_filename;
52 my $pdf_filename = $self->create_pdf(%create_params);
54 if ($::instance_conf->get_webdav_documents && !$form->{preview}) {
55 my $webdav = SL::Webdav->new(
56 type => $params{document}->type,
57 number => $params{document}->record_number,
59 my $webdav_file = SL::Webdav::File->new(
61 filename => $form->{attachment_filename},
64 $webdav_file->store(file => $pdf_filename);
67 push @{ $params{errors} }, $@ if exists $params{errors};
71 if ( $::instance_conf->get_doc_storage && ! $form->{preview}) {
72 $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type} );
73 $form->{tmpfile} = $pdf_filename;
74 $form->{id} = $params{document}->id;
75 $self->store_pdf($form);
77 $form->{id} = $params{document}->id;
78 if ( ! $form->{preview} ) {
79 if ( ref($params{document}) eq 'SL::DB::DeliveryOrder' ) {
80 $form->{snumbers} = "ordnumber_" . $params{document}->donumber;
83 $form->{snumbers} = "unknown";
85 $form->{addition} = "PRINTED";
86 $form->{what_done} = $::form->{type};
92 sub merge_massprint_pdf {
93 my ($self, %params) = @_;
94 return unless $params{file_names} && $params{type};
96 my $job_obj = $self->{job_obj};
97 my $data = $job_obj->data_as_hash;
98 my @pdf_file_names = @{$params{file_names}};
101 my $file_name = 'mass_'.$params{type}.'_'.$job_obj->id . '.pdf';
102 my $sfile = SL::SessionFile->new($file_name, mode => 'w', session_id => $data->{session_id});
104 $data->{pdf_file_name} = $sfile->file_name;
106 $self->merge_pdfs(file_names => \@pdf_file_names, bothsided => $data->{bothsided}, out_path => $data->{pdf_file_name});
107 unlink @pdf_file_names;
112 push @{ $data->{print_errors} }, { message => $@ };
115 $job_obj->update_attributes(data_as_hash => $data);
121 my $job_obj = $self->{job_obj};
122 my $data = $job_obj->data_as_hash;
123 my $printer_id = $data->{printer_id};
124 my $copy_printer_id = $data->{copy_printer_id};
126 return if !$printer_id;
130 foreach my $local_printer_id ($printer_id, $copy_printer_id) {
131 next unless $local_printer_id;
133 ->new(id => $local_printer_id)
135 ->print_document(file_name => $data->{pdf_file_name});
148 SL::Helper::MassPrint_CreatePDF
153 This Helper used bei Background Processing for Mass Printing.
154 The redundant way to fill data for createPDF is concentrated into this helper.
155 There are some additional settings for printing which are missed in CreatePDF Helper
156 and also the appending of generic PDF-Documents.
158 (This extension may be included in the CreatePDF Helper).
163 L<SL::Helper::CreatePDF>
167 =head2 C<create_massprint_pdf PARAMS>
169 a tempory $form is used to set
173 =item 1. content types
175 =item 2. flatten_to_form
177 =item 3. prepare_for_printing
183 before printing is done
185 Recognized parameters are (not a complete list):
189 =item * C<errors> – optional. If given, it must be an array ref. This will be
190 filled with potential errors.
197 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>