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);
 
   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 });
 
  13     $.post("controller.pl", data, kivi.eval_json_result);
 
  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);
 
  25   ns.reload_stocktaking_history = function(target, source) {
 
  26     var data = $('#stocktaking_form').serializeArray();
 
  30       success:    function (rsp) {
 
  32         $(target).find('a.paginate-link').click(function(event){
 
  33           event.preventDefault();
 
  34           kivi.Inventory.reload_stocktaking_history(target, event.target + '')});
 
  39   ns.stocktaking_correct_counted = function() {
 
  40     kivi.Inventory.close_already_counted_dialog();
 
  41     kivi.Inventory.save_stocktaking(1);
 
  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);
 
  51   ns.close_already_counted_dialog = function() {
 
  52     $('#already_counted_dialog').dialog("close");
 
  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');});
 
  62   kivi.Inventory.reload_stocktaking_history('#stocktaking_history', 'controller.pl?action=Inventory/reload_stocktaking_history');