From a2b43e372e56297b9900c24145058d4124e5cbeb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 13 Apr 2020 11:13:29 +0200 Subject: [PATCH] =?utf8?q?Mahnungen:=20Optional=20auch=20Original-Rechnung?= =?utf8?q?=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DN.pm | 49 ++++++++++++++++++- bin/mozilla/dn.pl | 1 + locale/de/all | 1 + templates/webpages/dunning/show_invoices.html | 5 ++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/SL/DN.pm b/SL/DN.pm index 4c8001ac8..dd4d61a00 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 { @@ -338,7 +340,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 +350,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 +374,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); @@ -1076,4 +1082,43 @@ 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', + ); + + 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; diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index 0b2b27c58..5cb23000d 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -226,6 +226,7 @@ sub save_dunning { "customer_id" => $form->{"customer_id_$i"}, "language_id" => $form->{"language_id_$i"}, "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"}, + "print_invoice" => $form->{"include_invoice_$i"}, "email" => $form->{"email_$i"}, }; } diff --git a/locale/de/all b/locale/de/all index b25c483ec..295050198 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1653,6 +1653,7 @@ $self->{texts} = { 'Include in drop-down menus' => 'In Aufklappmenü aufnehmen', 'Include invalid warehouses ' => 'Ungültige Lager berücksichtigen', 'Include invoices with direct debit' => 'Inklusive Rechnungen mit Lastschrifteinzug', + 'Include original Invoices?' => 'Original-Rechnung hinzufügen?', 'Includeable in reports' => 'In Berichten anzeigbar', 'Included in reports by default' => 'In Berichten standardmäßig enthalten', 'Including' => 'Enthaltene', diff --git a/templates/webpages/dunning/show_invoices.html b/templates/webpages/dunning/show_invoices.html index 8036ade97..b4128efb3 100644 --- a/templates/webpages/dunning/show_invoices.html +++ b/templates/webpages/dunning/show_invoices.html @@ -28,6 +28,10 @@ [% L.checkbox_tag('selectall_email', checkall='INPUT[name*=email_]', checked=all_email) %] + + [% L.checkbox_tag('selectall_include_invoices', checkall='INPUT[name*=include_invoice_]', checked=all_include_invoices) %] + + [% 'Customername' | $T8 %] [% 'Department' | $T8 %] @@ -63,6 +67,7 @@ + [% HTML.escape(row.customername) %] [% HTML.escape(row.departmentname) %] [% HTML.escape(row.language) %] -- 2.20.1