diff --git a/devdocs/todo.txt b/devdocs/todo.txt index d8bea6cd..52944b8b 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -6,6 +6,8 @@ Import / export features TODO: OUTSTANDING FOR IMPORT: Unit, Unitmodel, vendor, INVENTORY + HeadOffice contract code sb more like unit contract code with null vs empty handling of json + CustomerBiz contract code sb mroe like unit contract and updateable (update docs too to show it can be updated currently says no) test each object document each object Once all importers are done, add to changes from v7 that import is now built in including UPDATE ability and included with v8 no longer a plugin diff --git a/server/AyaNova/biz/UnitBiz.cs b/server/AyaNova/biz/UnitBiz.cs index 03ef405f..6ff94cc9 100644 --- a/server/AyaNova/biz/UnitBiz.cs +++ b/server/AyaNova/biz/UnitBiz.cs @@ -432,11 +432,9 @@ namespace AyaNova.Biz try { //Compile linked objects if specified - long? ImportCustomerId = -1;//default meaning not included / don't set + long ImportCustomerId = 0; //customer is required, can't be null so set to a definite bad setting if (j["CustomerViz"] != null) { - //something was specified, may be deliberate attempt to null it out so default to that - ImportCustomerId = null; if (!JsonUtil.JTokenIsNullOrEmpty(j["CustomerViz"])) { //a name was specified so attempt to find it @@ -498,26 +496,25 @@ namespace AyaNova.Biz } } - long? ImportContractId = -1; DateTime? ImportContractExpires = null; - if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"])) + if (j["ContractViz"] != null) { - ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync(); - if (ImportContractId == 0) - AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'"); - - if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"])) - ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be - else - ImportContractExpires = (DateTime)j["ContractExpires"]; - + ImportContractId = null; + if (!JsonUtil.JTokenIsNullOrEmpty(j["ContractViz"])) + { + ImportContractId = await ct.Contract.AsNoTracking().Where(z => z.Name == (string)j["ContractViz"]).Select(x => x.Id).FirstOrDefaultAsync(); + if (ImportContractId == 0) + AddError(ApiErrorCode.NOT_FOUND, "ContractViz", $"'{(string)j["ContractViz"]}'"); + if (JsonUtil.JTokenIsNullOrEmpty(j["ContractExpires"])) + ImportContractExpires = DateTime.UtcNow.Subtract(new TimeSpan(0, 1, 0));//expired one minute ago to be safe, can't guess what the contract should be + else + ImportContractExpires = (DateTime)j["ContractExpires"]; + } } - - long existingId = await ct.Unit.AsNoTracking().Where(z => z.Name == (string)j["Name"]).Select(x => x.Id).FirstOrDefaultAsync(); - + long existingId = await ct.Unit.AsNoTracking().Where(z => z.Serial == (string)j["Serial"]).Select(x => x.Id).FirstOrDefaultAsync(); if (existingId == 0) { if (importData.DoImport) @@ -526,24 +523,35 @@ namespace AyaNova.Biz var Target = j.ToObject(jsset); Target.Tags.Add(ImportTag); - if (ImportCustomerId != -1) - Target.ManufacturerId = ImportCustomerId; + Target.CustomerId = ImportCustomerId; if (ImportParentUnitId != -1) - Target.WholeSalerId = ImportParentUnitId; + Target.ParentUnitId = ImportParentUnitId; if (ImportUnitModelId != -1) - Target.AlternativeWholeSalerId = ImportUnitModelId; + Target.UnitModelId = ImportUnitModelId; + + if (ImportPurchasedFromVendorId != -1) + Target.PurchasedFromVendorId = ImportPurchasedFromVendorId; + + if (ImportReplacedByUnitId != -1) + Target.ReplacedByUnitId = ImportReplacedByUnitId; + + if (ImportContractId != -1) + { + Target.ContractId = ImportContractId; + Target.ContractExpires = ImportContractExpires; + } var res = await CreateAsync(Target); if (res == null) { - ImportResult.Add($"❌ {Target.Name}\r\n{this.GetErrorsAsString()}"); + ImportResult.Add($"❌ {Target.Serial}\r\n{this.GetErrorsAsString()}"); this.ClearErrors(); } else { - ImportResult.Add($"✔️ {Target.Name}"); + ImportResult.Add($"✔️ {Target.Serial}"); } } } @@ -556,26 +564,39 @@ namespace AyaNova.Biz var Target = await GetAsync((long)existingId); var Source = j.ToObject(jsset); var propertiesToUpdate = j.Properties().Select(p => p.Name).ToList(); - propertiesToUpdate.Remove("Name"); + propertiesToUpdate.Remove("Serial"); ImportUtil.Update(Source, Target, propertiesToUpdate); - if (ImportCustomerId != -1) - Target.ManufacturerId = ImportCustomerId; + + Target.CustomerId = ImportCustomerId; + if (ImportParentUnitId != -1) - Target.WholeSalerId = ImportParentUnitId; + Target.ParentUnitId = ImportParentUnitId; + if (ImportUnitModelId != -1) - Target.AlternativeWholeSalerId = ImportUnitModelId; + Target.UnitModelId = ImportUnitModelId; + + if (ImportPurchasedFromVendorId != -1) + Target.PurchasedFromVendorId = ImportPurchasedFromVendorId; + + if (ImportReplacedByUnitId != -1) + Target.ReplacedByUnitId = ImportReplacedByUnitId; + + if (ImportContractId != -1) + { + Target.ContractId = ImportContractId; + Target.ContractExpires = ImportContractExpires; + } var res = await PutAsync(Target); if (res == null) { - ImportResult.Add($"❌ {Target.Name} - {this.GetErrorsAsString()}"); + ImportResult.Add($"❌ {Target.Serial} - {this.GetErrorsAsString()}"); this.ClearErrors(); } else { - - ImportResult.Add($"✔️ {Target.Name}"); + ImportResult.Add($"✔️ {Target.Serial}"); } } }