From 17a42b1571f96ec6cd62e81aec24ea7ed12d3c3f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 24 Aug 2021 20:27:44 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 82 ++++++++++++++++++++------ 1 file changed, 65 insertions(+), 17 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 07ca1c0..ad6d316 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -35,7 +35,7 @@ namespace AyaNova.PlugIn.V8 public string PluginVersion { - get { return "7.6.1-alpha.125"; } + get { return "7.6.1-alpha.126"; } } public string About @@ -220,7 +220,7 @@ namespace AyaNova.PlugIn.V8 //not found, patch allowed, create a substitute record for it and put it in the map if (id == Guid.Empty) - throw new Exception("Error: Getv7v8IdMap (source id: " + id.ToString() + " for type: " + desiredType.ToString() + ") attempt to create substitute record for empty id, this is an unexpected error, please provide full export log to technical support"); + throw new Exception("Error: Getv7v8IdMap (source id: " + id.ToString() + " for type: " + desiredType.ToString() + ") attempt to create substitute record for empty id, this is an unexpected error, please provide full export log to technical support"); await CreateSubstitute(id, desiredType, extraV8Id); } return V7ToV8IdMap[id]; @@ -2338,7 +2338,7 @@ namespace AyaNova.PlugIn.V8 //Event log fixup if (c.ParentID == Guid.Empty && c.ReplacedByUnitID == Guid.Empty) await util.EventLog(util.AyaType.Unit, RavenId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); - + } //################# Now loop through the units again and set parent and replaced ID's @@ -2364,6 +2364,53 @@ namespace AyaNova.PlugIn.V8 await util.EventLog(util.AyaType.Unit, ThisUnitRavenId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); } } + + + + private async System.Threading.Tasks.Task ExportUnitMeterReadings(ProgressForm progress) + { + + if (!progress.KeepGoing) return; + + progress.Op("Start Unit meter readings export"); + progress.SubOp(""); + + //Step 2: export the objects + UnitPickList pl = UnitPickList.GetListOfAll(); + progress.Append("Checking " + pl.Count.ToString() + " units for exportable meter readings"); + + foreach (UnitPickList.UnitPickListInfo i in pl) + { + if (!progress.KeepGoing) return; + Unit c = Unit.GetItem(i.ID); + + //METER READINGS + if (c.Metered) + { + var RavenId = Getv7v8IdMap(c.ID, RootObjectTypes.Unit, false, false); + UnitMeterReadingList uml = UnitMeterReadingList.GetList(c.ID, null); + if (uml.Count > 0) + { + progress.Op(c.Serial + " exporting " + uml.Count.ToString() + " readings"); + foreach (UnitMeterReadingList.UnitMeterReadingListInfo ui in uml) + { + dynamic dm = new JObject(); + dm.meter = ui.LT_UnitMeterReading_Label_Meter; + dm.meterDate = util.DateToV8(ui.LT_UnitMeterReading_Label_MeterDate, true); + dm.notes = ui.LT_UnitMeterReading_Label_Description; + dm.unitId = RavenId; + if (ui.LT_UnitMeterReading_Label_WorkorderItemID.Value != Guid.Empty) + { + //workorder items in v7 are only mapped for this one op and only return the workorderitemUnit id which is + //what v8 uses here if it fails, then if fails and null is ok here + dm.workOrderItemUnitId = Getv7v8IdMapNullOk(ui.LT_UnitMeterReading_Label_WorkorderItemID.Value, RootObjectTypes.WorkorderItem, false); + } + await util.PostAsync("unit/meter-reading", dm); + } + } + } + } + } #endregion Units #region UnitModels @@ -2659,8 +2706,8 @@ namespace AyaNova.PlugIn.V8 //----- //Event log fixup - await util.EventLog(ravenType, RavenId, await Getv7v8IdMap(i.Creator, RootObjectTypes.User),await Getv7v8IdMap(i.Modifier, RootObjectTypes.User), i.Created, i.Modified); - + await util.EventLog(ravenType, RavenId, await Getv7v8IdMap(i.Creator, RootObjectTypes.User), await Getv7v8IdMap(i.Modifier, RootObjectTypes.User), i.Created, i.Modified); + } } @@ -2773,7 +2820,7 @@ namespace AyaNova.PlugIn.V8 //----- //Event log fixup - await util.EventLog(util.AyaType.TaxCode, RavenId, await Getv7v8IdMap(i.Creator, RootObjectTypes.User),await Getv7v8IdMap(i.Modifier, RootObjectTypes.User), i.Created, i.Modified); + await util.EventLog(util.AyaType.TaxCode, RavenId, await Getv7v8IdMap(i.Creator, RootObjectTypes.User), await Getv7v8IdMap(i.Modifier, RootObjectTypes.User), i.Created, i.Modified); } } @@ -2858,7 +2905,7 @@ namespace AyaNova.PlugIn.V8 var rMainObject = await util.PostAsync("work-order-item-priority", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(s.ID, RavenId); - await util.EventLog(util.AyaType.WorkOrderItemPriority, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User),await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); + await util.EventLog(util.AyaType.WorkOrderItemPriority, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User), await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); } @@ -2901,7 +2948,7 @@ namespace AyaNova.PlugIn.V8 long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(s.ID, RavenId); //Event log fixup - await util.EventLog(util.AyaType.WorkOrderStatus, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User),await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); + await util.EventLog(util.AyaType.WorkOrderStatus, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User), await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); } //Second export for workorder items @@ -2918,7 +2965,7 @@ namespace AyaNova.PlugIn.V8 var rMainObject = await util.PostAsync("work-order-item-status", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8WorkOrderItemStatusIdMap(s.ID, RavenId); - await util.EventLog(util.AyaType.WorkOrderItemStatus, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User),await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); + await util.EventLog(util.AyaType.WorkOrderItemStatus, RavenId, await Getv7v8IdMap(s.Creator, RootObjectTypes.User), await Getv7v8IdMap(s.Modifier, RootObjectTypes.User), s.Created, s.Modified); } @@ -3158,7 +3205,7 @@ namespace AyaNova.PlugIn.V8 dwi.requestDate = util.DateToV8(wi.RequestDate);//allow empty dates if empty source dwi.workOrderItemStatusId = Getv7v8WorkOrderItemStatusIdNullOk(wi.WorkorderStatusID); - if (wi.PriorityID!=Guid.Empty && V7ToV8IdMap.ContainsKey(wi.PriorityID)) + if (wi.PriorityID != Guid.Empty && V7ToV8IdMap.ContainsKey(wi.PriorityID)) dwi.workOrderItemPriorityId = V7ToV8IdMap[wi.PriorityID]; dwi.warrantyService = wi.WarrantyService; @@ -3173,7 +3220,7 @@ namespace AyaNova.PlugIn.V8 var ravenwoitemid = util.IdFromResponse(await util.PostAsync("workorder/items", dwi.ToString())); - await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User),await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); + await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User), await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); //##### WORKORDER ITEM UNIT if (wi.UnitID != Guid.Empty) @@ -3697,7 +3744,7 @@ namespace AyaNova.PlugIn.V8 var ravenwoitemid = util.IdFromResponse(await util.PostAsync("quote/items", dwi.ToString())); - await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User),await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); + await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User), await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); //##### WORKORDER ITEM UNIT if (wi.UnitID != Guid.Empty) @@ -4049,7 +4096,7 @@ namespace AyaNova.PlugIn.V8 var ravenwoitemid = util.IdFromResponse(await util.PostAsync("pm/items", dwi.ToString())); - await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User),await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); + await util.EventLog(util.AyaType.WorkOrderItem, ravenwoitemid, await Getv7v8IdMap(wi.Creator, RootObjectTypes.User), await Getv7v8IdMap(wi.Modifier, RootObjectTypes.User), wi.Created, wi.Modified); //##### WORKORDER ITEM UNIT if (wi.UnitID != Guid.Empty) @@ -4443,7 +4490,8 @@ namespace AyaNova.PlugIn.V8 d.unitId = await Getv7v8IdMapNullOk(c.UnitID, RootObjectTypes.Unit, true, false, await Getv7v8IdMap(c.ClientID, RootObjectTypes.Client)); //can't substitute a workorder item if missing so report it and export with null link and move on - if (c.WorkorderItemID != Guid.Empty ) { + if (c.WorkorderItemID != Guid.Empty) + { if (V7ToV8IdMap.ContainsKey(c.WorkorderItemID)) { d.workOrderItemId = V7ToV8IdMap[c.WorkorderItemID]; @@ -4452,9 +4500,9 @@ namespace AyaNova.PlugIn.V8 { //log it as unfixable but still migrated progress.Append("CSR '" + c.Title + "' is linked to a missing workorderitem; this CSR will be migrated but without the link to the workorder"); - } + } } - + d.requestedByUserId = await Getv7v8IdMap(c.Creator, RootObjectTypes.User);//creator should always be a 'outside' user account d.customerReferenceNumber = c.ClientRef; d.priority = (int)c.Priority;//same int value @@ -5314,7 +5362,7 @@ namespace AyaNova.PlugIn.V8 await util.PutAsync("form-custom/" + formCustomKey, d); //Event log fixup - await util.EventLog(util.AyaType.FormCustom, RavenFormCustomId, await Getv7v8IdMap(Creator, RootObjectTypes.User),await Getv7v8IdMap(Modifier, RootObjectTypes.User), Created, Modified); + await util.EventLog(util.AyaType.FormCustom, RavenFormCustomId, await Getv7v8IdMap(Creator, RootObjectTypes.User), await Getv7v8IdMap(Modifier, RootObjectTypes.User), Created, Modified); return ret;