From 8f908a41be9b2d39094f0f65038a17fc0c9e7341 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 16 Aug 2021 22:27:38 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 54 +++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index a9be65a..b98c48d 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -3608,6 +3608,7 @@ namespace AyaNova.PlugIn.V8 { if (!progress.KeepGoing) return; + if (!V7UseInventory) return; progress.Op("Synchronize inventory"); progress.SubOp(""); @@ -3642,10 +3643,61 @@ namespace AyaNova.PlugIn.V8 { progress.SubOp("sync part " + i.Name); PartInventoryList v7inv = PartInventoryList.GetListForSingleItem(i.ID); - JObject v8inv = (await util.GetAsync("part/latest-inventory/" + Getv7v8IdMap(i.ID, "part id for synchronize inventory"))).ObjectResponse; + long v8PartId=Getv7v8IdMap(i.ID, "part id for synchronize inventory"); + JObject v8inv = (await util.GetAsync("part/latest-inventory/" + v8PartId )).ObjectResponse; //iterate v8 inventory foreach (JObject v8o in v8inv["data"]) { + bool handled = false; + decimal dAdjust = 0; + decimal dMinStockLevel = 0; + decimal v8OnHand = (decimal)v8o["balance"]; + foreach (PartInventoryList.PartInventoryListInfo v7o in v7inv) + { + long whsv7tov8id = Getv7v8IdMap(v7o.LT_O_PartWarehouse.Value, "whs for inv sync"); + if (whsv7tov8id == (long)v8o["partWarehouseId"]) + { + //this is the match, do the fixup + //v8 inventory starts with 1 billion so every adjustment will always be *down* + dAdjust = v7o.LT_PartByWarehouseInventory_Label_QuantityOnHand - v8OnHand; + dMinStockLevel = v7o.LT_PartByWarehouseInventory_Label_MinStockLevel; + handled = true; + break; + } + } + if (!handled) + { + //no v7 matching inventory record, maybe no inventory, in any case reset to none in stock in v8 + dAdjust = v8OnHand * -1; + } + + //ok we have our values, send to raven + foreach (long l in Allv8WarehouseIds) + { + dynamic di = new JObject(); + di.description = "v8 migrate synchronize inventory"; + di.partId = v8PartId; + di.partWarehouseId = (long)v8o["partWarehouseId"]; + di.quantity = dAdjust; + await util.PostAsync("part-inventory", di.ToString()); + } + + if (dMinStockLevel > 0) + { + JObject jsa = (await util.GetAsync("part/stock-levels/" + v8PartId)).ObjectResponse; + foreach (JObject js in jsa["data"]) + { + if ((long)js["partWarehouseId"] == (long)v8o["partWarehouseId"]) + { + js["minimumQuantity"] = dMinStockLevel; + await util.PostAsync("part/stock-levels/" + v8PartId, jsa["data"].ToString()); + } + break; + } + + + } + } //find matching v7 item and adjust