Files
ERP_Distribution/Distribution/Features/GeneralLedger/GlJson.cs
T
HarithaRandunu ca81e9bc42 feat: add General Ledger integration and financial reporting features
- Implemented General Ledger client component for managing GL integration.
- Created a dedicated page for General Ledger configuration.
- Developed Finance Report client component for generating various financial reports.
- Added report blocks for structured display of financial data.
- Introduced API endpoints for fetching GL accounts and financial reports.
- Updated navigation to include links for GL integration and financial reports.
- Enhanced permissions to manage GL and view financial reports.
- Updated appsettings to include General Ledger API configuration.
2026-10-20 18:54:30 +05:30

34 lines
1.5 KiB
C#

using System.Text.Json;
namespace Distribution.Features.GeneralLedger;
/// <summary>Small readers for the GL service's ApiResponse envelope ({statusCode, success, message, data}).</summary>
public static class GlJson
{
public static JsonElement? Data(GeneralLedgerResult result) =>
result.Body is { ValueKind: JsonValueKind.Object } body && Get(body, "data") is { } data ? data : null;
public static string? Message(GeneralLedgerResult result) =>
result.Body is { ValueKind: JsonValueKind.Object } body ? Get(body, "message")?.GetString()
?? Get(body, "Message")?.GetString() : null;
/// <summary>Case-insensitive property lookup (GL success bodies are camelCase, its error bodies PascalCase).</summary>
public static JsonElement? Get(JsonElement element, string name)
{
if (element.ValueKind != JsonValueKind.Object) return null;
foreach (var p in element.EnumerateObject())
if (string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) return p.Value;
return null;
}
public static string? GetString(JsonElement element, string name)
{
var v = Get(element, name);
return v is null || v.Value.ValueKind == JsonValueKind.Null ? null
: v.Value.ValueKind == JsonValueKind.String ? v.Value.GetString() : v.Value.ToString();
}
public static long? GetLong(JsonElement element, string name) =>
long.TryParse(GetString(element, name), out var n) ? n : null;
}