-
-<script type='text/javascript'>
-function reload_cv_dependend_selections() {
- var data = $('#order_form').serialize();
- data += '&action=Order/customer_vendor_changed';
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function unit_change(event) {
- var row = $(event.target).parents("tbody").first();
- var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
- var sellprice_dom = $(row).find('[name="order.orderitems[].sellprice_as_number"]');
- var select_elt = $(row).find('[name="order.orderitems[].unit"]');
-
- var oldval = $(select_elt).data('oldval');
- $(select_elt).data('oldval', $(select_elt).val());
-
- var data = $('#order_form').serialize();
- data += '&action=Order/unit_changed';
- data += '&item_id=' + item_id_dom.val();
- data += '&old_unit=' + oldval;
- data += '&sellprice_dom_id=' + sellprice_dom.attr('id');
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function update_sellprice(item_id, price_str) {
- var row = $('#item_' + item_id).parents("tbody").first();
- 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);
-}
-
-function add_item() {
- if ($('#add_item_parts_id').val() == '') return;
- if (!check_cv()) return;
-
- var data = $('#order_form').serialize();
- data += '&action=Order/add_item';
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function show_multi_items_dialog() {
- if (!check_cv()) return;
-
- kivi.popup_dialog({
- url: 'controller.pl?action=Order/show_multi_items_dialog',
- data: { type: $('#type').val(),
- callback: 'Order/add_multi_items',
- callback_data_id: 'order_form' },
- id: 'jq_multi_items_dialog',
- dialog: {
- title: kivi.t8('Add multiple items'),
- width: 800,
- height: 500
- }
- });
- return true;
-}
-
-function close_multi_items_dialog() {
- $('#jq_multi_items_dialog').dialog('close');
-};
-
-function delete_order_item_row(clicked) {
- var row = $(clicked).parents("tbody").first();
- $(row).remove();
-
- recalc_amounts_and_taxes();
-}
-
-function price_chooser_item_row(clicked) {
- var row = $(clicked).parents("tbody").first();
- var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
-
- var data = $('#order_form').serialize();
- data += '&action=Order/price_popup';
- data += '&item_id=' + item_id_dom.val();
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function update_price_source(item_id, source, descr, price_str) {
- var row = $('#item_' + item_id).parents("tbody").first();
- 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);
-
- var editable_div_elt = $(row).find('[name="editable_price"]');
- var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
- if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
- // 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);
- recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
-}
-
-function update_discount_source(item_id, source, descr, discount_str) {
- var row = $('#item_' + item_id).parents("tbody").first();
- 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);
-
- var editable_div_elt = $(row).find('[name="editable_discount"]');
- var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
- if ([%- AUTH.assert('edit_prices', 1) %] == 1 && source == '') {
- // 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);
- recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
-}
-
-function reformat_number(event) {
- $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
-}
-
-function recalc_amounts_and_taxes() {
- var data = $('#order_form').serialize();
- data += '&action=Order/recalc_amounts_and_taxes';
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-function redisplay_linetotals(data) {
- $('.row_entry [name="linetotal"]').each(function(idx, elt) {
- $(elt).html(data[idx]);
- });
-}
-
-function row_table_scroll_down() {
- $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
-}
-
-function row_set_keyboard_events_by_id(item_id) {
- var row = $('#item_' + item_id).parents("tbody").first();
-
- row_set_keyboard_events(row);
-}
-
-function row_set_keyboard_events(rows) {
- $(rows).keydown(function(event) {
- if(event.keyCode == 40 && event.shiftKey == true) {
- // shift arrow down
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').show();
- return false;
- }
- if(event.keyCode == 38 && event.shiftKey == true) {
- // shift arrow up
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').hide();
- return false;
- }
- });
-
- $(rows).dblclick(function(event) {
- event.preventDefault();
- var row = $(event.target).parents(".row_entry").first();
- $(row).children().not(':first').toggle();
- return false;
- });
-}
-
-function set_unit_change_with_oldval_by_id(item_id) {
- var row = $('#item_' + item_id).parents("tbody").first();
- var select_elt = $(row).find('[name="order.orderitems[].unit"]');
-
- set_unit_change_with_oldval(select_elt);
-}
-
-function set_unit_change_with_oldval(selects) {
- selects.each(function(idx,elt) {
- $(elt).data('oldval', $(elt).val());
- });
-
- selects.change(unit_change);
-}
-
-var email_dialog;
-
-function show_email_dialog(html) {
- var id = 'jqueryui_popup_dialog';
- var dialog_params = {
- id: id,
- width: 800,
- height: 500,
- modal: true,
- close: function(event, ui) {
- email_dialog.remove();
- },
- };
-
- $('#' + id).remove();
-
- email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
- email_dialog.html(html);
- email_dialog.dialog(dialog_params);
-
- $('.cancel').click(close_email_dialog);
-
- return true;
-}
-
-close_email_dialog = function() {
- email_dialog.dialog("close");
-}
-
-
-$(function(){
- $('#order_[%- cv_id %]').change(reload_cv_dependend_selections);
- [%- IF SELF.cv == 'customer' %]
- $('#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)) });
- [%- END %]
- $('#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) {
- if(event.keyCode == 13) {
- event.preventDefault();
- add_item();
- return false;
- }
- });
- row_set_keyboard_events($('.row_entry'));
- $('.recalc').change(recalc_amounts_and_taxes);
- $('.reformat_number').change(reformat_number);
-
- set_unit_change_with_oldval($('.unitselect'));
-});
-
-</script>