1 namespace('kivi.Order', function(ns) {
2 ns.check_cv = function() {
3 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') {
4 if ($('#order_customer_id').val() === '') {
5 alert(kivi.t8('Please select a customer.'));
9 if ($('#order_vendor_id').val() === '') {
10 alert(kivi.t8('Please select a vendor.'));
17 ns.check_duplicate_parts = function(question) {
18 var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get();
20 var i, obj = {}, pos = [];
22 for (i = 0; i < id_arr.length; i++) {
24 if (obj.hasOwnProperty(id)) {
31 question = question || kivi.t8("Do you really want to continue?");
32 return confirm(kivi.t8("There are duplicate parts at positions") + "\n"
33 + pos.join(', ') + "\n"
39 ns.check_valid_reqdate = function() {
40 if ($('#order_reqdate_as_date').val() === '') {
41 alert(kivi.t8('Please select a delivery date.'));
48 ns.save = function(action, warn_on_duplicates, warn_on_reqdate) {
49 if (!ns.check_cv()) return;
50 if (warn_on_duplicates && !ns.check_duplicate_parts()) return;
51 if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
53 var data = $('#order_form').serializeArray();
54 data.push({ name: 'action', value: 'Order/' + action });
56 $.post("controller.pl", data, kivi.eval_json_result);
59 ns.delete_order = function() {
60 var data = $('#order_form').serializeArray();
61 data.push({ name: 'action', value: 'Order/delete' });
63 $.post("controller.pl", data, kivi.eval_json_result);
66 ns.show_print_options = function(warn_on_duplicates, warn_on_reqdate) {
67 if (!ns.check_cv()) return;
68 if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to print?"))) return;
69 if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
74 title: kivi.t8('Print options'),
81 ns.print = function() {
82 $('#print_options').dialog('close');
84 var data = $('#order_form').serializeArray();
85 data = data.concat($('#print_options_form').serializeArray());
86 data.push({ name: 'action', value: 'Order/print' });
88 $.post("controller.pl", data, kivi.eval_json_result);
93 ns.setup_send_email_dialog = function() {
94 kivi.SalesPurchase.show_all_print_options_elements();
95 kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false);
97 $('#print_options_form table').first().remove().appendTo('#email_form_print_options');
99 var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
100 $('#email_form_' + to_focus).focus();
103 ns.finish_send_email_dialog = function() {
104 kivi.SalesPurchase.show_all_print_options_elements();
106 $('#email_form_print_options table').first().remove().prependTo('#print_options_form');
110 ns.show_email_dialog = function(html) {
111 var id = 'send_email_dialog';
112 var dialog_params = {
116 title: kivi.t8('Send email'),
118 beforeClose: kivi.Order.finish_send_email_dialog,
119 close: function(event, ui) {
120 email_dialog.remove();
124 $('#' + id).remove();
126 email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
127 email_dialog.html(html);
128 email_dialog.dialog(dialog_params);
130 kivi.Order.setup_send_email_dialog();
132 $('.cancel').click(ns.close_email_dialog);
137 ns.send_email = function() {
138 // push button only once -> slow response from mail server
139 ns.email_dialog_disable_send();
141 var data = $('#order_form').serializeArray();
142 data = data.concat($('[name^="email_form."]').serializeArray());
143 data = data.concat($('[name^="print_options."]').serializeArray());
144 data.push({ name: 'action', value: 'Order/send_email' });
145 $.post("controller.pl", data, kivi.eval_json_result);
148 ns.email_dialog_disable_send = function() {
149 // disable mail send event to prevent
150 // impatient users to send multiple times
151 $('#send_email').prop('disabled', true);
154 ns.close_email_dialog = function() {
155 email_dialog.dialog("close");
158 ns.set_number_in_title = function(elt) {
159 $('#nr_in_title').html($(elt).val());
162 ns.reload_cv_dependent_selections = function() {
163 $('#order_shipto_id').val('');
164 var data = $('#order_form').serializeArray();
165 data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
167 $.post("controller.pl", data, kivi.eval_json_result);
170 ns.reformat_number = function(event) {
171 $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
174 ns.reformat_number_as_null_number = function(event) {
175 if ($(event.target).val() === '') {
178 ns.reformat_number(event);
181 ns.update_exchangerate = function(event) {
182 if (!ns.check_cv()) {
183 $('#order_currency_id').val($('#old_currency_id').val());
187 var rate_input = $('#order_exchangerate_as_null_number');
188 // unset exchangerate if currency changed
189 if ($('#order_currency_id').val() !== $('#old_currency_id').val()) {
193 // only set exchangerate if unset
194 if (rate_input.val() !== '') {
198 var data = $('#order_form').serializeArray();
199 data.push({ name: 'action', value: 'Order/update_exchangerate' });
202 url: 'controller.pl',
206 success: function(data){
207 if (!data.is_standard) {
208 $('#currency_name').text(data.currency_name);
209 if (data.exchangerate) {
210 rate_input.val(data.exchangerate);
214 $('#exchangerate_settings').show();
217 $('#exchangerate_settings').hide();
219 if ($('#order_currency_id').val() != $('#old_currency_id').val() ||
220 !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) {
221 kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
223 $('#old_currency_id').val($('#order_currency_id').val());
224 $('#old_exchangerate').val(data.exchangerate);
229 ns.exchangerate_changed = function(event) {
230 if (kivi.parse_amount($('#order_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) {
231 kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
232 $('#old_exchangerate').val($('#order_exchangerate_as_null_number').val());
236 ns.unit_change = function(event) {
237 var row = $(event.target).parents("tbody").first();
238 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
239 var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
240 var select_elt = $(row).find('[name="order.orderitems[].unit"]');
242 var oldval = $(select_elt).data('oldval');
243 $(select_elt).data('oldval', $(select_elt).val());
245 var data = $('#order_form').serializeArray();
246 data.push({ name: 'action', value: 'Order/unit_changed' },
247 { name: 'item_id', value: item_id_dom.val() },
248 { name: 'old_unit', value: oldval },
249 { name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
251 $.post("controller.pl", data, kivi.eval_json_result);
254 ns.update_sellprice = function(item_id, price_str) {
255 var row = $('#item_' + item_id).parents("tbody").first();
256 var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
257 var html_elt = $(row).find('[name="sellprice_text"]');
258 price_elt.val(price_str);
259 html_elt.html(price_str);
262 ns.load_second_row = function(row) {
263 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
264 var div_elt = $(row).find('[name="second_row"]');
266 if ($(div_elt).data('loaded') == 1) {
269 var data = $('#order_form').serializeArray();
270 data.push({ name: 'action', value: 'Order/load_second_rows' },
271 { name: 'item_ids[]', value: item_id_dom.val() });
273 $.post("controller.pl", data, kivi.eval_json_result);
276 ns.load_all_second_rows = function() {
277 var rows = $('.row_entry').filter(function(idx, elt) {
278 return $(elt).find('[name="second_row"]').data('loaded') != 1;
281 var item_ids = $.map(rows, function(elt) {
282 var item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
283 return { name: 'item_ids[]', value: item_id };
286 if (item_ids.length == 0) {
290 var data = $('#order_form').serializeArray();
291 data.push({ name: 'action', value: 'Order/load_second_rows' });
292 data = data.concat(item_ids);
294 $.post("controller.pl", data, kivi.eval_json_result);
297 ns.hide_second_row = function(row) {
298 $(row).children().not(':first').hide();
299 $(row).data('expanded', 0);
300 var elt = $(row).find('.expand');
301 elt.attr('src', "image/expand.svg");
302 elt.attr('alt', kivi.t8('Show details'));
303 elt.attr('title', kivi.t8('Show details'));
306 ns.show_second_row = function(row) {
307 $(row).children().not(':first').show();
308 $(row).data('expanded', 1);
309 var elt = $(row).find('.expand');
310 elt.attr('src', "image/collapse.svg");
311 elt.attr('alt', kivi.t8('Hide details'));
312 elt.attr('title', kivi.t8('Hide details'));
315 ns.toggle_second_row = function(row) {
316 if ($(row).data('expanded') == 1) {
317 ns.hide_second_row(row);
319 ns.show_second_row(row);
323 ns.init_row_handlers = function() {
324 kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
325 $(elt).change(ns.reformat_number);
328 kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
329 $(elt).data('oldval', $(elt).val());
330 $(elt).change(ns.unit_change);
333 kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
334 $(elt).keydown(function(event) {
336 if (event.keyCode == 40 && event.shiftKey === true) {
338 event.preventDefault();
339 row = $(event.target).parents(".row_entry").first();
340 ns.load_second_row(row);
341 ns.show_second_row(row);
344 if (event.keyCode == 38 && event.shiftKey === true) {
346 event.preventDefault();
347 row = $(event.target).parents(".row_entry").first();
348 ns.hide_second_row(row);
354 kivi.run_once_for('.expand', 'expand_second_row', function(elt) {
355 $(elt).click(function(event) {
356 event.preventDefault();
357 var row = $(event.target).parents(".row_entry").first();
358 ns.load_second_row(row);
359 ns.toggle_second_row(row);
366 ns.redisplay_line_values = function(is_sales, data) {
367 $('.row_entry').each(function(idx, elt) {
368 $(elt).find('[name="linetotal"]').html(data[idx][0]);
369 if (is_sales && $(elt).find('[name="second_row"]').data('loaded') == 1) {
370 var mt = data[idx][1];
371 var mp = data[idx][2];
373 if (mt[0] === '-') h += ' class="plus0"';
374 h += '>' + mt + ' ' + mp + '%';
376 $(elt).find('[name="linemargin"]').html(h);
381 ns.redisplay_cvpartnumbers = function(data) {
382 $('.row_entry').each(function(idx, elt) {
383 $(elt).find('[name="cvpartnumber"]').html(data[idx][0]);
387 ns.renumber_positions = function() {
388 $('.row_entry [name="position"]').each(function(idx, elt) {
391 $('.row_entry').each(function(idx, elt) {
392 $(elt).data("position", idx+1);
396 ns.reorder_items = function(order_by) {
397 var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
398 $('#row_table_id thead a img').remove();
403 src = "image/up.png";
406 src = "image/down.png";
409 $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
411 var data = $('#order_form').serializeArray();
412 data.push({ name: 'action', value: 'Order/reorder_items' },
413 { name: 'order_by', value: order_by },
414 { name: 'sort_dir', value: dir });
416 $.post("controller.pl", data, kivi.eval_json_result);
419 ns.redisplay_items = function(data) {
420 var old_rows = $('.row_entry').detach();
422 $(data).each(function(idx, elt) {
423 new_rows.push(old_rows[elt.old_pos - 1]);
425 $(new_rows).appendTo($('#row_table_id'));
426 ns.renumber_positions();
429 ns.get_insert_before_item_id = function(wanted_pos) {
430 if (wanted_pos === '') return;
432 var insert_before_item_id;
433 // selection by data does not seem to work if data is changed at runtime
434 // var elt = $('.row_entry [data-position="' + wanted_pos + '"]');
435 $('.row_entry').each(function(idx, elt) {
436 if ($(elt).data("position") == wanted_pos) {
437 insert_before_item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
442 return insert_before_item_id;
445 ns.add_item = function() {
446 if ($('#add_item_parts_id').val() === '') return;
447 if (!ns.check_cv()) return;
449 $('#row_table_id thead a img').remove();
451 var insert_before_item_id = ns.get_insert_before_item_id($('#add_item_position').val());
453 var data = $('#order_form').serializeArray();
454 data.push({ name: 'action', value: 'Order/add_item' },
455 { name: 'insert_before_item_id', value: insert_before_item_id });
457 $.post("controller.pl", data, kivi.eval_json_result);
460 ns.open_multi_items_dialog = function() {
461 if (!ns.check_cv()) return;
463 var pp = $("#add_item_parts_id").data("part_picker");
468 ns.add_multi_items = function(data) {
469 var insert_before_item_id = ns.get_insert_before_item_id($('#multi_items_position').val());
470 data = data.concat($('#order_form').serializeArray());
471 data.push({ name: 'action', value: 'Order/add_multi_items' },
472 { name: 'insert_before_item_id', value: insert_before_item_id });
473 $.post("controller.pl", data, kivi.eval_json_result);
476 ns.delete_order_item_row = function(clicked) {
477 var row = $(clicked).parents("tbody").first();
480 ns.renumber_positions();
483 ns.row_table_scroll_down = function() {
484 $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
487 ns.show_longdescription_dialog = function(clicked) {
488 var row = $(clicked).parents("tbody").first();
489 var position = $(row).find('[name="position"]').html();
490 var partnumber = $(row).find('[name="partnumber"]').html();
491 var description_elt = $(row).find('[name="order.orderitems[].description"]');
492 var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
495 runningnumber: position,
496 partnumber: partnumber,
497 description: description_elt.val(),
498 default_longdescription: longdescription_elt.val(),
499 set_function: function(val) {
500 longdescription_elt.val(val);
504 kivi.SalesPurchase.edit_longdescription_with_params(params);
507 ns.price_chooser_item_row = function(clicked) {
508 if (!ns.check_cv()) return;
509 var row = $(clicked).parents("tbody").first();
510 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
512 var data = $('#order_form').serializeArray();
513 data.push({ name: 'action', value: 'Order/price_popup' },
514 { name: 'item_id', value: item_id_dom.val() });
516 $.post("controller.pl", data, kivi.eval_json_result);
519 ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
520 var row = $('#item_' + item_id).parents("tbody").first();
521 var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]');
522 var button_elt = $(row).find('[name="price_chooser_button"]');
524 button_elt.val(button_elt.val().replace(/.*\|/, descr + " |"));
525 source_elt.val(source);
527 var editable_div_elt = $(row).find('[name="editable_price"]');
528 var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
529 if (price_editable == 1 && source === '') {
531 $(editable_div_elt).show();
532 $(not_editable_div_elt).hide();
533 $(editable_div_elt).find(':input').prop("disabled", false);
534 $(not_editable_div_elt).find(':input').prop("disabled", true);
537 $(editable_div_elt).hide();
538 $(not_editable_div_elt).show();
539 $(editable_div_elt).find(':input').prop("disabled", true);
540 $(not_editable_div_elt).find(':input').prop("disabled", false);
544 var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
545 var html_elt = $(row).find('[name="sellprice_text"]');
546 price_elt.val(price_str);
547 html_elt.html(price_str);
550 kivi.io.close_dialog();
553 ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
554 var row = $('#item_' + item_id).parents("tbody").first();
555 var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]');
556 var button_elt = $(row).find('[name="price_chooser_button"]');
558 button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr));
559 source_elt.val(source);
561 var editable_div_elt = $(row).find('[name="editable_discount"]');
562 var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
563 if (price_editable == 1 && source === '') {
565 $(editable_div_elt).show();
566 $(not_editable_div_elt).hide();
567 $(editable_div_elt).find(':input').prop("disabled", false);
568 $(not_editable_div_elt).find(':input').prop("disabled", true);
571 $(editable_div_elt).hide();
572 $(not_editable_div_elt).show();
573 $(editable_div_elt).find(':input').prop("disabled", true);
574 $(not_editable_div_elt).find(':input').prop("disabled", false);
578 var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]');
579 var html_elt = $(row).find('[name="discount_text"]');
580 discount_elt.val(discount_str);
581 html_elt.html(discount_str);
584 kivi.io.close_dialog();
587 ns.show_vc_details_dialog = function() {
588 if (!ns.check_cv()) return;
592 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
594 vc_id = $('#order_customer_id').val();
595 title = kivi.t8('Customer details');
598 vc_id = $('#order_vendor_id').val();
599 title = kivi.t8('Vendor details');
603 url: 'controller.pl',
604 data: { action: 'Order/show_customer_vendor_details_dialog',
605 type : $('#type').val(),
609 id: 'jq_customer_vendor_details_dialog',
619 ns.update_row_from_master_data = function(clicked) {
620 var row = $(clicked).parents("tbody").first();
621 var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
623 var data = $('#order_form').serializeArray();
624 data.push({ name: 'action', value: 'Order/update_row_from_master_data' });
625 data.push({ name: 'item_ids[]', value: item_id_dom.val() });
627 $.post("controller.pl", data, kivi.eval_json_result);
630 ns.update_all_rows_from_master_data = function() {
631 var item_ids = $.map($('.row_entry'), function(elt) {
632 var item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
633 return { name: 'item_ids[]', value: item_id };
636 if (item_ids.length == 0) {
640 var data = $('#order_form').serializeArray();
641 data.push({ name: 'action', value: 'Order/update_row_from_master_data' });
642 data = data.concat(item_ids);
644 $.post("controller.pl", data, kivi.eval_json_result);
647 ns.show_calculate_qty_dialog = function(clicked) {
648 var row = $(clicked).parents("tbody").first();
649 var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id');
650 var formula_id = $(row).find('[name="formula[+]"]').attr('id');
652 calculate_qty_selection_dialog("", input_id, "", formula_id);
656 ns.edit_custom_shipto = function() {
657 if (!ns.check_cv()) return;
659 kivi.SalesPurchase.edit_custom_shipto();
662 ns.purchase_order_check_for_direct_delivery = function() {
663 if ($('#type').val() != 'sales_order') {
664 kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
669 if ($('#order_shipto_id').val() !== '') {
671 shipto = $('#order_shipto_id option:selected').text();
673 $('#shipto_inputs [id^="shipto"]').each(function(idx, elt) {
674 if (!empty) return true;
675 if (/^shipto_to_copy/.test($(elt).prop('id'))) return true;
676 if (/^shiptocp_gender/.test($(elt).prop('id'))) return true;
677 if (/^shiptocvar_/.test($(elt).prop('id'))) return true;
678 if ($(elt).val() !== '') {
683 var shipto_elements = [];
684 $([$('#shiptoname').val(), $('#shiptostreet').val(), $('#shiptozipcode').val(), $('#shiptocity').val()]).each(function(idx, elt) {
685 if (elt !== '') shipto_elements.push(elt);
687 shipto = shipto_elements.join('; ');
692 ns.direct_delivery_dialog(shipto);
694 kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
698 ns.direct_delivery_callback = function(accepted) {
699 $('#direct-delivery-dialog').dialog('close');
702 $('<input type="hidden" name="use_shipto">').appendTo('#order_form').val('1');
705 kivi.submit_form_with_action($('#order_form'), 'Order/purchase_order');
708 ns.direct_delivery_dialog = function(shipto) {
709 $('#direct-delivery-dialog').remove();
711 var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
712 var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase order so that the vendor can deliver the goods directly to your customer?');
713 var html = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
714 html = html + '<hr><p>';
715 html = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true)">';
716 html = html + ' ';
717 html = html + '<input type="button" value="' + kivi.t8('No') + '" size="30" onclick="kivi.Order.direct_delivery_callback(false)">';
718 html = html + '</p></div>';
719 $(html).hide().appendTo('#order_form');
721 kivi.popup_dialog({id: 'direct-delivery-dialog',
722 dialog: {title: kivi.t8('Carry over shipping address'),
727 ns.follow_up_window = function() {
728 var id = $('#id').val();
729 var type = $('#type').val();
731 var number_info = '';
732 if ($('#type').val() == 'sales_order' || $('#type').val() == 'purchase_order') {
733 number_info = $('#order_ordnumber').val();
734 } else if ($('#type').val() == 'sales_quotation' || $('#type').val() == 'request_quotation') {
735 number_info = $('#order_quonumber').val();
739 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') {
740 name_info = $('#order_customer_id_name').val();
741 } else if ($('#type').val() == 'purchase_order' || $('#type').val() == 'request_quotation') {
742 name_info = $('#order_vendor_id_name').val();
746 if (number_info !== '') { info += ' (' + number_info + ')' }
747 if (name_info !== '') { info += ' (' + name_info + ')' }
749 if (!$('#follow_up_rowcount').lenght) {
750 $('<input type="hidden" name="follow_up_rowcount" id="follow_up_rowcount">').appendTo('#order_form');
751 $('<input type="hidden" name="follow_up_trans_id_1" id="follow_up_trans_id_1">').appendTo('#order_form');
752 $('<input type="hidden" name="follow_up_trans_type_1" id="follow_up_trans_type_1">').appendTo('#order_form');
753 $('<input type="hidden" name="follow_up_trans_info_1" id="follow_up_trans_info_1">').appendTo('#order_form');
754 $('<input type="hidden" name="follow_up_trans_subject_1" id="follow_up_trans_subject_1">').appendTo('#order_form');
756 $('#follow_up_rowcount').val(1);
757 $('#follow_up_trans_id_1').val(id);
758 $('#follow_up_trans_type_1').val(type);
759 $('#follow_up_trans_info_1').val(info);
760 $('#follow_up_trans_subject_1').val($('#order_transaction_description').val());
765 ns.create_part = function() {
766 var data = $('#order_form').serializeArray();
767 data.push({ name: 'action', value: 'Order/create_part' });
769 $.post("controller.pl", data, kivi.eval_json_result);
775 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
776 $('#order_customer_id').change(kivi.Order.reload_cv_dependent_selections);
778 $('#order_vendor_id').change(kivi.Order.reload_cv_dependent_selections);
781 $('#order_currency_id').change(kivi.Order.update_exchangerate);
782 $('#order_transdate_as_date').change(kivi.Order.update_exchangerate);
783 $('#order_exchangerate_as_null_number').change(kivi.Order.exchangerate_changed);
785 if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
786 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
788 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
790 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
791 $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
793 $('.add_item_input').keydown(function(event) {
794 if (event.keyCode == 13) {
795 event.preventDefault();
796 kivi.Order.add_item();
801 kivi.Order.init_row_handlers();
803 $('#row_table_id').on('sortstop', function(event, ui) {
804 $('#row_table_id thead a img').remove();
805 kivi.Order.renumber_positions();
808 $('#expand_all').on('click', function(event) {
809 event.preventDefault();
810 if ($('#expand_all').data('expanded') == 1) {
811 $('#expand_all').data('expanded', 0);
812 $('#expand_all').attr('src', 'image/expand.svg');
813 $('#expand_all').attr('alt', kivi.t8('Show all details'));
814 $('#expand_all').attr('title', kivi.t8('Show all details'));
815 $('.row_entry').each(function(idx, elt) {
816 kivi.Order.hide_second_row(elt);
819 $('#expand_all').data('expanded', 1);
820 $('#expand_all').attr('src', "image/collapse.svg");
821 $('#expand_all').attr('alt', kivi.t8('Hide all details'));
822 $('#expand_all').attr('title', kivi.t8('Hide all details'));
823 kivi.Order.load_all_second_rows();
824 $('.row_entry').each(function(idx, elt) {
825 kivi.Order.show_second_row(elt);
831 $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number);