Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b1b3cdeb

Von Bernd Bleßmann vor fast 9 Jahren hinzugefügt

  • ID b1b3cdebde020c32eb5d0e39e9e6139e1508b9f7
  • Vorgänger 46d3bb6e
  • Nachfolger b2242cae

Auftrags-Controller: Druck-Möglichkeit mit Options

Todos/Anmerkungen
- im Moment werden nur PDF/Bildschirm und PDF/Drucker unterstützt
- Sprache kann die Vorlage steuern, aber nicht das Hinzufügen von übersetzten
Artikeln
- es kann sicher noch mehr ausgelagert werden, entweder in den
PrintOptions-Helper oder in einen PrintOptions-Controller, der
dann auch noch mehr machen könnte
- E-Mail ist nicht berücksichtigt bzw. wird im Controller getrennt behandelt

Unterschiede anzeigen:

SL/Controller/Order.pm
10 10
use SL::PriceSource;
11 11
use SL::Form;
12 12
use SL::Webdav;
13
use SL::Template;
13 14

  
14 15
use SL::DB::Order;
15 16
use SL::DB::Customer;
......
21 22
use SL::DB::Unit;
22 23
use SL::DB::Price;
23 24
use SL::DB::Part;
25
use SL::DB::Printer;
26
use SL::DB::Language;
24 27

  
25 28
use SL::Helper::DateTime;
26 29
use SL::Helper::CreatePDF qw(:all);
30
use SL::Helper::PrintOptions;
27 31

  
28 32
use SL::Controller::Helper::GetModels;
29 33

  
......
43 47
__PACKAGE__->run_before('_check_auth');
44 48

  
45 49
__PACKAGE__->run_before('_recalc',
46
                        only => [ qw(update save save_and_delivery_order create_pdf send_email) ]);
50
                        only => [ qw(update save save_and_delivery_order print create_pdf send_email) ]);
47 51

  
48 52
__PACKAGE__->run_before('_get_unalterable_data',
49
                        only => [ qw(save save_and_delivery_order create_pdf send_email) ]);
53
                        only => [ qw(save save_and_delivery_order print create_pdf send_email) ]);
50 54

  
51 55
#
52 56
# actions
......
135 139
  $self->redirect_to(@redirect_params);
136 140
}
137 141

  
138
sub action_create_pdf {
142
sub action_print {
139 143
  my ($self) = @_;
140 144

  
141
  my $pdf;
142
  my @errors = _create_pdf($self->order, \$pdf);
143
  if (scalar @errors) {
144
    return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self);
145
  my $format      = $::form->{print_options}->{format};
146
  my $media       = $::form->{print_options}->{media};
147
  my $formname    = $::form->{print_options}->{formname};
148
  my $copies      = $::form->{print_options}->{copies};
149
  my $groupitems  = $::form->{print_options}->{groupitems};
150

  
151
  # only pdf by now
152
  if (none { $format eq $_ } qw(pdf)) {
153
    return $self->js->flash('error', t8('Format \'#1\' is not supported yet/anymore.', $format))->render;
145 154
  }
146 155

  
147
  my $sfile = SL::SessionFile::Random->new(mode => "w");
148
  $sfile->fh->print($pdf);
149
  $sfile->fh->close;
156
  # only screen or printer by now
157
  if (none { $media eq $_ } qw(screen printer)) {
158
    return $self->js->flash('error', t8('Media \'#1\' is not supported yet/anymore.', $media))->render;
159
  }
150 160

  
151
  my $key = join('_', Time::HiRes::gettimeofday(), int rand 1000000000000);
152
  $::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name);
161
  my $language;
162
  $language = SL::DB::Language->new(id => $::form->{print_options}->{language_id})->load if $::form->{print_options}->{language_id};
153 163

  
154 164
  my $form = Form->new;
155 165
  $form->{ordnumber} = $self->order->ordnumber;
156
  $form->{formname}  = $self->type;
157 166
  $form->{type}      = $self->type;
158
  $form->{language}  = 'de';
159
  $form->{format}    = 'pdf';
167
  $form->{format}    = $format;
168
  $form->{formname}  = $formname;
169
  $form->{language}  = '_' . $language->template_code if $language;
170
  my $pdf_filename   = $form->generate_attachment_filename();
171

  
172
  my $pdf;
173
  my @errors = _create_pdf($self->order, \$pdf, { format     => $format,
174
                                                  formname   => $formname,
175
                                                  language   => $language,
176
                                                  groupitems => $groupitems });
177
  if (scalar @errors) {
178
    return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render;
179
  }
180

  
181
  if ($media eq 'screen') {
182
    # screen/download
183
    my $sfile = SL::SessionFile::Random->new(mode => "w");
184
    $sfile->fh->print($pdf);
185
    $sfile->fh->close;
186

  
187
    my $key = join('_', Time::HiRes::gettimeofday(), int rand 1000000000000);
188
    $::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name);
189

  
190
    $self->js
191
    ->run('download_pdf', $pdf_filename, $key)
192
    ->flash('info', t8('The PDF has been created'));
193

  
194
  } elsif ($media eq 'printer') {
195
    # printer
196
    my $printer_id = $::form->{print_options}->{printer_id};
197
    my $printer;
198
    $printer = SL::DB::Printer->new(id => $printer_id)->load if $printer_id;
199
    if (!$printer) {
200
      return $self->js->flash('error', t8('Printer not found.'))->render;
201
    }
202

  
203
    my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command);
