From e984ae5afff6789315c8fe3283c8b5a796ef7162 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 17 Aug 2021 00:38:47 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 71 +++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 72127c3..a339cad 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -355,6 +355,7 @@ namespace AyaNova.PlugIn.V8 await InitInventory(progress); await ExportWarehouses(progress); await ExportParts(progress); + await ExportPartAssemblies(progress); await ExportProjects(progress); if (V7UseInventory) @@ -1637,6 +1638,74 @@ namespace AyaNova.PlugIn.V8 #endregion Parts + + #region Part assemblies + private async System.Threading.Tasks.Task ExportPartAssemblies(ProgressForm progress) + { + ResetUniqueNames(); + if (!progress.KeepGoing) return; + progress.Op("Start part assemblies export"); + progress.SubOp(""); + var ObjectTypeName = "Part Assembly"; + PartAssemblies pa = PartAssemblies.GetItems(); + string crit = " "; + PartList pl = PartList.GetList(crit); + + progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + " part records"); + Guid gCurrentPartAssemblyId = Guid.Empty; + string sCurrentPartAssemblyName = string.Empty; + List partsInAssembly = new List(); + foreach (PartList.PartListInfo i in pl) + { + if (!progress.KeepGoing) return; + //change of assembly in list + if (gCurrentPartAssemblyId != i.LT_O_PartAssembly.Value) + { + if (gCurrentPartAssemblyId != Guid.Empty) + { + foreach (PartAssembly p in pa) + { + if (p.ID == gCurrentPartAssemblyId) + { + //Save the current assembly + dynamic d = new JObject(); + d.name = sCurrentPartAssemblyName; + progress.Op(ObjectTypeName + " " + d.name); + d.active = p.Active; + d.notes = p.Description; + JArray dItems = new JArray(); + foreach (long l in partsInAssembly) + { + dynamic ditem = new JObject(); + ditem.partId = l; + ditem.partAssemblyId = 0; + ditem.quantity = 1; + dItems.Add(ditem); + } + d.items = dItems; + + List tags = new List(); + AddImportTag(tags); + SetTags(d, tags); + var rMainObject = await util.PostAsync("part-assembly", d.ToString()); + long RavenId = util.IdFromResponse(rMainObject); + //Event log fixup + await util.EventLog(util.AyaType.Project, RavenId, SafeGetUserMap(p.Creator), SafeGetUserMap(p.Modifier), p.Created, p.Modified); + break; + }//matches passembly list + }//each partassembly to match + }//not empty + partsInAssembly.Clear(); + gCurrentPartAssemblyId = i.LT_O_PartAssembly.Value; + sCurrentPartAssemblyName = GetUniqueName(i.LT_O_PartAssembly.Display); + } + partsInAssembly.Add(Getv7v8IdMap(i.LT_O_Part.Value, "part id for assembly")); + } + } + #endregion part assemblies + + + #region Warehouses private async System.Threading.Tasks.Task ExportWarehouses(ProgressForm progress) { @@ -3663,7 +3732,7 @@ namespace AyaNova.PlugIn.V8 { JObject jsa = (await util.GetAsync("part/stock-levels/" + v8PartId)).ObjectResponse; bool setMinStock = false; - JArray ja=(JArray)jsa["data"]; + JArray ja = (JArray)jsa["data"]; foreach (JObject js in ja) { if ((long)js["partWarehouseId"] == (long)v8o["partWarehouseId"])