From: Martin Helmling martin.helmling@octosoft.eu Date: Tue, 27 Dec 2016 13:20:36 +0000 (+0100) Subject: Dateimanagement: Alle Dokumente/Anhänge von Artikeln eines Auftrags als ZIP X-Git-Tag: release-3.5.4~1592 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=65922b0d6c4a14e29354f65c60dea2176d10f941;p=kivitendo-erp.git Dateimanagement: Alle Dokumente/Anhänge von Artikeln eines Auftrags als ZIP Es wird eine ZIP-Datei aller Dateien gemacht. (Die Prüfung welcher Zeichensatz für die Dateinamen im ZIP verwendet werden soll ist noch nicht implementiert) --- diff --git a/SL/Controller/DownloadZip.pm b/SL/Controller/DownloadZip.pm new file mode 100644 index 000000000..5bac4ba2e --- /dev/null +++ b/SL/Controller/DownloadZip.pm @@ -0,0 +1,142 @@ +package SL::Controller::DownloadZip; + +use strict; + +use parent qw(SL::Controller::Base); + +use List::Util qw(first max); + +use utf8; +use Encode qw(decode encode); +use Archive::Zip; +use SL::File; +use SL::SessionFile::Random; + +sub action_download_orderitems_files { + my ($self) = @_; + + # + # special case for customer which want to have not all + # in kivitendo.conf some regex may be defined: + # For no values just let it commented out + # PA = Produktionsauftrag, L = Lieferschein, ML = Materialliste + # If you want several options, please seperate the letter with '|'. Example: '^(PA|L).*' + #set_sales_documenttype_for_delivered_quantity = '^(LS).*' + #set_purchase_documenttype_for_delivered_quantity = '^(EL).*' + # + # enbale this perl code: + # my $doctype = $::lx_office_conf{system}->{"set_documenttype_for_part_zip_download"}; + # if ( $doctype ) { + # # eliminate first and last char (are quotes) + # $doctype =~ s/^.//; + # $doctype =~ s/.$//; + # } + + #$Archive::Zip::UNICODE = 1; + + my $object_id = $::form->{object_id}; + my $object_type = $::form->{object_type}; + my $element_type = $::form->{element_type}; + my $sfile = SL::SessionFile::Random->new(mode => "w"); + my $zip = Archive::Zip->new(); + #TODO Check client encoding !! + #my $name_encoding = 'cp850'; + my $name_encoding = 'UTF-8'; + + # today only sales_order implementation ! + if ( $object_id && $object_type eq 'sales_order' && $element_type eq 'part' ) { + my $orderitems = SL::DB::Manager::OrderItem->get_all(query => ['order.id' => $object_id ], + with_objects => [ 'order', 'part' ], + sort_by => 'part.partnumber ASC'); + my $part_id = 0; + foreach my $item ( @{$orderitems} ) { + next if $part_id == $item->parts_id; + + my @files = SL::File->get_all(object_id => $item->parts_id, + object_type => $element_type, + ); + my @wanted_files; + ## also for filtering if needed: + # if ( $doctype ) { + # @wanted_files = grep { $_->{file_name} =~ /$doctype/ } @files; + # } else { + @wanted_files = @files; + # } + if ( scalar (@wanted_files) > 0 ) { + $zip->addDirectory($item->part->partnumber); + $zip->addFile(SL::File->get_file_path(dbfile => $_ ), + Encode::encode($name_encoding,$item->part->partnumber.'/'.$_->{file_name}) + ) for @wanted_files; + } + } + } + unless ( $zip->writeToFileNamed($sfile->file_name) == Archive::Zip::AZ_OK ) { + die 'zipfile write error'; + } + $sfile->fh->close; + + return $self->send_file( + $sfile->file_name, + type => 'application/zip', + name => $::form->{zipname}.'.zip', + ); +} + +1; + +__END__ + +=pod + +=encoding utf-8 + +=head1 NAME + +SL::Controller::DownloadZip - controller for download all files from parts of an order in one zip file + +=head2 C + +Some customer want all attached files for the parts of an sales order or sales delivery order in one zip to download. +This is a special method for one customer, so it is moved into an extra controller. +The $Archive::Zip::UNICODE = 1; doesnt work ok +So today the filenames in cp850/DOS format for legacy windows. +To ues it for Linux Clients an additinal effort must be done, +for ex. a link to the same file with an utf-8 name. + +There is also a special javascript method necessary which calles this controller method. +THis method must be inserted into the customer branch: + +=begin text + + ns.downloadOrderitemsAtt = function(type,id) { + var rowcount = $('input[name=rowcount]').val() - 1; + var data = { + action: 'FileManagement/download_zip', + type: type, + object_id: id, + rowcount: rowcount + }; + if ( rowcount == 0 ) { + kivi.display_flash('error', kivi.t8('No articles have been added yet.')); + return false; + } + for (var i = 1; i <= rowcount; i++) { + data['parts_id_'+i] = $('#id_' + i).val(); + }; + $.download("controller.pl", data); + return false; + } + +=end text + +See also L + +=head1 DISCUSSION + +Is this method needed in the master branch ? + +=head1 AUTHOR + +Martin Helmling Emartin.helmling@opendynamic.deE + +=cut diff --git a/js/kivi.File.js b/js/kivi.File.js index 036cefee6..68ef7ac52 100644 --- a/js/kivi.File.js +++ b/js/kivi.File.js @@ -235,6 +235,18 @@ namespace('kivi.File', function(ns) { return true; } + ns.downloadOrderitemsFiles = function(type,id) { + var data = { + action: 'DownloadZip/download_orderitems_files', + object_type: type, + object_id: id, + element_type: 'part', + zipname: 'Order_Files_'+id, + }; + $.download("controller.pl", data); + return false; + } + ns.init = function() { } diff --git a/js/locale/de.js b/js/locale/de.js index 71749f7d4..702d42933 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -57,6 +57,7 @@ namespace("kivi").setupLocale({ "If you switch to a different tab without saving you will lose the data you've entered in the current tab.":"Wenn Sie auf einen anderen Tab wechseln, ohne vorher zu speichern, so gehen die im aktuellen Tab eingegebenen Daten verloren.", "Map":"Karte", "No":"Nein", +"No articles have been added yet.":"Es wurden noch keine Artikel hinzugefügt.", "No delievery orders selected, please set one checkbox!":"Kein Lieferschein selektiert, bitte eine Box anklicken!", "No delivery orders have been selected.":"Es wurden keine Lieferscheine ausgewählt.", "No entries have been selected.":"Es wurden keine Einträge ausgewählt.", diff --git a/locale/de/all b/locale/de/all index 9cf72dd7a..52973e76d 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1006,6 +1006,7 @@ $self->{texts} = { 'Download PDF' => 'PDF herunterladen', 'Download PDF, do not print' => 'Nicht drucken, sondern PDF herunterladen', 'Download SEPA XML export file' => 'SEPA-XML-Exportdatei herunterladen', + 'Download all Attachments' => 'Herunterladen der Dateianhänge aller Artikel', 'Download picture' => 'Bild herunterladen', 'Download sample file' => 'Beispieldatei herunterladen', 'Draft deleted' => 'Entwurf gelöscht', diff --git a/templates/webpages/oe/form_footer.html b/templates/webpages/oe/form_footer.html index 86910e0ab..d58ab7416 100644 --- a/templates/webpages/oe/form_footer.html +++ b/templates/webpages/oe/form_footer.html @@ -148,6 +148,9 @@ [% L.submit_tag('action_save_and_close', LxERP.t8('Save and close'), confirm=LxERP.t8('Missing transport cost: #1 Are you sure?', tpca_reminder), 'data-require-transaction-description'=INSTANCE_CONF.get_require_transaction_description_ps, 'data-warn-save-active-periodic-invoice'=warn_save_active_periodic_invoice) %] [% END %] +[%- IF id AND INSTANCE_CONF.get_doc_storage %] + +[%- END %] [%- IF id %] diff --git a/templates/webpages/order/form.html b/templates/webpages/order/form.html index 46258ae41..9f8c4c68e 100644 --- a/templates/webpages/order/form.html +++ b/templates/webpages/order/form.html @@ -53,5 +53,8 @@ [%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %] [% L.button_tag('kivi.Order.delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %] [%- END %] +[%- IF SELF.order.id && INSTANCE_CONF.get_doc_storage %] + [% L.button_tag('kivi.File.downloadOrderitemsFiles(\'' _ SELF.order.type _'\',' _ SELF.order.id _')',LxERP.t8('Download all Attachments')) %] +[%- END %]