X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDN.pm;h=ee06cd8f913271d6d279e4c4dc9a95b0617ea7a4;hb=cbbe00ccddaac72d03a759996e7d55315aff9a5e;hp=4c8001ac85b0ab7665b32d2f1d4185368dc9d4ff;hpb=4aa9760e3d155fccea859b2c56f75946c12633f9;p=kivitendo-erp.git diff --git a/SL/DN.pm b/SL/DN.pm index 4c8001ac8..ee06cd8f9 100644 --- a/SL/DN.pm +++ b/SL/DN.pm @@ -51,6 +51,8 @@ use SL::TransNumber; use SL::Util qw(trim); use SL::DB; +use File::Copy; + use strict; sub get_config { @@ -109,7 +111,8 @@ sub _save_config { $form->{"template_$i"}, $form->{"fee_$i"}, $form->{"interest_rate_$i"}, $form->{"active_$i"} ? 't' : 'f', $form->{"auto_$i"} ? 't' : 'f', $form->{"email_$i"} ? 't' : 'f', $form->{"email_attachment_$i"} ? 't' : 'f', conv_i($form->{"payment_terms_$i"}), conv_i($form->{"terms_$i"}), - $form->{"create_invoices_for_fees_$i"} ? 't' : 'f'); + $form->{"create_invoices_for_fees_$i"} ? 't' : 'f', + $form->{"print_original_invoice_$i"} ? 't' : 'f'); if ($form->{"id_$i"}) { $query = qq|UPDATE dunning_config SET @@ -118,7 +121,8 @@ sub _save_config { template = ?, fee = ?, interest_rate = ?, active = ?, auto = ?, email = ?, email_attachment = ?, payment_terms = ?, terms = ?, - create_invoices_for_fees = ? + create_invoices_for_fees = ?, + print_original_invoice = ? WHERE id = ?|; push(@values, conv_i($form->{"id_$i"})); } else { @@ -126,8 +130,9 @@ sub _save_config { qq|INSERT INTO dunning_config (dunning_level, dunning_description, email_subject, email_body, template, fee, interest_rate, active, auto, email, - email_attachment, payment_terms, terms, create_invoices_for_fees) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; + email_attachment, payment_terms, terms, create_invoices_for_fees, + print_original_invoice) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; } do_query($form, $dbh, $query, @values); } @@ -338,7 +343,7 @@ sub _save_dunning { my @invoice_ids; my ($next_dunning_config_id, $customer_id); - my $send_email = 0; + my ($send_email, $print_invoice) = (0, 0); foreach my $row (@{ $rows }) { push @invoice_ids, $row->{invoice_id}; @@ -348,7 +353,8 @@ sub _save_dunning { @values = ($row->{next_dunning_config_id}, $row->{invoice_id}); do_statement($form, $h_update_ar, $q_update_ar, @values); - $send_email |= $row->{email}; + $send_email |= $row->{email}; + $print_invoice |= $row->{print_invoice}; my $next_config_id = conv_i($row->{next_dunning_config_id}); my $invoice_id = conv_i($row->{invoice_id}); @@ -371,6 +377,9 @@ sub _save_dunning { $self->print_invoice_for_fees($myconfig, $form, $dunning_id, $dbh); $self->print_dunning($myconfig, $form, $dunning_id, $dbh); + if ($print_invoice) { + $self->print_original_invoices($myconfig, $form, $_, $dbh) for @invoice_ids; + } if ($send_email) { $self->send_email($myconfig, $form, $dunning_id, $dbh); @@ -591,7 +600,7 @@ sub get_invoices { nextcfg.dunning_description AS next_dunning_description, nextcfg.id AS next_dunning_config_id, - nextcfg.terms, nextcfg.active, nextcfg.email + nextcfg.terms, nextcfg.active, nextcfg.email, nextcfg.print_original_invoice FROM ar a @@ -1076,4 +1085,48 @@ sub set_customer_cvars { } +sub print_original_invoices { + my ($self, $myconfig, $form, $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); + $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', + }, + ); + + 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; + + push @{ $form->{DUNNING_PDFS} }, $file_name; + push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'path' => "${spool}/$file_name", + 'name' => $form->get_formname_translation('invoice') . "_" . $invoice->invnumber . ".pdf" }; + + $form->{recipient_locale} = $saved_reicpient_locale; +} + 1;