Auftragsmaske: JavaScript-Checks für Speichern aktiver per. Rechnungen nach kivi...
[kivitendo-erp.git] / js / kivi.SalesPurchase.js
1 namespace('kivi.SalesPurchase', function(ns) {
2   this.edit_longdescription = function(row) {
3     var $edit    = $('#popup_edit_longdescription_input');
4     var $element = $('#longdescription_' + row);
5
6     if (!$element.length) {
7       console.error("kivi.SalesPurchase.edit_longdescription: Element #longdescription_" + row + " not found");
8       return;
9     }
10
11     $edit.data('element', $element);
12     $edit.val($element.val());
13
14     $('#popup_edit_longdescription_runningnumber').html(row);
15     $('#popup_edit_longdescription_partnumber').html($('#partnumber_' + row).val() || '');
16
17     var description = ($('#description_' + row).val() || '').replace(/[\n\r]+/, '');
18     if (description.length >= 50)
19       description = description.substring(0, 50) + "…";
20     $('#popup_edit_longdescription_description').html(description);
21
22     kivi.popup_dialog({
23       id:    'edit_longdescription_dialog',
24       dialog: {
25         title: kivi.t8('Enter longdescription'),
26         open:  function() { kivi.set_focus('#popup_edit_longdescription_input'); }
27       }
28     });
29   };
30
31   this.set_longdescription = function() {
32     var $edit    = $('#popup_edit_longdescription_input');
33     var $element = $edit.data('element');
34
35     $element.val($edit.val());
36     $('#edit_longdescription_dialog').dialog('close');
37   };
38
39   this.delivery_order_check_transfer_qty = function() {
40     var all_match = true;
41     var rowcount  = $('input[name=rowcount]').val();
42     for (var i = 1; i < rowcount; i++)
43       if ($('#stock_in_out_qty_matches_' + i).val() != 1)
44         all_match = false;
45
46     if (all_match)
47       return true;
48
49     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?'));
50   };
51
52   this.oe_warn_save_active_periodic_invoice = function() {
53     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?'));
54   };
55
56   this.on_submit_checks = function() {
57     var $button = $(this);
58     if (($button.data('check-transfer-qty') == 1) && !kivi.SalesPurchase.delivery_order_check_transfer_qty())
59       return false;
60
61     if (($button.data('warn-save-active-periodic-invoice') == 1) && !kivi.SalesPurchase.oe_warn_save_active_periodic_invoice())
62       return false;
63
64     return true;
65   };
66
67   this.init_on_submit_checks = function() {
68      $('input[type=submit]').click(kivi.SalesPurchase.on_submit_checks);
69   };
70 });