160 204

  
161
  my $pdf_filename = $form->generate_attachment_filename();
205
    for my $i (1 .. $copies) {
206
      open my $out, '|-', $command or die $!;
207
      binmode $out;
208
      print $out $pdf;
209
      close $out;
210
    }
211

  
212
    $self->js->flash('info', t8('The PDF has been printed'));
213
  }
162 214

  
163 215
  # copy file to webdav folder
164 216
  if ($self->order->ordnumber && $::instance_conf->get_webdav_documents) {
......
178 230
    }
179 231
  }
180 232

  
181
  $self->js
182
    ->run('download_pdf', $pdf_filename, $key)
183
    ->flash('info', t8('The PDF has been created'))->render($self);
233
  $self->js->render;
184 234
}
185 235

  
186 236
sub action_download_pdf {
......
853 903

  
854 904
  $self->{current_employee_id} = SL::DB::Manager::Employee->current->id;
855 905

  
906
  my $print_form = Form->new('');
907
  $print_form->{type}      = $self->type;
908
  $print_form->{printers}  = SL::DB::Manager::Printer->get_all_sorted;
909
  $print_form->{languages} = SL::DB::Manager::Language->get_all_sorted;
910
  $self->{print_options}   = SL::Helper::PrintOptions->get_print_options(
911
    form => $print_form,
912
    options => {dialog_name_prefix => 'print_options.',
913
                show_headers       => 1,
914
                no_queue           => 1,
915
                no_postscript      => 1,
916
                no_opendocument    => 1,
917
                no_html            => 1},
918
  );
919

  
856 920
  foreach my $item (@{$self->order->orderitems}) {
857 921
    my $price_source = SL::PriceSource->new(record_item => $item, record => $self->order);
858 922
    $item->active_price_source(   $price_source->price_from_source(   $item->active_price_source   ));
......
878 942
sub _create_pdf {
879 943
  my ($order, $pdf_ref, $params) = @_;
880 944

  
945
  my @errors = ();
946

  
881 947
  my $print_form = Form->new('');
882
  $print_form->{type}     = $order->type;
883
  $print_form->{formname} = $order->type;
884
  $print_form->{format}   = $params->{format} || 'pdf',
885
  $print_form->{media}    = $params->{media}  || 'file';
948
  $print_form->{type}        = $order->type;
949
  $print_form->{formname}    = $params->{formname} || $order->type;
950
  $print_form->{format}      = $params->{format}   || 'pdf';
951
  $print_form->{media}       = $params->{media}    || 'file';
952
  $print_form->{groupitems}  = $params->{groupitems};
953
  $print_form->{media}       = 'file'                             if $print_form->{media} eq 'screen';
954
  $print_form->{language}    = $params->{language}->template_code if $print_form->{language};
955
  $print_form->{language_id} = $params->{language}->id            if $print_form->{language};
886 956

  
887 957
  $order->flatten_to_form($print_form, format_amounts => 1);
888 958
  # flatten_to_form sets payment_terms from customer/vendor - we do not want that here
889 959
  delete $print_form->{payment_terms} if !$print_form->{payment_id};
890 960

  
891
  my @errors = ();
961
  # search for the template
962
  my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template(
963
    name        => $print_form->{formname},
964
    email       => $print_form->{media} eq 'email',
965
    language    => $params->{language},
966
    printer_id  => $print_form->{printer_id},  # todo
967
  );
968

  
969
  if (!defined $template_file) {
970
    push @errors, $::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files);
971
  }
972

  
973
  return @errors if scalar @errors;
974

  
892 975
  $print_form->throw_on_error(sub {
893 976
    eval {
894 977
      $print_form->prepare_for_printing;
895 978

  
896 979
      $$pdf_ref = SL::Helper::CreatePDF->create_pdf(
897
        template  => SL::Helper::CreatePDF->find_template(name => $print_form->{formname}),
980
        template  => $template_file,
898 981
        variables => $print_form,
899 982
        variable_content_types => {
900 983
          longdescription => 'html',
js/locale/de.js
56 56
"Please select a customer.":"Bitte wählen Sie einen Kunden aus.",
57 57
"Please select a vendor.":"Bitte wählen Sie einen Lieferanten aus.",
58 58
"Price Types":"Preistypen",
59
"Print options":"Druckoptionen",
59 60
"Project link actions":"Projektverknüpfungs-Aktionen",
60 61
"Quotations/Orders actions":"Aktionen für Angebote/Aufträge",
61 62
"Re-numbering all sections and function blocks in the order they are currently shown cannot be undone.":"Das Neu-Nummerieren aller Abschnitte und Funktionsblöcke kann nicht rückgängig gemacht werden.",
locale/de/all
1287 1287
  'Foreign Exchange Gain'       => 'Wechselkurserträge',
1288 1288
  'Foreign Exchange Loss'       => 'Wechselkursaufwendungen',
1289 1289
  'Form details (second row)'   => 'Formulardetails (zweite Positionszeile)',
1290
  'Format \'#1\' is not supported yet/anymore.' => 'Das Format \'#1\' wird noch nicht oder nicht mehr unterstützt.',
1290 1291
  'Formula'                     => 'Formel',
1291 1292
  'Found #1 errors.'            => '#1 Fehler gefunden.',
1292 1293
  'Found #1 objects of which #2 can be imported.' => 'Es wurden #1 Objekte gefunden, von denen #2 importiert werden können.',
......
1660 1661
  'May '                        => 'Mai',
1661 1662
  'May set the BCC field when sending emails' => 'Beim Verschicken von E-Mails das Feld \'BCC\' setzen',
1662 1663
  'Meaning'                     => 'Bedeutung',
1664
  'Media \'#1\' is not supported yet/anymore.' => 'Das Medium \'#1\' wird noch nicht oder nicht mehr unterstützt.',
1663 1665
  'Medium Number'               => 'Datenträgernummer',
1664 1666
  'Memo'                        => 'Memo',
1665 1667
  'Message'                     => 'Nachricht',
......
2102 2104
  'Printer Description'         => 'Druckerbeschreibung',
2103 2105
  'Printer Management'          => 'Druckeradministration',
2104 2106
  'Printer management'          => 'Druckerverwaltung',
2107
  'Printer not found.'          => 'Drucker nicht gefunden.',
2105 2108
  'Printing ... '               => 'Es wird gedruckt.',
2106 2109
  'Printing invoices (this can take a while)' => 'Drucke Rechnungen (kann eine Weile dauern)',
2107 2110
  'Prior year'                  => 'Vorheriges Jahr',
......
2696 2699
  'The LDAP server "#1:#2" is unreachable. Please check config/kivitendo.conf.' => 'Der LDAP-Server "#1:#2" ist nicht erreichbar. Bitte überprüfen Sie die Angaben in config/kivitendo.conf.',
2697 2700
  'The MT940 import needs an import profile called MT940' => 'Der MT940 Import benötigt ein Importprofil mit dem Namen "MT940"',
2698 2701
  'The PDF has been created'    => 'Die PDF-Datei wurde erstellt.',
2702
  'The PDF has been printed'    => 'Das PDF-Dokument wurde gedruckt.',
2699 2703
  'The SEPA export has been created.' => 'Der SEPA-Export wurde erstellt',
2700 2704
  'The SEPA strings have been saved.' => 'Die bei SEPA-Überweisungen verwendeten Begriffe wurden gespeichert.',
2701 2705
  'The WebDAV feature has been used.' => 'Das WebDAV-Feature wurde benutzt.',
templates/webpages/order/form.html
2 2
[%- USE LxERP %]
3 3
[%- USE L %]
4 4

  
5
<div id="print_options" style="display:none">
6
  <form method="post" action="controller.pl" id="print_options_form">
7
    [% SELF.print_options %]
8
    <br>
9
    [% L.button_tag('print()', LxERP.t8('Print')) %]
10
    <a href="#" onclick="$('#print_options').dialog('close');">[% LxERP.t8("Cancel") %]</a>
11
  </form>
12
</div>
13

  
5 14
<form method="post" action="controller.pl" id="order_form">
6 15
  <div class="listtop">[% FORM.title %]</div>
7 16

  
......
31 40
  [% L.hidden_tag('action', 'Order/dispatch') %]
32 41

  
33 42
  [% L.button_tag('save()', LxERP.t8('Save')) %]
34
  [% L.button_tag('create_pdf()', LxERP.t8('Create PDF')) %]
43
  [% L.button_tag('show_print_options()', LxERP.t8('Print')) %]
35 44
  [% L.button_tag('email()', LxERP.t8('E-mail')) %]
36 45
  [% L.button_tag('save_and_delivery_order()', LxERP.t8('Save and Delivery Order')) %]
37 46
[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %]
......
58 67
  $.post("controller.pl", data, kivi.eval_json_result);
59 68
}
60 69

  
61
function create_pdf() {
70
function show_print_options() {
62 71
  if (!check_cv()) return;
72

  
73
  kivi.popup_dialog({
74
    id: 'print_options',
75
    dialog: {
76
      title: kivi.t8('Print options'),
77
      width:  800,
78
      height: 300
79
    }
80
  });
81
}
82

  
83
function print() {
84
  $('#print_options').dialog('close');
85

  
63 86
  var data = $('#order_form').serializeArray();
64
  data.push({ name: 'action', value: 'Order/create_pdf' });
87
  data = data.concat($('#print_options_form').serializeArray());
88
  data.push({ name: 'action', value: 'Order/print' });
65 89

  
66 90
  $.post("controller.pl", data, kivi.eval_json_result);
67 91
}

Auch abrufbar als: Unified diff