From 3ee6518d62f4086164d64162ed108833f3474e90 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Sat, 2 May 2020 23:50:55 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 68 +++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 66735e5..c81bb3a 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -256,7 +256,7 @@ namespace AyaNova.PlugIn.V8 await ExportClients(progress); await ExportHeadOffices(progress); await ExportContracts(progress); - //await ExportLoanUnits(progress); + await ExportLoanItems(progress); //await ExportParts(progress); //await ExportProjects(progress); //await ExportPurchaseOrders(progress); @@ -682,6 +682,72 @@ namespace AyaNova.PlugIn.V8 } #endregion Contracts + #region LoanItems + private async System.Threading.Tasks.Task ExportLoanItems(ProgressForm progress) + { + if (!progress.KeepGoing) return; + var ObjectTypeName = "LoanItem"; + var RavenObjectName = "LoanUnit"; + //Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too + var ocf = ObjectHasCustomFieldDataToExport(ObjectTypeName); + bool ShouldExportCustom = ocf != null; + var DateCustomFields = await ExportCustomFieldSchema(ocf, ObjectTypeName, RavenObjectName); + + //Step 2: export the objects + PickListAutoComplete pl = PickListAutoComplete.GetList("**", "loanitem"); + progress.Append("Exporting " + pl.Count.ToString() + " " + ObjectTypeName + "s"); + + foreach (PickListAutoComplete.PickListAutoCompleteInfo i in pl) + { + if (!progress.KeepGoing) return; + List tags = new List(); + tags.Add(ImportTag); + + LoanItem c = LoanItem.GetItem(i.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.LoanItem, c.ID); + + dynamic d = new JObject(); + d.name = c.Name; + progress.Op(ObjectTypeName + " " + d.name); + d.active = c.Active; + d.notes = c.Notes; + Tagit(c.RegionID, tags); + SetTags(d, tags); + + var hasWiki = WikiPage.HasWiki(c.ID); + if (hasWiki) + { + d.wiki = GetWikiContent(ObjectTID); + } + + //Custom fields? + if (ShouldExportCustom) + d.customFields = CustomFieldData(c, DateCustomFields); + + var rMainObject = await util.PostAsync(RavenObjectName, d.ToString()); + long RavenId = util.IdFromResponse(rMainObject); + Map.Add(c.ID, RavenId); + + //Attachments / FILES + await ExportAttachments(ObjectTID, progress); + + //docs + string NonFileUrls = await ExportDocs(ObjectTID, c.Docs, progress); + if (!string.IsNullOrEmpty(NonFileUrls)) + { + //need to repost the object with the notes modified + d = rMainObject.ObjectResponse["data"]; + d.notes = NonFileUrls + "\n-----------------\n" + d.notes; + await util.PutAsync(RavenObjectName + "/" + RavenId.ToString(), d.ToString()); + } + + //Event log fixup + await util.EventLog(util.AyaType.LoanUnit, RavenId, SafeGetUserMap(c.Creator), SafeGetUserMap(c.Modifier), c.Created, c.Modified); + + } + } + #endregion LoanItems + #region locales private async System.Threading.Tasks.Task ExportLocales(ProgressForm progress)