Projekt

Allgemein

Profil

Herunterladen (23,1 KB) Statistiken
| Zweig: | Markierung: | Revision:
0935b012 Bernd Bleßmann
namespace('kivi.Order', function(ns) {
ns.check_cv = function() {
68da3b40 Bernd Bleßmann
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation') {
7ede2933 Sven Schöling
if ($('#order_customer_id').val() === '') {
0935b012 Bernd Bleßmann
alert(kivi.t8('Please select a customer.'));
return false;
}
} else {
7ede2933 Sven Schöling
if ($('#order_vendor_id').val() === '') {
0935b012 Bernd Bleßmann
alert(kivi.t8('Please select a vendor.'));
return false;
}
}
return true;
};

e09f2da3 Bernd Bleßmann
ns.check_save_duplicate_parts = function() {
68da3b40 Bernd Bleßmann
var id_arr = $('[name="order.orderitems[].parts_id"]').map(function() { return this.value; }).get();
e09f2da3 Bernd Bleßmann
var i, obj = {}, pos = [];

for (i = 0; i < id_arr.length; i++) {
var id = id_arr[i];
if (obj.hasOwnProperty(id)) {
pos.push(i + 1);
}
obj[id] = 0;
}

if (pos.length > 0) {
return confirm(kivi.t8("There are duplicate parts at positions") + "\n"
+ pos.join(', ') + "\n"
+ kivi.t8("Do you really want to save?"));
}
return true;
};

1d1f3140 Jan Büren
ns.check_valid_reqdate = function() {
if ($('#order_reqdate').val() === '') {
alert(kivi.t8('Please select a delivery date.'));
return false;
} else {
return true;
}
};

ns.save = function(action, warn_on_duplicates, warn_on_reqdate) {
0935b012 Bernd Bleßmann
if (!ns.check_cv()) return;
e09f2da3 Bernd Bleßmann
if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
68da3b40 Bernd Bleßmann
if (warn_on_reqdate && !ns.check_valid_reqdate()) return;
0935b012 Bernd Bleßmann
var data = $('#order_form').serializeArray();
06806380 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/' + action });
07dd84c0 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

0935b012 Bernd Bleßmann
ns.delete_order = function() {
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/delete' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.show_print_options = function() {
if (!ns.check_cv()) return;

kivi.popup_dialog({
id: 'print_options',
dialog: {
title: kivi.t8('Print options'),
width: 800,
height: 300
}
});
};

ns.print = function() {
$('#print_options').dialog('close');

var data = $('#order_form').serializeArray();
data = data.concat($('#print_options_form').serializeArray());
data.push({ name: 'action', value: 'Order/print' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.download_pdf = function(pdf_filename, key) {
68da3b40 Bernd Bleßmann
var data = [{ name: 'action', value: 'Order/download_pdf' },
{ name: 'type', value: $('#type').val() },
{ name: 'pdf_filename', value: pdf_filename },
{ name: 'key', value: key }];
0935b012 Bernd Bleßmann
$.download("controller.pl", data);
};

ns.email = function() {
if (!ns.check_cv()) return;
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/show_email_dialog' });

$.post("controller.pl", data, kivi.eval_json_result);
};

var email_dialog;

d83928f0 Bernd Bleßmann
ns.setup_send_email_dialog = function() {
kivi.SalesPurchase.show_all_print_options_elements();
kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false);

$('#print_options_form table').first().remove().appendTo('#email_form_print_options');

var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
$('#email_form_' + to_focus).focus();
};

ns.finish_send_email_dialog = function() {
kivi.SalesPurchase.show_all_print_options_elements();

$('#email_form_print_options table').first().remove().prependTo('#print_options_form');
return true;
};

0935b012 Bernd Bleßmann
ns.show_email_dialog = function(html) {
d83928f0 Bernd Bleßmann
var id = 'send_email_dialog';
0935b012 Bernd Bleßmann
var dialog_params = {
id: id,
width: 800,
d83928f0 Bernd Bleßmann
height: 600,
title: kivi.t8('Send email'),
0935b012 Bernd Bleßmann
modal: true,
d83928f0 Bernd Bleßmann
beforeClose: kivi.Order.finish_send_email_dialog,
0935b012 Bernd Bleßmann
close: function(event, ui) {
email_dialog.remove();
d83928f0 Bernd Bleßmann
}
0935b012 Bernd Bleßmann
};

$('#' + id).remove();

email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
email_dialog.html(html);
email_dialog.dialog(dialog_params);

d83928f0 Bernd Bleßmann
kivi.Order.setup_send_email_dialog();

0935b012 Bernd Bleßmann
$('.cancel').click(ns.close_email_dialog);

return true;
};

ns.send_email = function() {
var data = $('#order_form').serializeArray();
d83928f0 Bernd Bleßmann
data = data.concat($('[name^="email_form."]').serializeArray());
data = data.concat($('[name^="print_options."]').serializeArray());
0935b012 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/send_email' });
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.close_email_dialog = function() {
email_dialog.dialog("close");
};

faf31da3 Bernd Bleßmann
ns.set_number_in_title = function(elt) {
$('#nr_in_title').html($(elt).val());
};

96caf7a5 Geoffrey Richardson
ns.reload_cv_dependant_selections = function() {
0935b012 Bernd Bleßmann
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/customer_vendor_changed' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.reformat_number = function(event) {
$(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
};

ns.recalc_amounts_and_taxes = function() {
var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.unit_change = function(event) {
68da3b40 Bernd Bleßmann
var row = $(event.target).parents("tbody").first();
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
0935b012 Bernd Bleßmann
var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
68da3b40 Bernd Bleßmann
var select_elt = $(row).find('[name="order.orderitems[].unit"]');
0935b012 Bernd Bleßmann
var oldval = $(select_elt).data('oldval');
$(select_elt).data('oldval', $(select_elt).val());

var data = $('#order_form').serializeArray();
68da3b40 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/unit_changed' },
{ name: 'item_id', value: item_id_dom.val() },
{ name: 'old_unit', value: oldval },
{ name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
0935b012 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.update_sellprice = function(item_id, price_str) {
68da3b40 Bernd Bleßmann
var row = $('#item_' + item_id).parents("tbody").first();
0935b012 Bernd Bleßmann
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
var html_elt = $(row).find('[name="sellprice_text"]');
price_elt.val(price_str);
html_elt.html(price_str);
};

28a7a539 Bernd Bleßmann
ns.load_second_row = function(row) {
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
68da3b40 Bernd Bleßmann
var div_elt = $(row).find('[name="second_row"]');
28a7a539 Bernd Bleßmann
if ($(div_elt).data('loaded') == 1) {
return;
}
var data = $('#order_form').serializeArray();
68da3b40 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/load_second_rows' },
{ name: 'item_ids[]', value: item_id_dom.val() });
28a7a539 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

9eb765a5 Bernd Bleßmann
ns.load_all_second_rows = function() {
var rows = $('.row_entry').filter(function(idx, elt) {
return $(elt).find('[name="second_row"]').data('loaded') != 1;
});

var item_ids = $.map(rows, function(elt) {
var item_id = $(elt).find('[name="orderitem_ids[+]"]').val();
return { name: 'item_ids[]', value: item_id };
});

if (item_ids.length == 0) {
return;
}

var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/load_second_rows' });
data = data.concat(item_ids);

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.hide_second_row = function(row) {
$(row).children().not(':first').hide();
2659735b Bernd Bleßmann
$(row).data('expanded', 0);
9eb765a5 Bernd Bleßmann
var elt = $(row).find('.expand');
91d46243 Bernd Bleßmann
elt.attr('src', "image/expand.svg");
9eb765a5 Bernd Bleßmann
elt.attr('alt', kivi.t8('Show details'));
elt.attr('title', kivi.t8('Show details'));
};

ns.show_second_row = function(row) {
$(row).children().not(':first').show();
2659735b Bernd Bleßmann
$(row).data('expanded', 1);
9eb765a5 Bernd Bleßmann
var elt = $(row).find('.expand');
91d46243 Bernd Bleßmann
elt.attr('src', "image/collapse.svg");
9eb765a5 Bernd Bleßmann
elt.attr('alt', kivi.t8('Hide details'));
elt.attr('title', kivi.t8('Hide details'));
};

ns.toggle_second_row = function(row) {
2659735b Bernd Bleßmann
if ($(row).data('expanded') == 1) {
9eb765a5 Bernd Bleßmann
ns.hide_second_row(row);
} else {
ns.show_second_row(row);
}
};
28a7a539 Bernd Bleßmann
0935b012 Bernd Bleßmann
ns.init_row_handlers = function() {
kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
$(elt).change(ns.recalc_amounts_and_taxes);
});

kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
$(elt).change(ns.reformat_number);
});

kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
$(elt).data('oldval', $(elt).val());
$(elt).change(ns.unit_change);
});

kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
$(elt).keydown(function(event) {
37acd860 Bernd Bleßmann
var row;
68da3b40 Bernd Bleßmann
if (event.keyCode == 40 && event.shiftKey === true) {
0935b012 Bernd Bleßmann
// shift arrow down
event.preventDefault();
37acd860 Bernd Bleßmann
row = $(event.target).parents(".row_entry").first();
28a7a539 Bernd Bleßmann
ns.load_second_row(row);
9eb765a5 Bernd Bleßmann
ns.show_second_row(row);
0935b012 Bernd Bleßmann
return false;
}
68da3b40 Bernd Bleßmann
if (event.keyCode == 38 && event.shiftKey === true) {
0935b012 Bernd Bleßmann
// shift arrow up
event.preventDefault();
37acd860 Bernd Bleßmann
row = $(event.target).parents(".row_entry").first();
9eb765a5 Bernd Bleßmann
ns.hide_second_row(row);
0935b012 Bernd Bleßmann
return false;
}
});
});
9eb765a5 Bernd Bleßmann
kivi.run_once_for('.expand', 'expand_second_row', function(elt) {
$(elt).click(function(event) {
event.preventDefault();
var row = $(event.target).parents(".row_entry").first();
ns.load_second_row(row);
ns.toggle_second_row(row);
return false;
})
});

0935b012 Bernd Bleßmann
};

5737ce39 Bernd Bleßmann
ns.redisplay_line_values = function(is_sales, data) {
$('.row_entry').each(function(idx, elt) {
$(elt).find('[name="linetotal"]').html(data[idx][0]);
if (is_sales && $(elt).find('[name="second_row"]').data('loaded') == 1) {
var mt = data[idx][1];
var mp = data[idx][2];
var h = '<span';
if (mt[0] === '-') h += ' class="plus0"';
h += '>' + mt + '&nbsp;&nbsp;' + mp + '%';
h += '</span>';
$(elt).find('[name="linemargin"]').html(h);
}
0935b012 Bernd Bleßmann
});
};

ns.renumber_positions = function() {
$('.row_entry [name="position"]').each(function(idx, elt) {
$(elt).html(idx+1);
});
};

ns.reorder_items = function(order_by) {
var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
$('#row_table_id thead a img').remove();

var src;
if (dir == "1") {
dir = "0";
src = "image/up.png";
} else {
dir = "1";
src = "image/down.png";
7ede2933 Sven Schöling
}
0935b012 Bernd Bleßmann
$('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');

var data = $('#order_form').serializeArray();
68da3b40 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/reorder_items' },
{ name: 'order_by', value: order_by },
{ name: 'sort_dir', value: dir });
0935b012 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.redisplay_items = function(data) {
var old_rows = $('.row_entry').detach();
var new_rows = [];
$(data).each(function(idx, elt) {
new_rows.push(old_rows[elt.old_pos - 1]);
});
$(new_rows).appendTo($('#row_table_id'));
ns.renumber_positions();
};

ns.add_item = function() {
7ede2933 Sven Schöling
if ($('#add_item_parts_id').val() === '') return;
0935b012 Bernd Bleßmann
if (!ns.check_cv()) return;

$('#row_table_id thead a img').remove();

var data = $('#order_form').serializeArray();
data.push({ name: 'action', value: 'Order/add_item' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.show_multi_items_dialog = function() {
if (!ns.check_cv()) return;

$('#row_table_id thead a img').remove();

kivi.popup_dialog({
url: 'controller.pl?action=Order/show_multi_items_dialog',
68da3b40 Bernd Bleßmann
data: { type: $('#type').val(),
callback: 'Order/add_multi_items',
0935b012 Bernd Bleßmann
callback_data_id: 'order_form' },
id: 'jq_multi_items_dialog',
dialog: {
68da3b40 Bernd Bleßmann
title: kivi.t8('Add multiple items'),
0935b012 Bernd Bleßmann
width: 800,
height: 500
}
});
return true;
};

ns.close_multi_items_dialog = function() {
$('#jq_multi_items_dialog').dialog('close');
};

ns.delete_order_item_row = function(clicked) {
var row = $(clicked).parents("tbody").first();
$(row).remove();

ns.renumber_positions();
ns.recalc_amounts_and_taxes();
};

ns.row_table_scroll_down = function() {
$('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
};

ns.show_longdescription_dialog = function(clicked) {
68da3b40 Bernd Bleßmann
var row = $(clicked).parents("tbody").first();
var position = $(row).find('[name="position"]').html();
var partnumber = $(row).find('[name="partnumber"]').html();
var description_elt = $(row).find('[name="order.orderitems[].description"]');
var description = description_elt.val();
0935b012 Bernd Bleßmann
var longdescription_elt = $(row).find('[name="order.orderitems[].longdescription"]');
var longdescription;

if (!longdescription_elt.length) {
68da3b40 Bernd Bleßmann
var data = [
{ name: 'action', value: 'Order/get_item_longdescription' },
{ name: 'type', value: $('#type').val() },
{ name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() },
{ name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() }
];

0935b012 Bernd Bleßmann
$.ajax({
68da3b40 Bernd Bleßmann
url: 'controller.pl',
data: data,
method: "GET",
async: false,
0935b012 Bernd Bleßmann
dataType: 'text',
68da3b40 Bernd Bleßmann
success: function(val) {
0935b012 Bernd Bleßmann
longdescription = val;
}
});
} else {
longdescription = longdescription_elt.val();
}

68da3b40 Bernd Bleßmann
var params = {
runningnumber: position,
partnumber: partnumber,
description: description,
default_longdescription: longdescription,
set_function: function(val) {
longdescription_elt.remove();
$('<input type="hidden" name="order.orderitems[].longdescription">').insertAfter(description_elt).val(val);
}
};
0935b012 Bernd Bleßmann
kivi.SalesPurchase.edit_longdescription_with_params(params);
};

ns.price_chooser_item_row = function(clicked) {
69966b4c Bernd Bleßmann
if (!ns.check_cv()) return;
68da3b40 Bernd Bleßmann
var row = $(clicked).parents("tbody").first();
0935b012 Bernd Bleßmann
var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');

var data = $('#order_form').serializeArray();
68da3b40 Bernd Bleßmann
data.push({ name: 'action', value: 'Order/price_popup' },
{ name: 'item_id', value: item_id_dom.val() });
0935b012 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
68da3b40 Bernd Bleßmann
var row = $('#item_' + item_id).parents("tbody").first();
0935b012 Bernd Bleßmann
var source_elt = $(row).find('[name="order.orderitems[].active_price_source"]');
var button_elt = $(row).find('[name="price_chooser_button"]');

button_elt.val(button_elt.val().replace(/.*\|/, descr + " |"));
source_elt.val(source);

68da3b40 Bernd Bleßmann
var editable_div_elt = $(row).find('[name="editable_price"]');
0935b012 Bernd Bleßmann
var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
7ede2933 Sven Schöling
if (price_editable == 1 && source === '') {
0935b012 Bernd Bleßmann
// editable
$(editable_div_elt).show();
$(not_editable_div_elt).hide();
$(editable_div_elt).find(':input').prop("disabled", false);
$(not_editable_div_elt).find(':input').prop("disabled", true);
} else {
// not editable
$(editable_div_elt).hide();
$(not_editable_div_elt).show();
$(editable_div_elt).find(':input').prop("disabled", true);
$(not_editable_div_elt).find(':input').prop("disabled", false);
}

if (price_str) {
var price_elt = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
var html_elt = $(row).find('[name="sellprice_text"]');
price_elt.val(price_str);
html_elt.html(price_str);
ns.recalc_amounts_and_taxes();
}

kivi.io.close_dialog();
};

ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
68da3b40 Bernd Bleßmann
var row = $('#item_' + item_id).parents("tbody").first();
0935b012 Bernd Bleßmann
var source_elt = $(row).find('[name="order.orderitems[].active_discount_source"]');
var button_elt = $(row).find('[name="price_chooser_button"]');

button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr));
source_elt.val(source);

68da3b40 Bernd Bleßmann
var editable_div_elt = $(row).find('[name="editable_discount"]');
0935b012 Bernd Bleßmann
var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
7ede2933 Sven Schöling
if (price_editable == 1 && source === '') {
0935b012 Bernd Bleßmann
// editable
$(editable_div_elt).show();
$(not_editable_div_elt).hide();
$(editable_div_elt).find(':input').prop("disabled", false);
$(not_editable_div_elt).find(':input').prop("disabled", true);
} else {
// not editable
$(editable_div_elt).hide();
$(not_editable_div_elt).show();
$(editable_div_elt).find(':input').prop("disabled", true);
$(not_editable_div_elt).find(':input').prop("disabled", false);
}

if (discount_str) {
var discount_elt = $(row).find('[name="order.orderitems[].discount_as_percent"]');
var html_elt = $(row).find('[name="discount_text"]');
discount_elt.val(discount_str);
html_elt.html(discount_str);
ns.recalc_amounts_and_taxes();
}

kivi.io.close_dialog();
};

5c859d64 Bernd Bleßmann
ns.show_periodic_invoices_config_dialog = function() {
if ($('#type').val() !== 'sales_order') return;

kivi.popup_dialog({
68da3b40 Bernd Bleßmann
url: 'controller.pl?action=Order/show_periodic_invoices_config_dialog',
data: { type: $('#type').val(),
id: $('#id').val(),
config: $('#order_periodic_invoices_config').val(),
customer_id: $('#order_customer_id').val(),
transdate: $('#order_transdate').val(),
language_id: $('#language_id').val()
},
id: 'jq_periodic_invoices_config_dialog',
load: kivi.reinit_widgets,
5c859d64 Bernd Bleßmann
dialog: {
68da3b40 Bernd Bleßmann
title: kivi.t8('Edit the configuration for periodic invoices'),
5c859d64 Bernd Bleßmann
width: 800,
height: 650
}
});
return true;
};

ns.close_periodic_invoices_config_dialog = function() {
$('#jq_periodic_invoices_config_dialog').dialog('close');
};

ns.assign_periodic_invoices_config = function() {
var data = $('[name="Form"]').serializeArray();
68da3b40 Bernd Bleßmann
data.push({ name: 'type', value: $('#type').val() },
{ name: 'action', value: 'Order/assign_periodic_invoices_config' });
5c859d64 Bernd Bleßmann
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.check_save_active_periodic_invoices = function() {
var type = $('#type').val();
if (type !== 'sales_order') return true;

var active = false;
$.ajax({
68da3b40 Bernd Bleßmann
url: 'controller.pl',
data: { action: 'Order/get_has_active_periodic_invoices',
type : type,
id : $('#id').val(),
config: $('#order_periodic_invoices_config').val(),
},
method: "GET",
async: false,
5c859d64 Bernd Bleßmann
dataType: 'text',
68da3b40 Bernd Bleßmann
success: function(val) {
5c859d64 Bernd Bleßmann
active = val;
}
});

if (active == 1) {
return confirm(kivi.t8('This sales order has an active configuration for periodic invoices. If you save then all subsequently created invoices will contain those changes as well, but not those that have already been created. Do you want to continue?'));
}

return true;
};

aacd6696 Bernd Bleßmann
ns.show_vc_details_dialog = function() {
if (!ns.check_cv()) return;
var vc;
var vc_id;
var title;
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
vc = 'customer';
vc_id = $('#order_customer_id').val();
title = kivi.t8('Customer details');
} else {
vc = 'vendor';
vc_id = $('#order_vendor_id').val();
title = kivi.t8('Vendor details');
}

kivi.popup_dialog({
68da3b40 Bernd Bleßmann
url: 'controller.pl',
data: { action: 'Order/show_customer_vendor_details_dialog',
type : $('#type').val(),
vc : vc,
vc_id : vc_id
},
id: 'jq_customer_vendor_details_dialog',
aacd6696 Bernd Bleßmann
dialog: {
68da3b40 Bernd Bleßmann
title: title,
aacd6696 Bernd Bleßmann
width: 800,
height: 650
}
});
return true;
};

00402ae6 Bernd Bleßmann
ns.show_calculate_qty_dialog = function(clicked) {
68da3b40 Bernd Bleßmann
var row = $(clicked).parents("tbody").first();
var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id');
6770b19a Bernd Bleßmann
var formula_id = $(row).find('[name="formula[+]"]').attr('id');
00402ae6 Bernd Bleßmann
6770b19a Bernd Bleßmann
calculate_qty_selection_dialog("", input_id, "", formula_id);
00402ae6 Bernd Bleßmann
return true;
68da3b40 Bernd Bleßmann
};
00402ae6 Bernd Bleßmann
0935b012 Bernd Bleßmann
});

68da3b40 Bernd Bleßmann
$(function() {
8e77bd29 Bernd Bleßmann
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
96caf7a5 Geoffrey Richardson
$('#order_customer_id').change(kivi.Order.reload_cv_dependant_selections);
0935b012 Bernd Bleßmann
} else {
96caf7a5 Geoffrey Richardson
$('#order_vendor_id').change(kivi.Order.reload_cv_dependant_selections);
0935b012 Bernd Bleßmann
}

8e77bd29 Bernd Bleßmann
if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
0935b012 Bernd Bleßmann
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
} else {
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
}
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
$('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });

$('.add_item_input').keydown(function(event) {
68da3b40 Bernd Bleßmann
if (event.keyCode == 13) {
0935b012 Bernd Bleßmann
event.preventDefault();
kivi.Order.add_item();
return false;
}
});

kivi.Order.init_row_handlers();

$('#row_table_id').on('sortstop', function(event, ui) {
$('#row_table_id thead a img').remove();
kivi.Order.renumber_positions();
});
9eb765a5 Bernd Bleßmann
$('#expand_all').on('click', function(event) {
event.preventDefault();
2659735b Bernd Bleßmann
if ($('#expand_all').data('expanded') == 1) {
$('#expand_all').data('expanded', 0);
91d46243 Bernd Bleßmann
$('#expand_all').attr('src', 'image/expand.svg');
9eb765a5 Bernd Bleßmann
$('#expand_all').attr('alt', kivi.t8('Show all details'));
$('#expand_all').attr('title', kivi.t8('Show all details'));
$('.row_entry').each(function(idx, elt) {
kivi.Order.hide_second_row(elt);
});
} else {
2659735b Bernd Bleßmann
$('#expand_all').data('expanded', 1);
91d46243 Bernd Bleßmann
$('#expand_all').attr('src', "image/collapse.svg");
9eb765a5 Bernd Bleßmann
$('#expand_all').attr('alt', kivi.t8('Hide all details'));
$('#expand_all').attr('title', kivi.t8('Hide all details'));
kivi.Order.load_all_second_rows();
$('.row_entry').each(function(idx, elt) {
kivi.Order.show_second_row(elt);
});
}
return false;
});
2659735b Bernd Bleßmann
0935b012 Bernd Bleßmann
});