Volltext-Suche: Tabelle für Texte aus Dateien im DMS. DB und Rose
[kivitendo-erp.git] / js / kivi.DeliveryOrder.js
index f90184f..00a9294 100644 (file)
@@ -78,6 +78,66 @@ namespace('kivi.DeliveryOrder', function(ns) {
     });
   };
 
+  ns.open_stock_in_out_dialog = function(clicked, in_out) {
+    var $row = $(clicked).parents("tbody").first();
+    var id = $row.find('[name="orderitem_ids[+]"]').val();
+    $row.uniqueId();
+
+    kivi.popup_dialog({
+      id: "stock_in_out_dialog",
+      url: "controller.pl?action=DeliveryOrder/stock_in_out_dialog",
+      data: {
+        id:            $("#id").val(),
+        type:          $("#type").val(),
+        parts_id:      $row.find("[name$=parts_id]").val(),
+        unit:          $row.find("[name$=unit]").val(),
+        qty_as_number: $row.find("[name$=qty_as_number]").val(),
+        stock:         $row.find("[name$=stock_info]").val(),
+        item_id:       id,
+        row:           $row.attr("id"),
+      },
+      dialog: { title: kivi.t8('Transfer stock') }
+    });
+  };
+
+  ns.save_updated_stock = function() {
+    // stock information is saved in DOM as a yaml dump.
+    // we don't want to do this in javascript so we do a tiny roundtrip to the backend
+
+    let data = [];
+    $("#stock-in-out-table tr.listrow").each((i,row) => {
+      let qty = kivi.parse_amount($(row).find(".data-qty").val());
+
+      if (qty === 0) return;
+
+      data.push({
+        qty:                           qty,
+        warehouse_id:                  $(row).find(".data-warehouse-id").val(),
+        bin_id:                        $(row).find(".data-bin-id").val(),
+        chargenumber:                  $(row).find(".data-chargenumber").val(),
+        bestbefore:                    $(row).find(".data-bestbefore").val(),
+        unit:                          $(row).find(".data-unit").val(),
+        delivery_order_items_stock_id: $(row).find(".data-stock-id").val(),
+      });
+    });
+
+    let row = $(".data-row").val();
+
+    $.post("controller.pl",
+      kivi.serialize({
+        action:     "DeliveryOrder/update_stock_information",
+        unit:       $("#" + row).find("[name$=unit]").val(),
+        stock_info: data,
+        row:        row
+      }),
+      (data) => {
+        $("#" + row + " .data-stock-info").val(data.stock_info);
+        $("#" + row + " .data-stock-qty").text(data.stock_qty)
+        $("#stock_in_out_dialog").dialog("close");
+      }
+    );
+  };
+
   ns.print = function() {
     $('#print_options').dialog('close');
 
@@ -521,7 +581,7 @@ namespace('kivi.DeliveryOrder', function(ns) {
     var vc;
     var vc_id;
     var title;
-    if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
+    if ($('#order_customer_id').val()) {
       vc    = 'customer';
       vc_id = $('#order_customer_id').val();
       title = kivi.t8('Customer details');
@@ -704,21 +764,13 @@ namespace('kivi.DeliveryOrder', function(ns) {
 });
 
 $(function() {
-  if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
-    $('#order_customer_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
-  } else {
-    $('#order_vendor_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
-  }
+  $('#order_customer_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
+  $('#order_vendor_id').change(kivi.DeliveryOrder.reload_cv_dependent_selections);
 
   $('#order_currency_id').change(kivi.DeliveryOrder.update_exchangerate);
   $('#order_transdate_as_date').change(kivi.DeliveryOrder.update_exchangerate);
   $('#order_exchangerate_as_null_number').change(kivi.DeliveryOrder.exchangerate_changed);
 
-  if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) {
-    $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
-  } else {
-    $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
-  }
   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
   $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });