Revision aa36021a
Von Bernd Bleßmann vor fast 9 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
5 | 5 |
|
6 | 6 |
use SL::Helper::Flash; |
7 | 7 |
use SL::Presenter; |
8 |
use SL::Locale::String; |
|
9 |
use SL::SessionFile::Random; |
|
8 | 10 |
use SL::PriceSource; |
11 |
use SL::Form; |
|
9 | 12 |
|
10 | 13 |
use SL::DB::Order; |
11 | 14 |
use SL::DB::Customer; |
... | ... | |
17 | 20 |
use SL::DB::Unit; |
18 | 21 |
|
19 | 22 |
use SL::Helper::DateTime; |
23 |
use SL::Helper::CreatePDF qw(:all); |
|
20 | 24 |
|
21 | 25 |
use List::Util qw(max first); |
22 | 26 |
use List::MoreUtils qw(none pairwise); |
27 |
use English qw(-no_match_vars); |
|
28 |
use File::Spec; |
|
23 | 29 |
|
24 | 30 |
use Rose::Object::MakeMethods::Generic |
25 | 31 |
( |
... | ... | |
31 | 37 |
__PACKAGE__->run_before('_check_auth'); |
32 | 38 |
|
33 | 39 |
__PACKAGE__->run_before('_recalc', |
34 |
only => [ qw(edit update save) ]); |
|
40 |
only => [ qw(edit update save create_pdf send_email) ]);
|
|
35 | 41 |
|
36 | 42 |
__PACKAGE__->run_before('_get_unalterable_data', |
37 | 43 |
only => [ qw(save save_and_delivery_order create_pdf send_email) ]); |
... | ... | |
120 | 126 |
$self->redirect_to(@redirect_params); |
121 | 127 |
} |
122 | 128 |
|
129 |
sub action_create_pdf { |
|
130 |
my ($self) = @_; |
|
131 |
|
|
132 |
my $pdf; |
|
133 |
my @errors = _create_pdf($self->order, \$pdf); |
|
134 |
if (scalar @errors) { |
|
135 |
return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self); |
|
136 |
} |
|
137 |
|
|
138 |
my $sfile = SL::SessionFile::Random->new(mode => "w"); |
|
139 |
$sfile->fh->print($pdf); |
|
140 |
$sfile->fh->close; |
|
141 |
|
|
142 |
my $key = join('_', Time::HiRes::gettimeofday(), int rand 1000000000000); |
|
143 |
$::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name); |
|
144 |
|
|
145 |
my $form = Form->new; |
|
146 |
$form->{ordnumber} = $self->order->ordnumber; |
|
147 |
$form->{formname} = $self->type; |
|
148 |
$form->{type} = $self->type; |
|
149 |
$form->{language} = 'de'; |
|
150 |
$form->{format} = 'pdf'; |
|
151 |
|
|
152 |
my $pdf_filename = $form->generate_attachment_filename(); |
|
153 |
|
|
154 |
$self->js |
|
155 |
->run('download_pdf', $pdf_filename, $key) |
|
156 |
->flash('info', t8('The PDF has been created'))->render($self); |
|
157 |
} |
|
158 |
|
|
159 |
sub action_download_pdf { |
|
160 |
my ($self) = @_; |
|
161 |
|
|
162 |
my $key = $::form->{key}; |
|
163 |
my $tmp_filename = $::auth->get_session_value("Order::create_pdf-${key}"); |
|
164 |
return $self->send_file( |
|
165 |
$tmp_filename, |
|
166 |
type => 'application/pdf', |
|
167 |
name => $::form->{pdf_filename}, |
|
168 |
); |
|
169 |
} |
|
170 |
|
|
171 |
sub action_show_email_dialog { |
|
172 |
my ($self) = @_; |
|
173 |
|
|
174 |
my $cv_method = $self->cv; |
|
175 |
|
|
176 |
if (!$self->order->$cv_method) { |
|
177 |
return $self->js->flash('error', $self->cv eq 'customer' ? t8('Cannot send E-mail without customer given') : t8('Cannot send E-mail without vendor given')) |
|
178 |
->render($self); |
|
179 |
} |
|
180 |
|
|
181 |
$self->{email}->{to} = $self->order->contact->cp_email if $self->order->contact; |
|
182 |
$self->{email}->{to} ||= $self->order->$cv_method->email; |
|
183 |
$self->{email}->{cc} = $self->order->$cv_method->cc; |
|
184 |
$self->{email}->{bcc} = join ', ', grep $_, $self->order->$cv_method->bcc, SL::DB::Default->get->global_bcc; |
|
185 |
# Todo: get addresses from shipto, if any |
|
186 |
|
|
187 |
my $form = Form->new; |
|
188 |
$form->{ordnumber} = $self->order->ordnumber; |
|
189 |
$form->{formname} = $self->type; |
|
190 |
$form->{type} = $self->type; |
|
191 |
$form->{language} = 'de'; |
|
192 |
$form->{format} = 'pdf'; |
|
193 |
|
|
194 |
$self->{email}->{subject} = $form->generate_email_subject(); |
|
195 |
$self->{email}->{attachment_filename} = $form->generate_attachment_filename(); |
|
196 |
$self->{email}->{message} = $form->create_email_signature(); |
|
197 |
|
|
198 |
my $dialog_html = $self->render('order/tabs/_email_dialog', { output => 0 }); |
|
199 |
$self->js |
|
200 |
->run('show_email_dialog', $dialog_html) |
|
201 |
->reinit_widgets |
|
202 |
->render($self); |
|
203 |
} |
|
204 |
|
|
205 |
# Todo: handling error messages: flash is not displayed in dialog, but in the main form |
|
206 |
sub action_send_email { |
|
207 |
my ($self) = @_; |
|
208 |
|
|
209 |
my $mail = Mailer->new; |
|
210 |
$mail->{from} = qq|"$::myconfig{name}" <$::myconfig{email}>|; |
|
211 |
$mail->{$_} = $::form->{email}->{$_} for qw(to cc bcc subject message); |
|
212 |
|
|
213 |
my $pdf; |
|
214 |
my @errors = _create_pdf($self->order, \$pdf, {media => 'email'}); |
|
215 |
if (scalar @errors) { |
|
216 |
return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self); |
|
217 |
} |
|
218 |
|
|
219 |
$mail->{attachments} = [{ "content" => $pdf, |
|
220 |
"name" => $::form->{email}->{attachment_filename} }]; |
|
221 |
|
|
222 |
if (my $err = $mail->send) { |
|
223 |
return $self->js->flash('error', t8('Sending E-mail: ') . $err) |
|
224 |
->render($self); |
|
225 |
} |
|
226 |
|
|
227 |
# internal notes |
|
228 |
my $intnotes = $self->order->intnotes; |
|
229 |
$intnotes .= "\n\n" if $self->order->intnotes; |
|
230 |
$intnotes .= t8('[email]') . "\n"; |
|
231 |
$intnotes .= t8('Date') . ": " . $::locale->format_date_object(DateTime->now_local, precision => 'seconds') . "\n"; |
|
232 |
$intnotes .= t8('To (email)') . ": " . $mail->{to} . "\n"; |
|
233 |
$intnotes .= t8('Cc') . ": " . $mail->{cc} . "\n" if $mail->{cc}; |
|
234 |
$intnotes .= t8('Bcc') . ": " . $mail->{bcc} . "\n" if $mail->{bcc}; |
|
235 |
$intnotes .= t8('Subject') . ": " . $mail->{subject} . "\n\n"; |
|
236 |
$intnotes .= t8('Message') . ": " . $mail->{message}; |
|
237 |
|
|
238 |
$self->js |
|
239 |
->val('#order_intnotes', $intnotes) |
|
240 |
->run('close_email_dialog') |
|
241 |
->render($self); |
|
242 |
} |
|
243 |
|
|
244 |
|
|
123 | 245 |
sub action_customer_vendor_changed { |
124 | 246 |
my ($self) = @_; |
125 | 247 |
|
... | ... | |
452 | 574 |
$::request->{layout}->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery); |
453 | 575 |
} |
454 | 576 |
|
577 |
sub _create_pdf { |
|
578 |
my ($order, $pdf_ref, $params) = @_; |
|
579 |
|
|
580 |
my $print_form = Form->new(''); |
|
581 |
$print_form->{type} = $order->type; |
|
582 |
$print_form->{formname} = $order->type; |
|
583 |
$print_form->{format} = $params->{format} || 'pdf', |
|
584 |
$print_form->{media} = $params->{media} || 'file'; |
|
585 |
|
|
586 |
$order->flatten_to_form($print_form, format_amounts => 1); |
|
587 |
# flatten_to_form sets payment_terms from customer/vendor - we do not want that here |
|
588 |
delete $print_form->{payment_terms} if !$print_form->{payment_id}; |
|
589 |
|
|
590 |
my @errors = (); |
|
591 |
$print_form->throw_on_error(sub { |
|
592 |
eval { |
|
593 |
$print_form->prepare_for_printing; |
|
594 |
|
|
595 |
$$pdf_ref = SL::Helper::CreatePDF->create_pdf( |
|
596 |
template => SL::Helper::CreatePDF->find_template(name => $print_form->{formname}), |
|
597 |
variables => $print_form, |
|
598 |
variable_content_types => { |
|
599 |
longdescription => 'html', |
|
600 |
partnotes => 'html', |
|
601 |
notes => 'html', |
|
602 |
}, |
|
603 |
); |
|
604 |
1; |
|
605 |
} || push @errors, ref($EVAL_ERROR) eq 'SL::X::FormError' ? $EVAL_ERROR->getMessage : $EVAL_ERROR; |
|
606 |
}); |
|
607 |
|
|
608 |
return @errors; |
|
609 |
} |
|
610 |
|
|
455 | 611 |
sub _sales_order_type { |
456 | 612 |
'sales_order'; |
457 | 613 |
} |
locale/de/all | ||
---|---|---|
497 | 497 |
'Cannot save order!' => 'Auftrag kann nicht gespeichert werden!', |
498 | 498 |
'Cannot save preferences!' => 'Einstellungen können nicht gespeichert werden!', |
499 | 499 |
'Cannot save quotation!' => 'Angebot kann nicht gespeichert werden!', |
500 |
'Cannot send E-mail without customer given' => 'E-Mail kann nicht ohne Angabe eines Kunden evrsendet werden.', |
|
501 |
'Cannot send E-mail without vendor given' => 'E-Mail kann nicht ohne Angabe eines Lieferanten evrsendet werden.', |
|
500 | 502 |
'Cannot stock negative amounts' => 'Negative Mengen können nicht eingelagert werden!', |
501 | 503 |
'Cannot stock without amount' => 'Kann nicht ohne Menge einlagern!', |
502 | 504 |
'Cannot storno invoice for a closed period!' => 'Das Rechnungsdatum der zu stornierenden Rechnung fällt in einen abgeschlossenen Zeitraum!', |
... | ... | |
2430 | 2432 |
'Sellprice significant places' => 'Verkaufspreis: Nachkommastellen', |
2431 | 2433 |
'Semicolon' => 'Semikolon', |
2432 | 2434 |
'Sender' => 'AbsenderIn', |
2435 |
'Sending E-mail: ' => 'E-Mail versenden: ', |
|
2433 | 2436 |
'Sent emails can be optionally stored in the database with or without their attachments.' => 'Gesendete E-Mails können optional mit oder ohne ihre Anhänge in der Datenbank gespeichert werden.', |
2434 | 2437 |
'Sent on' => 'Verschickt am', |
2435 | 2438 |
'Sep' => 'Sep', |
... | ... | |
2688 | 2691 |
'The IBAN is missing.' => 'Die IBAN fehlt.', |
2689 | 2692 |
'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.', |
2690 | 2693 |
'The MT940 import needs an import profile called MT940' => 'Der MT940 Import benötigt ein Importprofil mit dem Namen "MT940"', |
2694 |
'The PDF has been created' => 'Die PDF-Datei wurde erstellt.', |
|
2691 | 2695 |
'The SEPA export has been created.' => 'Der SEPA-Export wurde erstellt', |
2692 | 2696 |
'The SEPA strings have been saved.' => 'Die bei SEPA-Überweisungen verwendeten Begriffe wurden gespeichert.', |
2693 | 2697 |
'The WebDAV feature has been used.' => 'Das WebDAV-Feature wurde benutzt.', |
templates/webpages/order/form.html | ||
---|---|---|
31 | 31 |
[% L.hidden_tag('action', 'Order/dispatch') %] |
32 | 32 |
|
33 | 33 |
[% L.button_tag('save()', LxERP.t8('Save')) %] |
34 |
[% L.button_tag('create_pdf()', LxERP.t8('Create PDF')) %] |
|
35 |
[% L.button_tag('email()', LxERP.t8('E-mail')) %] |
|
34 | 36 |
[%- IF SELF.order.id && ( (SELF.cv == 'customer' && INSTANCE_CONF.get_sales_order_show_delete) || (SELF.cv == 'vendor' && INSTANCE_CONF.get_purchase_order_show_delete) ) %] |
35 | 37 |
[% L.button_tag('delete_order()', LxERP.t8('Delete'), confirm=LxERP.t8("Are you sure?")) %] |
36 | 38 |
[%- END %] |
... | ... | |
55 | 57 |
$.post("controller.pl", data, kivi.eval_json_result); |
56 | 58 |
} |
57 | 59 |
|
60 |
function create_pdf() { |
|
61 |
if (!check_cv()) return; |
|
62 |
var data = $('#order_form').serialize(); |
|
63 |
data += '&action=Order/create_pdf'; |
|
64 |
|
|
65 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
66 |
} |
|
67 |
|
|
68 |
function download_pdf(pdf_filename, key) { |
|
69 |
var data = 'action=Order/download_pdf'; |
|
70 |
data += '&type=' + $('#type').val(); |
|
71 |
data += '&pdf_filename=' + pdf_filename; |
|
72 |
data += '&key=' + key; |
|
73 |
$.download("controller.pl", data); |
|
74 |
} |
|
75 |
|
|
76 |
function email() { |
|
77 |
if (!check_cv()) return; |
|
78 |
var data = $('#order_form').serialize(); |
|
79 |
data += '&action=Order/show_email_dialog'; |
|
80 |
|
|
81 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
82 |
} |
|
83 |
|
|
58 | 84 |
function check_cv() { |
59 | 85 |
if ($('#order_[%- cv_id %]').val() == '') { |
60 | 86 |
[%- IF SELF.cv == 'customer' %] |
templates/webpages/order/tabs/_email_dialog.html | ||
---|---|---|
1 |
[%- USE T8 %][%- USE HTML %][%- USE L %][%- USE LxERP %] |
|
2 |
|
|
3 |
<form method="post" id="email_form" method="POST"> |
|
4 |
<h2>[%- 'E-mail' | $T8 %] [%- SELF.type | $T8 %]</h2> |
|
5 |
|
|
6 |
<table width="100%"> |
|
7 |
<tr> |
|
8 |
<td> |
|
9 |
<table> |
|
10 |
<tr align="left"> |
|
11 |
<th align="right" nowrap>[% 'To' | $T8 %]</th> |
|
12 |
<td>[% L.input_tag("email.to", SELF.email.to, size=30, class=(SELF.email.to ? '' : 'initial_focus')) %]</td> |
|
13 |
</tr> |
|
14 |
<tr> |
|
15 |
<th align="right" nowrap>[% 'Cc' | $T8 %]</th> |
|
16 |
<td>[% L.input_tag("email.cc", SELF.email.cc, size=30) %]</td> |
|
17 |
</tr> |
|
18 |
[%- IF AUTH.assert('email_bcc', 1) %] |
|
19 |
<tr> |
|
20 |
<th align="right" nowrap>[% 'Bcc' | $T8 %]</th> |
|
21 |
<td>[% L.input_tag("email.bcc", SELF.email.bcc, size=30) %]</td> |
|
22 |
</tr> |
|
23 |
[%- END %] |
|
24 |
<tr> |
|
25 |
<th align="right" nowrap>[% 'Subject' | $T8 %]</th> |
|
26 |
<td>[% L.input_tag('email.subject', SELF.email.subject, size=30, class=(SELF.email.subject ? 'initial_focus' : '')) %]</td> |
|
27 |
</tr> |
|
28 |
<tr> |
|
29 |
<th align="right" nowrap>[% 'Attachment name' | $T8 %]</th> |
|
30 |
<td>[% L.input_tag("email.attachment_filename", SELF.email.attachment_filename, size=30) %]</td> |
|
31 |
</tr> |
|
32 |
</table> |
|
33 |
</td> |
|
34 |
</tr> |
|
35 |
|
|
36 |
<tr> |
|
37 |
<table> |
|
38 |
<tr> |
|
39 |
<th align="left" nowrap>[% 'Message' | $T8 %]</th> |
|
40 |
</tr> |
|
41 |
<tr> |
|
42 |
<td> |
|
43 |
[% L.textarea_tag("email.message", SELF.email.message, wrap="soft", style="width: 350px; height: 150px") %] |
|
44 |
</td> |
|
45 |
</tr> |
|
46 |
</tr> |
|
47 |
|
|
48 |
</table> |
|
49 |
|
|
50 |
<br> |
|
51 |
[% L.hidden_tag('action', 'Order/dispatch') %] |
|
52 |
[% L.button_tag('send_email()', LxERP.t8('Continue')) %] |
|
53 |
<a href="#" onclick="close_email_dialog();">[%- LxERP.t8("Cancel") %]</a> |
|
54 |
|
|
55 |
<script type='text/javascript'> |
|
56 |
function send_email() { |
|
57 |
var data = $('#order_form').serialize(); |
|
58 |
data += '&'; |
|
59 |
data += $('#email_form').serialize(); |
|
60 |
data += '&action=Order/send_email'; |
|
61 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
62 |
} |
|
63 |
</script> |
|
64 |
|
|
65 |
</form> |
templates/webpages/order/tabs/basic_data.html | ||
---|---|---|
321 | 321 |
}); |
322 | 322 |
} |
323 | 323 |
|
324 |
var email_dialog; |
|
325 |
|
|
326 |
function show_email_dialog(html) { |
|
327 |
var id = 'jqueryui_popup_dialog'; |
|
328 |
var dialog_params = { |
|
329 |
id: id, |
|
330 |
width: 800, |
|
331 |
height: 500, |
|
332 |
modal: true, |
|
333 |
close: function(event, ui) { |
|
334 |
email_dialog.remove(); |
|
335 |
}, |
|
336 |
}; |
|
337 |
|
|
338 |
$('#' + id).remove(); |
|
339 |
|
|
340 |
email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body'); |
|
341 |
email_dialog.html(html); |
|
342 |
email_dialog.dialog(dialog_params); |
|
343 |
|
|
344 |
$('.cancel').click(close_email_dialog); |
|
345 |
|
|
346 |
return true; |
|
347 |
} |
|
348 |
|
|
349 |
close_email_dialog = function() { |
|
350 |
email_dialog.dialog("close"); |
|
351 |
} |
|
352 |
|
|
353 |
|
|
324 | 354 |
$(function(){ |
325 | 355 |
$('#order_[%- cv_id %]').change(reload_cv_dependend_selections); |
326 | 356 |
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) }); |
Auch abrufbar als: Unified diff
Auftrags-Controller: Drucken und E-Mail