+ if ($form->{cp_id}) {
+ $custom_variables = CVar->get_custom_variables(dbh => $form->get_standard_dbh,
+ module => 'Contacts',
+ trans_id => $form->{cp_id});
+ $form->{"cp_cvar_$_->{name}"} = $_->{value} for @{ $custom_variables };
+ }
+
+}
+
+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;