diff --git a/bin/mozilla/sepa.pl b/bin/mozilla/sepa.pl index b73ad257ed..c45b619217 100755 --- a/bin/mozilla/sepa.pl +++ b/bin/mozilla/sepa.pl @@ -606,6 +606,68 @@ sub bank_transfer_download_sepa_xml { $main::lxdebug->leave_sub(); } +sub bank_transfer_download_sepa_docs { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $defaults = SL::DB::Default->get; + my $locale = $main::locale; + my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; + + if (!$defaults->doc_storage) { + $form->show_generic_error($locale->text('Doc Storage is not enabled')); + } + + my @ids; + if ($form->{mode} && ($form->{mode} eq 'multi')) { + @ids = @{ $form->{ids} || [] }; + } else { + @ids = ($form->{id}); + } + + if (!@ids) { + $form->show_generic_error($locale->text('You have not selected any export.')); + } + + my @items = (); + + foreach my $id (@ids) { + my $export = SL::SEPA->retrieve_export('id' => $id, 'details' => 1, vc => $vc); + push @items, @{ $export->{items} } if ($export); + } + my @files; + foreach my $item (@items) { + + # check if there is already a file for the invoice + # File::get_all and converting to scalar is a tiny bit stupid, see Form.pm, + # but there is no get_latest_version (but sorts objects by itime!) + # check if already resynced + my ( $file_object ) = SL::File->get_all(object_id => $item->{ap_id} ? $item->{ap_id} : $item->{ar_id}, + object_type => $item->{ap_id} ? 'purchase_invoice' : 'invoice', + file_type => 'document', + ); + next if (ref $file_object ne 'SL::File::Object'); + next unless $file_object->mime_type eq 'application/pdf'; + + my $file = $file_object->get_file; + die "No file" unless -e $file; + push @files, $file; + } + my $inputfiles = join " ", @files; + my $downloadname = $locale->text('SEPA XML Docs for Exports ') . (join " ", @ids) . ".pdf"; + my $in = IO::File->new($::lx_office_conf{applications}->{ghostscript} . " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=- $inputfiles |"); + + $form->error($main::locale->text('Could not spawn ghostscript.')) unless $in; + + print $::form->create_http_response(content_type => 'Application/PDF', + content_disposition => 'attachment; filename="'. $downloadname . '"'); + + $::locale->with_raw_io(\*STDOUT, sub { print while <$in> }); + $in->close; + + $main::lxdebug->leave_sub(); +} + sub bank_transfer_mark_as_closed { $main::lxdebug->enter_sub(); @@ -643,7 +705,8 @@ sub dispatcher { foreach my $action (qw(bank_transfer_create bank_transfer_edit bank_transfer_list bank_transfer_post_payments bank_transfer_download_sepa_xml bank_transfer_mark_as_closed_step1 bank_transfer_mark_as_closed_step2 - bank_transfer_payment_list_as_pdf bank_transfer_undo_sepa_xml)) { + bank_transfer_payment_list_as_pdf bank_transfer_undo_sepa_xml + bank_transfer_download_sepa_docs)) { if ($form->{"action_${action}"}) { call_sub($action); return; diff --git a/locale/de/all b/locale/de/all index f9205cfa86..06d003c6e0 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1309,6 +1309,7 @@ $self->{texts} = { 'Do you want to overwrite your current title?' => 'Möchten Sie den aktuellen Titel überschreiben?', 'Do you want to set the account number "#1" to "#2" and the name "#3" to "#4"?' => 'Soll die Kontonummer "#1" zu "#2" und den Name "#3" zu "#4" geändert werden?', 'Do you want to store the existing onhand values into a new warehouse?' => 'Möchten Sie die vorhandenen Mengendaten in ein Lager übertragen?', + 'Doc Storage is not enabled' => 'DMS Funktion ist nicht aktiviert', 'Document' => 'Dokument', 'Document Count' => 'Anz. PDF Belege', 'Document Project (database ID)' => 'Projektnummer des Belegs (Datenbank-ID)', @@ -1329,6 +1330,7 @@ $self->{texts} = { 'Done.' => 'Fertig.', 'Double partnumbers' => 'Doppelte Artikelnummern', 'Download' => 'Download', + 'Download Documents for exported bookings' => 'Download hinterlegte PDFs zum aktuellen SEPA-Lauf', 'Download PDF' => 'PDF herunterladen', 'Download PDF, do not print' => 'Nicht drucken, sondern PDF herunterladen', 'Download SEPA XML export file' => 'SEPA-XML-Exportdatei herunterladen', @@ -3341,6 +3343,7 @@ $ ./scripts/installation_check.pl', 'SCREENED' => 'Angezeigt', 'SEPA' => 'SEPA', 'SEPA Transfer Amount' => 'Betrag in offenen SEPA Exporten', + 'SEPA XML Docs for Exports ' => 'SEPA-XML-Dokumente Export-Nummer', 'SEPA XML download' => 'SEPA-XML-Download', 'SEPA creditor ID' => 'SEPA-Kreditoren-Identifikation', 'SEPA exports' => 'SEPA-Exporte', diff --git a/locale/en/all b/locale/en/all index 65ae5643ea..3e4cb8267d 100644 --- a/locale/en/all +++ b/locale/en/all @@ -1308,6 +1308,7 @@ $self->{texts} = { 'Do you want to overwrite your current title?' => '', 'Do you want to set the account number "#1" to "#2" and the name "#3" to "#4"?' => '', 'Do you want to store the existing onhand values into a new warehouse?' => '', + 'Doc Storage is not enabled' => '', 'Document' => '', 'Document Count' => '', 'Document Project (database ID)' => '', @@ -1328,6 +1329,7 @@ $self->{texts} = { 'Done.' => '', 'Double partnumbers' => '', 'Download' => '', + 'Download Documents for exported bookings' => '', 'Download PDF' => '', 'Download PDF, do not print' => '', 'Download SEPA XML export file' => '', @@ -3339,6 +3341,7 @@ $self->{texts} = { 'SCREENED' => '', 'SEPA' => '', 'SEPA Transfer Amount' => '', + 'SEPA XML Docs for Exports ' => '', 'SEPA XML download' => '', 'SEPA creditor ID' => '', 'SEPA exports' => '', diff --git a/templates/design40_webpages/sepa/bank_transfer_created.html b/templates/design40_webpages/sepa/bank_transfer_created.html index 4f831e4616..3738d60e32 100644 --- a/templates/design40_webpages/sepa/bank_transfer_created.html +++ b/templates/design40_webpages/sepa/bank_transfer_created.html @@ -6,5 +6,8 @@

[% title %]

[% 'The SEPA export has been created.' | $T8 %]

diff --git a/templates/webpages/sepa/bank_transfer_created.html b/templates/webpages/sepa/bank_transfer_created.html index e4930156c8..f9c7b6ecc0 100644 --- a/templates/webpages/sepa/bank_transfer_created.html +++ b/templates/webpages/sepa/bank_transfer_created.html @@ -13,7 +13,9 @@

[% title %]

[% 'Download SEPA XML export file' | $T8 %] - + [%- IF INSTANCE_CONF.get_doc_storage %] +
  • [% 'Download Documents for exported bookings' | $T8 %]
  • + [% END %]
  • [% 'List open SEPA exports' | $T8 %]