Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 65922b0d

Von Martin Helmling martin.helmling@octosoft.eu vor fast 8 Jahren hinzugefügt

  • ID 65922b0d6c4a14e29354f65c60dea2176d10f941
  • Vorgänger 54ce5144
  • Nachfolger fd2e0902

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)

Unterschiede anzeigen:

SL/Controller/DownloadZip.pm
1
package SL::Controller::DownloadZip;
2

  
3
use strict;
4

  
5
use parent qw(SL::Controller::Base);
6

  
7
use List::Util qw(first max);
8

  
9
use utf8;
10
use Encode qw(decode encode);
11
use Archive::Zip;
12
use SL::File;
13
use SL::SessionFile::Random;
14

  
15
sub action_download_orderitems_files {
16
  my ($self) = @_;
17

  
18
  #
19
  # special case for customer which want to have not all
20
  # in kivitendo.conf some regex may be defined:
21
  # For no values just let it commented out
22
  # PA = Produktionsauftrag, L = Lieferschein, ML = Materialliste
23
  # If you want several options, please seperate the letter with '|'. Example: '^(PA|L).*'
24
  #set_sales_documenttype_for_delivered_quantity = '^(LS).*'
25
  #set_purchase_documenttype_for_delivered_quantity = '^(EL).*'
26
  #
27
  # enbale this perl code:
28
  #  my $doctype = $::lx_office_conf{system}->{"set_documenttype_for_part_zip_download"};
29
  #  if ( $doctype ) {
30
  #    # eliminate first and last char (are quotes)
31
  #    $doctype =~ s/^.//;
32
  #    $doctype =~ s/.$//;
33
  #  }
34

  
35
  #$Archive::Zip::UNICODE = 1;
36

  
37
  my $object_id    = $::form->{object_id};
38
  my $object_type  = $::form->{object_type};
39
  my $element_type = $::form->{element_type};
40
  my $sfile = SL::SessionFile::Random->new(mode => "w");
41
  my $zip = Archive::Zip->new();
42
  #TODO Check client encoding !!
43
  #my $name_encoding = 'cp850';
44
  my $name_encoding = 'UTF-8';
45

  
46
  # today only sales_order implementation !
47
  if ( $object_id && $object_type eq 'sales_order' && $element_type eq 'part' ) {
48
    my $orderitems = SL::DB::Manager::OrderItem->get_all(query => ['order.id' => $object_id ],
49
                                                         with_objects => [ 'order', 'part' ],
50
                                                         sort_by => 'part.partnumber ASC');
51
    my $part_id = 0;
52
    foreach my $item ( @{$orderitems} ) {
53
      next if $part_id == $item->parts_id;
54

  
55
      my @files = SL::File->get_all(object_id   => $item->parts_id,
56
                                    object_type => $element_type,
57
                                  );
58
      my @wanted_files;
59
      ## also for filtering if needed:
60
      # if ( $doctype ) {
61
      #   @wanted_files = grep { $_->{file_name} =~ /$doctype/ } @files;
62
      # } else {
63
      @wanted_files = @files;
64
      # }
65
      if ( scalar (@wanted_files) > 0 ) {
66
        $zip->addDirectory($item->part->partnumber);
67
        $zip->addFile(SL::File->get_file_path(dbfile => $_ ),
68
                      Encode::encode($name_encoding,$item->part->partnumber.'/'.$_->{file_name})
69
                      ) for @wanted_files;
70
      }
71
    }
72
  }
73
  unless ( $zip->writeToFileNamed($sfile->file_name) == Archive::Zip::AZ_OK ) {
74
    die 'zipfile write error';
75
  }
76
  $sfile->fh->close;
77

  
78
  return $self->send_file(
79
    $sfile->file_name,
80
    type => 'application/zip',
81
    name => $::form->{zipname}.'.zip',
82
  );
83
}
84

  
85
1;
86

  
87
__END__
88

  
89
=pod
90

  
91
=encoding utf-8
92

  
93
=head1 NAME
94

  
95
SL::Controller::DownloadZip - controller for download all files from parts of an order in one zip file
96

  
97
=head2  C<action_download_zip FORMPARAMS>
98

  
99
Some customer want all attached files for the parts of an sales order or sales delivery order in one zip to download.
100
This is a special method for one customer, so it is moved into an extra controller.
101
The $Archive::Zip::UNICODE = 1; doesnt work ok
102
So today the filenames in cp850/DOS format for legacy windows.
103
To ues it for Linux Clients an additinal effort must be done,
104
for ex. a link to the same file with an utf-8 name.
105

  
106
There is also a special javascript method necessary which calles this controller method.
107
THis method must be inserted into the customer branch:
108

  
109
=begin text
110

  
111
  ns.downloadOrderitemsAtt = function(type,id) {
112
    var rowcount  = $('input[name=rowcount]').val() - 1;
113
	  var data = {
114
        action:     'FileManagement/download_zip',
115
        type:       type,
116
        object_id:  id,
117
        rowcount:   rowcount
118
    };
119
    if ( rowcount == 0 ) {
120
        kivi.display_flash('error', kivi.t8('No articles have been added yet.'));
121
        return false; 
122
    }
123
    for (var i = 1; i <= rowcount; i++) {
124
        data['parts_id_'+i] =  $('#id_' + i).val();
125
    };
126
    $.download("controller.pl", data);
127
    return false;
128
  }
