+sub print_original_invoice {
+ my ($self, $myconfig, $form, $dunning_id, $invoice_id) = @_;
+ # get one invoice as object and print to pdf
+ my $invoice = SL::DB::Invoice->new(id => $invoice_id)->load;
+
+ die "Invalid invoice object" unless ref($invoice) eq 'SL::DB::Invoice';
+
+ my $print_form = Form->new('');
+ $print_form->{type} = 'invoice';
+ $print_form->{formname} = 'invoice',
+ $print_form->{format} = 'pdf',
+ $print_form->{media} = 'file';
+ # no language override, should always be the object's language
+ $invoice->flatten_to_form($print_form, format_amounts => 1);
+ for my $i (1 .. $print_form->{rowcount}) {
+ $print_form->{"sellprice_$i"} = $print_form->{"fxsellprice_$i"};
+ }
+ $print_form->prepare_for_printing;
+
+ my $filename = SL::Helper::CreatePDF->create_pdf(
+ template => 'invoice.tex',
+ variables => $print_form,
+ return => 'file_name',
+ variable_content_types => {
+ longdescription => 'html',
+ partnotes => 'html',
+ notes => 'html',
+ $print_form->get_variable_content_types_for_cvars,
+ },
+ );
+
+ my $spool = $::lx_office_conf{paths}->{spool};
+ my ($volume, $directory, $file_name) = File::Spec->splitpath($filename);
+ my $full_file_name = File::Spec->catfile($spool, $file_name);
+
+ move($filename, $full_file_name) or die "The move operation failed: $!";
+
+ # form get_formname_translation should use language_id_$i
+ my $saved_reicpient_locale = $form->{recipient_locale};
+ $form->{recipient_locale} = $invoice->language;
+
+ my $attachment_filename = $form->get_formname_translation('invoice') . "_" . $invoice->invnumber . ".pdf";
+
+ push @{ $form->{DUNNING_PDFS} }, $file_name;
+ push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$file_name",
+ 'name' => $attachment_filename };
+ push @{ $form->{DUNNING_PDFS_STORAGE} }, { 'dunning_id' => $dunning_id,
+ 'path' => "${spool}/$file_name",
+ 'name' => $attachment_filename };
+
+ $form->{recipient_locale} = $saved_reicpient_locale;
+}
+
+sub _store_pdf_to_webdav_and_filemanagement {
+ my ($dunning_id, $path, $name) =@_;
+
+ my @errors;
+
+ if ($::instance_conf->get_doc_storage) {
+ eval {
+ SL::File->save(
+ object_id => $dunning_id,
+ object_type => 'dunning',
+ mime_type => 'application/pdf',
+ source => 'created',
+ file_type => 'document',
+ file_name => $name,
+ file_path => $path,
+ );
+ 1;
+ } or do {
+ push @errors, $::locale->text('Storing PDF in storage backend failed: #1', $@);
+ };
+ }
+
+ if ($::instance_conf->get_webdav_documents) {
+ eval {
+ my $webdav = SL::Webdav->new(
+ type => 'dunning',
+ number => $dunning_id,
+ );
+ my $webdav_file = SL::Webdav::File->new(
+ webdav => $webdav,
+ filename => $name,
+ );
+ $webdav_file->store(file => $path);
+ } or do {
+ push @errors, $::locale->text('Storing PDF to webdav folder failed: #1', $@);
+ };
+ }
+
+ return @errors;
+}
+
+