- ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
- 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 (price_editable == 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);
- ns.recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
- };
-
- ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
- 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 (price_editable == 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);
- ns.recalc_amounts_and_taxes();
- }
-
- kivi.io.close_dialog();
- };
-
- ns.show_periodic_invoices_config_dialog = function() {
- if ($('#type').val() !== 'sales_order') return;
-
- kivi.popup_dialog({
- 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_as_date: $('#order_transdate_as_date').val(),
- language_id: $('#language_id').val()
- },
- id: 'jq_periodic_invoices_config_dialog',
- load: kivi.reinit_widgets,
- dialog: {
- title: kivi.t8('Edit the configuration for periodic invoices'),
- 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();
- data.push({ name: 'type', value: $('#type').val() },
- { name: 'action', value: 'Order/assign_periodic_invoices_config' });
- $.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({
- 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,
- dataType: 'text',
- success: function(val) {
- 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;
- };
-