+ 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;
+ };
+
+ 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({
+ 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',
+ dialog: {
+ title: title,
+ width: 800,
+ height: 650
+ }
+ });
+ return true;
+ };
+
+ ns.update_row_from_master_data = function(clicked) {
+ var row = $(clicked).parents("tbody").first();
+ var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
+
+ var data = $('#order_form').serializeArray();
+ data.push({ name: 'action', value: 'Order/update_row_from_master_data' });
+ data.push({ name: 'item_ids[]', value: item_id_dom.val() });
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.update_all_rows_from_master_data = function() {
+ var item_ids = $.map($('.row_entry'), 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/update_row_from_master_data' });
+ data = data.concat(item_ids);
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+ };
+
+ ns.show_calculate_qty_dialog = function(clicked) {
+ var row = $(clicked).parents("tbody").first();
+ var input_id = $(row).find('[name="order.orderitems[].qty_as_number"]').attr('id');
+ var formula_id = $(row).find('[name="formula[+]"]').attr('id');
+
+ calculate_qty_selection_dialog("", input_id, "", formula_id);
+ return true;
+ };
+