1 namespace('kivi.SalesPurchase', function(ns) {
2 this.edit_longdescription = function(row) {
3 var $element = $('#longdescription_' + row);
5 if (!$element.length) {
6 console.error("kivi.SalesPurchase.edit_longdescription: Element #longdescription_" + row + " not found");
10 var params = { element: $element,
12 partnumber: $('#partnumber_' + row).val() || '',
13 description: $('#description_' + row).val() || '',
14 default_longdescription: $('#longdescription_' + row).val() || ''
16 this.edit_longdescription_with_params(params);
19 this.edit_longdescription_with_params = function(params) {
20 var $container = $('#popup_edit_longdescription_input_container');
21 var $edit = $('<textarea id="popup_edit_longdescription_input" class="texteditor-in-dialog" wrap="soft" style="width: 750px; height: 220px;"></textarea>');
23 $container.children().remove();
24 $container.append($edit);
27 $container.data('element', params.element);
29 if (params.set_function) {
30 $container.data('setFunction', params.set_function);
33 $edit.val(params.default_longdescription);
35 kivi.init_text_editor($edit);
37 $('#popup_edit_longdescription_runningnumber').html(params.runningnumber);
38 $('#popup_edit_longdescription_partnumber').html(params.partnumber);
40 var description = params.description.replace(/[\n\r]+/, '');
41 if (description.length >= 50)
42 description = description.substring(0, 50) + "…";
43 $('#popup_edit_longdescription_description').html(description);
46 id: 'edit_longdescription_dialog',
48 title: kivi.t8('Enter longdescription'),
49 open: function() { kivi.focus_ckeditor_when_ready('#popup_edit_longdescription_input'); },
50 close: function() { $('#popup_edit_longdescription_input_container').children().remove(); }
55 this.set_longdescription = function() {
56 if ($('#popup_edit_longdescription_input_container').data('setFunction')) {
57 $('#popup_edit_longdescription_input_container').data('setFunction')($('#popup_edit_longdescription_input').val());
59 $('#popup_edit_longdescription_input_container')
61 .val( $('#popup_edit_longdescription_input').val() );
63 $('#edit_longdescription_dialog').dialog('close');
66 this.delivery_order_check_transfer_qty = function() {
68 var rowcount = $('input[name=rowcount]').val();
69 for (var i = 1; i < rowcount; i++)
70 if ($('#stock_in_out_qty_matches_' + i).val() != 1)
76 return confirm(kivi.t8('There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?'));
79 this.oe_warn_save_active_periodic_invoice = function() {
80 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?'));
83 this.check_transaction_description = function() {
84 if ($('#transaction_description').val() !== '')
87 alert(kivi.t8('A transaction description is required.'));
91 this.check_transport_cost_article_presence = function() {
92 var $form = $('#form');
93 var wanted_part_id = $form.data('transport-cost-reminder-article-id');
98 var rowcount = $('#rowcount').val() * 1;
99 for (var row = 1; row <= rowcount; row++)
100 if ( (($('#id_' + row).val() * 1) === wanted_part_id)
101 && (($('#partnumber_' + row).val() || '') !== ''))
104 var description = $form.data('transport-cost-reminder-article-description');
105 return confirm(kivi.t8("The transport cost article '#1' is missing. Do you want to continue anyway?", [ description ]));
108 this.on_submit_checks = function() {
109 var $button = $(this);
110 if (($button.data('check-transfer-qty') == 1) && !kivi.SalesPurchase.delivery_order_check_transfer_qty())
113 if (($button.data('warn-save-active-periodic-invoice') == 1) && !kivi.SalesPurchase.oe_warn_save_active_periodic_invoice())
116 if (($button.data('require-transaction-description') == 1) && !kivi.SalesPurchase.check_transaction_description())
122 this.init_on_submit_checks = function() {
123 $('input[type=submit]').click(kivi.SalesPurchase.on_submit_checks);
126 this.set_duedate_on_reference_date_change = function(reference_field_id) {
127 setTimeout(function() {
129 action: 'set_duedate',
130 invdate: $('#' + reference_field_id).val(),
131 duedate: $('#duedate').val(),
132 payment_id: $('#payment_id').val(),
134 $.post('is.pl', data, kivi.eval_json_result);