Revision 2d50590b
Von Bernd Bleßmann vor fast 9 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
329 | 329 |
$self->js->render(); |
330 | 330 |
} |
331 | 331 |
|
332 |
sub action_unit_changed { |
|
333 |
my ($self) = @_; |
|
334 |
|
|
335 |
my $idx = first_index { $_ eq $::form->{item_id} } @{ $::form->{orderitem_ids} }; |
|
336 |
my $item = $self->order->items->[$idx]; |
|
337 |
|
|
338 |
my $old_unit_obj = SL::DB::Unit->new(name => $::form->{old_unit})->load; |
|
339 |
$item->sellprice($item->unit_obj->convert_to($item->sellprice, $old_unit_obj)); |
|
340 |
|
|
341 |
$self->_recalc(); |
|
342 |
|
|
343 |
$self->js |
|
344 |
->run('update_sellprice', $::form->{item_id}, $item->sellprice_as_number); |
|
345 |
$self->_js_redisplay_linetotals; |
|
346 |
$self->_js_redisplay_amounts_and_taxes; |
|
347 |
$self->js->render(); |
|
348 |
} |
|
349 |
|
|
332 | 350 |
sub action_add_item { |
333 | 351 |
my ($self) = @_; |
334 | 352 |
|
... | ... | |
349 | 367 |
->val('.add_item_input', '') |
350 | 368 |
->run('row_table_scroll_down') |
351 | 369 |
->run('row_set_keyboard_events_by_id', $item_id) |
370 |
->run('set_unit_change_with_oldval_by_id', $item_id) |
|
352 | 371 |
->on('.recalc', 'change', 'recalc_amounts_and_taxes') |
353 | 372 |
->on('.reformat_number', 'change', 'reformat_number') |
354 | 373 |
->focus('#add_item_parts_id_name'); |
... | ... | |
400 | 419 |
|
401 | 420 |
$self->js |
402 | 421 |
->append('#row_table_id', $row_as_html) |
403 |
->run('row_set_keyboard_events_by_id', $item_id); |
|
422 |
->run('row_set_keyboard_events_by_id', $item_id) |
|
423 |
->run('set_unit_change_with_oldval_by_id', $item_id); |
|
404 | 424 |
} |
405 | 425 |
|
406 | 426 |
$self->js |
templates/webpages/order/tabs/_row.html | ||
---|---|---|
42 | 42 |
class="recalc") %] |
43 | 43 |
</td> |
44 | 44 |
<td nowrap> |
45 |
[%- L.input_tag("order.orderitems[].unit", |
|
46 |
ITEM.unit, |
|
47 |
size = 5, |
|
48 |
class="recalc") %] |
|
45 |
[%- L.select_tag("order.orderitems[].unit", |
|
46 |
ITEM.part.available_units, |
|
47 |
default = ITEM.unit, |
|
48 |
title_key = 'name', |
|
49 |
value_key = 'name', |
|
50 |
class = 'unitselect') %] |
|
49 | 51 |
</td> |
50 | 52 |
<td> |
51 | 53 |
[%- L.button_tag("price_chooser_item_row(this)", |
templates/webpages/order/tabs/basic_data.html | ||
---|---|---|
272 | 272 |
$.post("controller.pl", data, kivi.eval_json_result); |
273 | 273 |
} |
274 | 274 |
|
275 |
function unit_change(event) { |
|
276 |
var row = $(event.target).parents("tbody").first(); |
|
277 |
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); |
|
278 |
var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
279 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]'); |
|
280 |
|
|
281 |
var oldval = $(select_elt).data('oldval'); |
|
282 |
$(select_elt).data('oldval', $(select_elt).val()); |
|
283 |
|
|
284 |
var data = $('#order_form').serialize(); |
|
285 |
data += '&action=Order/unit_changed'; |
|
286 |
data += '&item_id=' + item_id_dom.val(); |
|
287 |
data += '&old_unit=' + oldval; |
|
288 |
data += '&sellprice_dom_id=' + sellprice_dom.attr('id'); |
|
289 |
|
|
290 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
291 |
} |
|
292 |
|
|
293 |
function update_sellprice(item_id, price_str) { |
|
294 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
295 |
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]'); |
|
296 |
var html_elt = $(row).find('[name="sellprice_text"]'); |
|
297 |
price_elt.val(price_str); |
|
298 |
html_elt.html(price_str); |
|
299 |
} |
|
300 |
|
|
275 | 301 |
function add_item() { |
276 | 302 |
if ($('#add_item_parts_id').val() == '') return; |
277 | 303 |
if (!check_cv()) return; |
... | ... | |
445 | 471 |
}); |
446 | 472 |
} |
447 | 473 |
|
474 |
function set_unit_change_with_oldval_by_id(item_id) { |
|
475 |
var row = $('#item_' + item_id).parents("tbody").first(); |
|
476 |
var select_elt = $(row).find('[name="order.orderitems[].unit"]'); |
|
477 |
|
|
478 |
set_unit_change_with_oldval(select_elt); |
|
479 |
} |
|
480 |
|
|
481 |
function set_unit_change_with_oldval(selects) { |
|
482 |
selects.each(function(idx,elt) { |
|
483 |
$(elt).data('oldval', $(elt).val()); |
|
484 |
}); |
|
485 |
|
|
486 |
selects.change(unit_change); |
|
487 |
} |
|
488 |
|
|
448 | 489 |
var email_dialog; |
449 | 490 |
|
450 | 491 |
function show_email_dialog(html) { |
... | ... | |
494 | 535 |
row_set_keyboard_events($('.row_entry')); |
495 | 536 |
$('.recalc').change(recalc_amounts_and_taxes); |
496 | 537 |
$('.reformat_number').change(reformat_number); |
538 |
|
|
539 |
set_unit_change_with_oldval($('.unitselect')); |
|
497 | 540 |
}); |
498 | 541 |
|
499 | 542 |
</script> |
Auch abrufbar als: Unified diff
Auftrags-Controller: Einheiten per Select ändern können und sellprice anpassen.