Auftrags-Controller: E-Mail-Dialog aus common verwenden.
[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 });
56
57 $(function(){
58   $('#part_id').change(kivi.Inventory.stocktaking_part_changed);
59   $('#warehouse_id').change(kivi.Inventory.reload_bin_selection);
60   $('#cutoff_date_as_date').change(function() {kivi.Inventory.reload_stocktaking_history('#stocktaking_history', 'controller.pl?action=Inventory/reload_stocktaking_history');});
61
62   kivi.Inventory.reload_stocktaking_history('#stocktaking_history', 'controller.pl?action=Inventory/reload_stocktaking_history');
63 });