Compare commits
2 Commits
cd4c233b60
...
99deca3b62
| Author | SHA1 | Date | |
|---|---|---|---|
| 99deca3b62 | |||
| 23e64829bb |
@@ -3051,6 +3051,15 @@ public class CompanySettingsController : Controller
|
||||
var companyId = _tenantContext.GetCurrentCompanyId()!.Value;
|
||||
var templates = await _unitOfWork.CustomItemTemplates.FindAsync(t => t.CompanyId == companyId);
|
||||
|
||||
// Parse FieldsJson into a real JsonElement so it is embedded as a proper JSON array
|
||||
// in the export file rather than as an escaped string. This makes the file human-readable
|
||||
// and avoids round-trip corruption when files are manually edited.
|
||||
static System.Text.Json.JsonElement ParseFields(string? raw)
|
||||
{
|
||||
try { return System.Text.Json.JsonDocument.Parse(raw ?? "[]").RootElement.Clone(); }
|
||||
catch { return System.Text.Json.JsonDocument.Parse("[]").RootElement.Clone(); }
|
||||
}
|
||||
|
||||
var export = new
|
||||
{
|
||||
exportedAt = DateTime.UtcNow,
|
||||
@@ -3062,7 +3071,7 @@ public class CompanySettingsController : Controller
|
||||
t.Name,
|
||||
t.Description,
|
||||
t.OutputMode,
|
||||
t.FieldsJson,
|
||||
Fields = ParseFields(t.FieldsJson),
|
||||
t.Formula,
|
||||
t.DefaultRate,
|
||||
t.RateLabel,
|
||||
@@ -3142,13 +3151,14 @@ public class CompanySettingsController : Controller
|
||||
Name = name,
|
||||
Description = item.TryGetProperty("description", out var d) ? d.GetString() : null,
|
||||
OutputMode = item.TryGetProperty("outputMode", out var om) ? om.GetString() ?? "FixedRate" : "FixedRate",
|
||||
FieldsJson = item.TryGetProperty("fieldsJson", out var fj) ? fj.GetString() ?? "[]" : "[]",
|
||||
// "fields" is a real JSON array in the export; GetRawText() reconstructs the string
|
||||
FieldsJson = item.TryGetProperty("fields", out var fj) ? fj.GetRawText() : "[]",
|
||||
Formula = item.TryGetProperty("formula", out var f) ? f.GetString() ?? "" : "",
|
||||
DefaultRate = item.TryGetProperty("defaultRate", out var dr) && dr.ValueKind == System.Text.Json.JsonValueKind.Number ? dr.GetDecimal() : null,
|
||||
RateLabel = item.TryGetProperty("rateLabel", out var rl) ? rl.GetString() : null,
|
||||
Notes = item.TryGetProperty("notes", out var n) ? n.GetString() : null,
|
||||
DisplayOrder = item.TryGetProperty("displayOrder", out var dord) && dord.ValueKind == System.Text.Json.JsonValueKind.Number ? dord.GetInt32() : 0,
|
||||
IsActive = item.TryGetProperty("isActive", out var ia) && ia.ValueKind == System.Text.Json.JsonValueKind.True,
|
||||
IsActive = true,
|
||||
};
|
||||
|
||||
var fieldError = ValidateTemplateFields(dto.FieldsJson);
|
||||
|
||||
Reference in New Issue
Block a user