129

  
130
=end text
131

  
132
See also L<SL::Controller::FileManagement>
133

  
134
=head1 DISCUSSION
135

  
136
Is this method needed in the master branch ?
137

  
138
=head1 AUTHOR
139

  
140
Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
141

  
142
=cut
js/kivi.File.js
235 235
    return true;
236 236
  }
237 237

  
238
  ns.downloadOrderitemsFiles = function(type,id) {
239
	  var data = {
240
      action:       'DownloadZip/download_orderitems_files',
241
      object_type:  type,
242
      object_id:    id,
243
      element_type: 'part',
244
      zipname:      'Order_Files_'+id,
245
    };
246
    $.download("controller.pl", data);
247
    return false;
248
  }
249

  
238 250

  
239 251
  ns.init = function() {
240 252
  }
js/locale/de.js
57 57
"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.",
58 58
"Map":"Karte",
59 59
"No":"Nein",
60
"No articles have been added yet.":"Es wurden noch keine Artikel hinzugefügt.",
60 61
"No delievery orders selected, please set one checkbox!":"Kein Lieferschein selektiert, bitte eine Box anklicken!",
61 62
"No delivery orders have been selected.":"Es wurden keine Lieferscheine ausgewählt.",
62 63
"No entries have been selected.":"Es wurden keine Einträge ausgewählt.",
locale/de/all
1006 1006
  'Download PDF'                => 'PDF herunterladen',
1007 1007
  'Download PDF, do not print'  => 'Nicht drucken, sondern PDF herunterladen',
1008 1008
  'Download SEPA XML export file' => 'SEPA-XML-Exportdatei herunterladen',
1009
  'Download all Attachments'    => 'Herunterladen der Dateianhänge aller Artikel',
1009 1010
  'Download picture'            => 'Bild herunterladen',
1010 1011
  'Download sample file'        => 'Beispieldatei herunterladen',
1011 1012
  'Draft deleted'               => 'Entwurf gelöscht',
templates/webpages/oe/form_footer.html
148 148
    [% 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) %]
149 149
[% END %]
150 150

  
151
[%- IF id AND INSTANCE_CONF.get_doc_storage %]
152
  <input type="button" class="submit"onclick="kivi.File.downloadOrderitemsFiles('[% type %]',[% id %]);" name="action_download_files" value="[% 'Download all Attachments' | $T8 %]">
153
[%- END %]
151 154
[%- IF id %]
152 155
  <input type="button" class="submit" onclick="follow_up_window()" value="[% 'Follow-Up' | $T8 %]">
153 156
  <input type="button" class="submit" onclick="set_history_window([% HTML.escape(id) %], 'id')" name="history" id="history" value="[% 'history' | $T8 %]">
templates/webpages/order/form.html
53 53
[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %]
54 54
  [% L.button_tag('kivi.Order.delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %]
55 55
[%- END %]
56
[%- IF SELF.order.id && INSTANCE_CONF.get_doc_storage %]
57
  [% L.button_tag('kivi.File.downloadOrderitemsFiles(\'' _ SELF.order.type _'\',' _ SELF.order.id _')',LxERP.t8('Download all Attachments')) %]
58
[%- END %]
56 59

  
57 60
</form>

Auch abrufbar als: Unified diff