From e809d4e080a8fa4dc1b058769e75c1464708458a Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 20 Aug 2021 22:07:08 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 126 ++++++++++++++----------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 9fc4d34..1f704b2 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -277,6 +277,7 @@ namespace AyaNova.PlugIn.V8 case RootObjectTypes.User: { route = "user"; + d.userType = 1;//scheduleable user in case on workorder but not active so not consuming a license } break; case RootObjectTypes.Project: @@ -633,7 +634,7 @@ namespace AyaNova.PlugIn.V8 d.users = duserid; d.memo = dmemo; - await util.PostAsync("memo", d.ToString()); + await util.PostAsync("memo", d); } catch (Exception ex) { @@ -685,7 +686,7 @@ namespace AyaNova.PlugIn.V8 d.login = null; d.password = null; d.notes = d.notes + "\n-----------------\n" + NonFileUrls; - await util.PutAsync("user", d.ToString()); + await util.PutAsync("user", d); } string adminCustomFields = null; @@ -706,7 +707,7 @@ namespace AyaNova.PlugIn.V8 d.customFields = CustomFieldData(admin, DateCustomFields); d.login = null;//do not update the login / password d.password = null; - await util.PutAsync("user", d.ToString()); + await util.PutAsync("user", d); } @@ -822,7 +823,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("user", d.ToString()); + await util.PutAsync("user", d); //----- } @@ -999,7 +1000,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("user", d.ToString()); + await util.PutAsync("user", d); //----- } @@ -1185,7 +1186,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("customer", d.ToString()); + await util.PutAsync("customer", d); //----- //Event log fixup @@ -1212,7 +1213,7 @@ namespace AyaNova.PlugIn.V8 - var rContact = await util.PostAsync("user", d.ToString()); + var rContact = await util.PostAsync("user", d); long RavenContactId = util.IdFromResponse(rContact); @@ -1228,7 +1229,7 @@ namespace AyaNova.PlugIn.V8 // d.translationId = 1; - await util.PutAsync("user-option/" + RavenContactId.ToString(), d.ToString()); + await util.PutAsync("user-option/" + RavenContactId.ToString(), d); //Event log fixup (using customer data since the contact is created from the customer) await util.EventLog(util.AyaType.User, RavenContactId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); @@ -1373,7 +1374,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("head-office", d.ToString()); + var rMainObject = await util.PostAsync("head-office", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -1399,7 +1400,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("head-office", d.ToString()); + await util.PutAsync("head-office", d); //----- //Event log fixup @@ -1428,7 +1429,7 @@ namespace AyaNova.PlugIn.V8 - var rContact = await util.PostAsync("user", d.ToString()); + var rContact = await util.PostAsync("user", d); long RavenContactId = util.IdFromResponse(rContact); @@ -1444,7 +1445,7 @@ namespace AyaNova.PlugIn.V8 // d.translationId = 1; - await util.PutAsync("user-option/" + RavenContactId.ToString(), d.ToString()); + await util.PutAsync("user-option/" + RavenContactId.ToString(), d); //Event log fixup (using customer data since the contact is created from the customer) await util.EventLog(util.AyaType.User, RavenContactId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); @@ -1530,7 +1531,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("contract", d.ToString()); + var rMainObject = await util.PostAsync("contract", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -1556,7 +1557,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("contract", d.ToString()); + await util.PutAsync("contract", d); //----- //Event log fixup @@ -1619,7 +1620,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("loan-unit", d.ToString()); + var rMainObject = await util.PostAsync("loan-unit", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -1645,7 +1646,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("loan-unit", d.ToString()); + await util.PutAsync("loan-unit", d); //----- //Event log fixup @@ -1669,7 +1670,7 @@ namespace AyaNova.PlugIn.V8 var a = await util.GetAsync("global-biz-setting"); dynamic d = a.ObjectResponse["data"]; d.useInventory = false; - await util.PutAsync("global-biz-setting", d.ToString()); + await util.PutAsync("global-biz-setting", d); return; } progress.Append("Info: v7 Use inventory is Active"); @@ -1737,7 +1738,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("part", d.ToString()); + var rMainObject = await util.PostAsync("part", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -1763,7 +1764,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("part", d.ToString()); + await util.PutAsync("part", d); //----- //Event log fixup @@ -1860,7 +1861,7 @@ namespace AyaNova.PlugIn.V8 List tags = new List(); AddImportTag(tags); SetTags(d, tags); - var rMainObject = await util.PostAsync("part-assembly", d.ToString()); + var rMainObject = await util.PostAsync("part-assembly", d); long RavenId = util.IdFromResponse(rMainObject); //Event log fixup long lCreator = await Getv7v8IdMap(p.Creator, RootObjectTypes.User); @@ -1902,7 +1903,7 @@ namespace AyaNova.PlugIn.V8 d.notes = i.Description; TagFromv7Guid(i.RegionID, tags); SetTags(d, tags); - var rMainObject = await util.PostAsync("part-warehouse", d.ToString()); + var rMainObject = await util.PostAsync("part-warehouse", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(i.ID, RavenId); Allv8WarehouseIds.Add(RavenId); @@ -1953,7 +1954,7 @@ namespace AyaNova.PlugIn.V8 //Custom fields? if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("project", d.ToString()); + var rMainObject = await util.PostAsync("project", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); //Attachments / FILES @@ -1976,7 +1977,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("project", d.ToString()); + await util.PutAsync("project", d); //----- //Event log fixup @@ -2126,7 +2127,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("purchase-order", d.ToString()); + var rMainObject = await util.PostAsync("purchase-order", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -2146,7 +2147,7 @@ namespace AyaNova.PlugIn.V8 if (repost) - await util.PutAsync("purchase-order", d.ToString()); + await util.PutAsync("purchase-order", d); //----- //Event log fixup @@ -2202,7 +2203,7 @@ namespace AyaNova.PlugIn.V8 dTasks.Add(dtask); } d.items = dTasks; - var rMainObject = await util.PostAsync("task-group", d.ToString()); + var rMainObject = await util.PostAsync("task-group", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); await util.EventLog(util.AyaType.Project, RavenId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); @@ -2295,7 +2296,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("unit", d.ToString()); + var rMainObject = await util.PostAsync("unit", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -2321,7 +2322,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("unit", d.ToString()); + await util.PutAsync("unit", d); //----- //DONT DO THIS for second steppers UNTIL THE SECOND STEP BELOW OR IT WILL BE WRONG for them @@ -2348,7 +2349,7 @@ namespace AyaNova.PlugIn.V8 d.replacedByUnitId = await Getv7v8IdMapNullOk(c.ReplacedByUnitID, RootObjectTypes.Unit); d.parentUnitId = await Getv7v8IdMapNullOk(c.ParentID, RootObjectTypes.Unit); if (d.parentUnitId != null || d.replacedByUnitId != null) - await util.PutAsync("unit", d.ToString()); + await util.PutAsync("unit", d); //----- //Event log fixup await util.EventLog(util.AyaType.Unit, ThisUnitRavenId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); @@ -2422,7 +2423,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("unit-model", d.ToString()); + var rMainObject = await util.PostAsync("unit-model", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -2447,7 +2448,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("unit-model", d.ToString()); + await util.PutAsync("unit-model", d); //----- //Event log fixup @@ -2538,7 +2539,7 @@ namespace AyaNova.PlugIn.V8 if (ShouldExportCustom) d.customFields = CustomFieldData(c, DateCustomFields); - var rMainObject = await util.PostAsync("vendor", d.ToString()); + var rMainObject = await util.PostAsync("vendor", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -2563,7 +2564,7 @@ namespace AyaNova.PlugIn.V8 repost = true; } if (repost) - await util.PutAsync("vendor", d.ToString()); + await util.PutAsync("vendor", d); //----- //Event log fixup @@ -2638,7 +2639,7 @@ namespace AyaNova.PlugIn.V8 ravenType = util.AyaType.TravelRate; } - var rMainObject = await util.PostAsync(route, d.ToString()); + var rMainObject = await util.PostAsync(route, d); long RavenId = util.IdFromResponse(rMainObject); if (isTravelRate) TravelRateMap.Add(i.ID, RavenId); @@ -2755,7 +2756,7 @@ namespace AyaNova.PlugIn.V8 SetTags(d, tags); - var rMainObject = await util.PostAsync("tax-code", d.ToString()); + var rMainObject = await util.PostAsync("tax-code", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(i.ID, RavenId); @@ -2808,7 +2809,7 @@ namespace AyaNova.PlugIn.V8 progress.Op(ObjectTypeName + " " + mem.ID.ToString()); - var rMainObject = await util.PostAsync("memo", d.ToString()); + var rMainObject = await util.PostAsync("memo", d); long RavenId = util.IdFromResponse(rMainObject); //Event log fixup await util.EventLog(util.AyaType.Memo, RavenId, RavenFromId, RavenFromId, mem.Created, mem.Modified); @@ -2845,7 +2846,7 @@ namespace AyaNova.PlugIn.V8 d.active = s.Active; d.color = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(s.Color)); SetTags(d, tags); - var rMainObject = await util.PostAsync("work-order-item-priority", d.ToString()); + 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); @@ -2887,7 +2888,7 @@ namespace AyaNova.PlugIn.V8 d.removeRoles = 1290; d.color = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(s.ARGB)); SetTags(d, tags); - var rMainObject = await util.PostAsync("work-order-status", d.ToString()); + var rMainObject = await util.PostAsync("work-order-status", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(s.ID, RavenId); //Event log fixup @@ -2905,7 +2906,7 @@ namespace AyaNova.PlugIn.V8 d.active = s.Active; d.color = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(s.ARGB)); SetTags(d, tags); - var rMainObject = await util.PostAsync("work-order-item-status", d.ToString()); + 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); @@ -2927,7 +2928,7 @@ namespace AyaNova.PlugIn.V8 d.color = "#000000"; d.notes = "This status automatically created by the v8 migrate process for closed work orders"; SetTags(d, tags); - var rMainObject = await util.PostAsync("work-order-status", d.ToString()); + var rMainObject = await util.PostAsync("work-order-status", d); ClosedWorkOrderStatus = util.IdFromResponse(rMainObject); //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); @@ -2948,7 +2949,7 @@ namespace AyaNova.PlugIn.V8 d.color = "#BBBBBB"; d.notes = "This status automatically created by the v8 migrate process for service completed work orders"; SetTags(d, tags); - var rMainObject = await util.PostAsync("work-order-status", d.ToString()); + var rMainObject = await util.PostAsync("work-order-status", d); ServiceCompletedWorkOrderStatus = util.IdFromResponse(rMainObject); //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); @@ -3059,7 +3060,7 @@ namespace AyaNova.PlugIn.V8 SetTags(d, tags); - var rMainObject = await util.PostAsync("workorder", d.ToString()); + var rMainObject = await util.PostAsync("workorder", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); d = rMainObject.ObjectResponse["data"]; @@ -3091,7 +3092,7 @@ namespace AyaNova.PlugIn.V8 } //put the header object - await util.PutAsync("workorder", d.ToString()); + await util.PutAsync("workorder", d); //----- //Event log fixup @@ -3148,7 +3149,7 @@ namespace AyaNova.PlugIn.V8 dwi.requestDate = util.DateToV8(wi.RequestDate);//allow empty dates if empty source dwi.workOrderItemStatusId = Getv7v8WorkOrderItemStatusIdNullOk(wi.WorkorderStatusID); - if (V7ToV8IdMap.ContainsKey(wi.PriorityID)) + if (wi.PriorityID!=Guid.Empty && V7ToV8IdMap.ContainsKey(wi.PriorityID)) dwi.workOrderItemPriorityId = V7ToV8IdMap[wi.PriorityID]; dwi.warrantyService = wi.WarrantyService; @@ -3612,7 +3613,7 @@ namespace AyaNova.PlugIn.V8 SetTags(d, tags); - var rMainObject = await util.PostAsync("quote", d.ToString()); + var rMainObject = await util.PostAsync("quote", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); d = rMainObject.ObjectResponse["data"]; @@ -3633,7 +3634,7 @@ namespace AyaNova.PlugIn.V8 d.notes = d.notes + "\n-----------------\n" + NonFileUrls; //put the header object - await util.PutAsync("quote", d.ToString()); + await util.PutAsync("quote", d); //----- //Event log fixup @@ -3673,7 +3674,7 @@ namespace AyaNova.PlugIn.V8 dwi.techNotes = wi.TechNotes; dwi.requestDate = util.DateToV8(wi.RequestDate);//allow empty dates if empty source dwi.workOrderItemStatusId = Getv7v8WorkOrderItemStatusIdNullOk(wi.WorkorderStatusID); - if (V7ToV8IdMap.ContainsKey(wi.PriorityID)) + if (wi.PriorityID != Guid.Empty && V7ToV8IdMap.ContainsKey(wi.PriorityID)) dwi.workOrderItemPriorityId = V7ToV8IdMap[wi.PriorityID]; dwi.warrantyService = wi.WarrantyService; @@ -3978,7 +3979,7 @@ namespace AyaNova.PlugIn.V8 SetTags(d, tags); util.ApiResponse rMainObject = null; - rMainObject = await util.PostAsync("pm", d.ToString()); + rMainObject = await util.PostAsync("pm", d); long RavenId = util.IdFromResponse(rMainObject); @@ -4001,7 +4002,7 @@ namespace AyaNova.PlugIn.V8 d.notes = d.notes + "\n-----------------\n" + NonFileUrls; //put the header object - await util.PutAsync("pm", d.ToString()); + await util.PutAsync("pm", d); //----- @@ -4025,7 +4026,7 @@ namespace AyaNova.PlugIn.V8 dwi.techNotes = wi.TechNotes; dwi.requestDate = util.DateToV8(wi.RequestDate);//allow empty dates if empty source dwi.workOrderItemStatusId = Getv7v8WorkOrderItemStatusIdNullOk(wi.WorkorderStatusID); - if (V7ToV8IdMap.ContainsKey(wi.PriorityID)) + if (wi.PriorityID != Guid.Empty && V7ToV8IdMap.ContainsKey(wi.PriorityID)) dwi.workOrderItemPriorityId = V7ToV8IdMap[wi.PriorityID]; dwi.warrantyService = wi.WarrantyService; @@ -4262,7 +4263,7 @@ namespace AyaNova.PlugIn.V8 d.objectType = util.RootObjectToAyaType(c.FollowType); SetTags(d, tags); progress.Op("FollowUp " + c.ID.ToString()); - var rMainObject = await util.PostAsync("review", d.ToString()); + var rMainObject = await util.PostAsync("review", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); await util.EventLog(util.AyaType.Review, RavenId, await Getv7v8IdMap(c.Creator, RootObjectTypes.User), await Getv7v8IdMap(c.Modifier, RootObjectTypes.User), c.Created, c.Modified); @@ -4303,7 +4304,7 @@ namespace AyaNova.PlugIn.V8 d.color = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.ARGB)); SetTags(d, tags); progress.Op("ScheduleMarker " + c.ID.ToString()); - var rMainObject = await util.PostAsync("reminder", d.ToString()); + var rMainObject = await util.PostAsync("reminder", d); long RavenId = util.IdFromResponse(rMainObject); if (!V7ToV8IdMap.ContainsKey(c.ID)) Addv7v8IdMap(c.ID, RavenId); @@ -4380,7 +4381,7 @@ namespace AyaNova.PlugIn.V8 // d.lastHoursBalance = iLast.LT_ServiceBank_Label_HoursBalance; // } - // var rMainObject = await util.PostAsync("service-bank/migrate", d.ToString()); + // var rMainObject = await util.PostAsync("service-bank/migrate", d); // long RavenId = util.IdFromResponse(rMainObject); // // Addv7v8IdMap(i.ID, RavenId); @@ -4431,7 +4432,20 @@ namespace AyaNova.PlugIn.V8 d.dateRequested = util.DateToV8(c.Created, true); d.customerId = await Getv7v8IdMap(c.ClientID, RootObjectTypes.Client); d.unitId = await Getv7v8IdMapNullOk(c.UnitID, RootObjectTypes.Unit, true, false, await Getv7v8IdMap(c.ClientID, RootObjectTypes.Client)); - d.workOrderItemId = await Getv7v8IdMapNullOk(c.WorkorderItemID, RootObjectTypes.WorkorderItem, false, false); + + //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 (V7ToV8IdMap.ContainsKey(c.WorkorderItemID)) + { + d.workOrderItemId = V7ToV8IdMap[c.WorkorderItemID]; + } + else + { + //log it as unfixable but still migrated + progress.Append("CSR '" + c.Title + "' is linked to a missing work order item record. This cannot be fixed automatically; this CSR will still be migrated but without the link to the missing work order item record"); + } + } + 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 @@ -4454,7 +4468,7 @@ namespace AyaNova.PlugIn.V8 - var rMainObject = await util.PostAsync("csr", d.ToString()); + var rMainObject = await util.PostAsync("csr", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -5288,7 +5302,7 @@ namespace AyaNova.PlugIn.V8 var RavenFormCustomId = util.IdFromResponse(a); var ctoken = util.CTokenFromResponse(a); d.concurrency = ctoken; - await util.PutAsync("form-custom/" + formCustomKey, d.ToString()); + 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);