Inventur: Schwellwert in Mandantenkonfig. für Warnung bei Mengenabweichung
[kivitendo-erp.git] / js / kivi.Inventory.js
1 namespace('kivi.Inventory', function(ns) {
2   ns.reload_bin_selection = function() {
3     $.post("controller.pl", { action: 'Inventory/warehouse_changed',
4                               warehouse_id: function(){ return $('#warehouse_id').val() } },
5            kivi.eval_json_result);
6   };
7
8   ns.save_stocktaking = function(dont_check_already_counted) {
9     var data = $('#stocktaking_form').serializeArray();
10     data.push({ name: 'action', value: 'Inventory/save_stocktaking' });
11     data.push({ name: 'dont_check_already_counted', value: dont_check_already_counted });
12
13     $.post("controller.pl", data, kivi.eval_json_result);
14   };
15
16   ns.stocktaking_part_changed = function() {
17     var data = $('#stocktaking_form').serializeArray();
18     data.push({ name: 'action', value: 'Inventory/stocktaking_part_changed' });
19     $.post("controller.pl", data, kivi.eval_json_result);
20     $.post("controller.pl", { action: 'Inventory/mini_stock',
21                               part_id: function(){ return $('#part_id').val() } },
22            kivi.eval_json_result);
23   };
24
25   ns.reload_stocktaking_history = function(target, source) {
26     var data = $('#stocktaking_form').serializeArray();
27     $.ajax({
28       url:        source,
29       data:       data,
30       success:    function (rsp) {
31         $(target).html(rsp);
32         $(target).find('a.paginate-link').click(function(event){
33           event.preventDefault();
34           kivi.Inventory.reload_stocktaking_history(target, event.target + '')});
35       }
36     });
37   };
38
39   ns.stocktaking_correct_counted = function() {
40     kivi.Inventory.close_already_counted_dialog();
41     kivi.Inventory.save_stocktaking(1);
42   };
43
44   ns.stocktaking_add_counted = function(qty_to_add_to) {
45     resulting_qty = kivi.parse_amount($('#target_qty').val()) + 1.0*qty_to_add_to;
46     $('#target_qty').val(kivi.format_amount(resulting_qty, -2));
47     kivi.Inventory.close_already_counted_dialog();
48     kivi.Inventory.save_stocktaking(1);
49   };
50
51   ns.close_already_counted_dialog = function() {
52     $('#already_counted_dialog').dialog("close");
53   };
54
55   ns.check_stocktaking_qty_threshold = function() {
56     var data = $('#stocktaking_form').serializeArray();
57     data.push({ name: 'action', value: 'Inventory/stocktaking_get_warn_qty_threshold' });
58
59     var warn = false;
60     $.ajax({
61       url:      'controller.pl',
62       data:     data,
63       method:   "GET",
64       async:    false,
65       dataType: 'text',
66       success:  function(val) {
67         warn = val;
68       }
69     });
70
71     if (warn) {
72       return confirm(warn);
73     } else {
74       return true;
75     }
76   };
77 });
78
79 $(function(){
80   $('#part_id').change(kivi.Inventory.stocktaking_part_changed);
81   $('#warehouse_id').change(kivi.Inventory.reload_bin_selection);
82   $('#cutoff_date_as_date').change(function() {kivi.Inventory.reload_stocktaking_history('#stocktaking_history', 'controller.pl?action=Inventory/reload_stocktaking_history');});
83
84   kivi.Inventory.reload_stocktaking_history('#stocktaking_history', 'controller.pl?action=Inventory/reload_stocktaking_history');
85 });