From 576745c20e054363e042b73451f91c453565067a Mon Sep 17 00:00:00 2001 From: Ishan Pranav Date: Tue, 20 Aug 2024 10:47:50 -0700 Subject: [PATCH] Add account summary --- src/Liber.Forms/FormattedStrings.resx | 3 + src/Liber.Forms/Liber.Forms.csproj | 4 ++ src/Liber.Forms/Reports/ReportData.cs | 11 ---- src/Liber.Forms/Reports/Xsl/XslReport.cs | 10 +-- src/Liber.Forms/Reports/Xsl/XslReportView.cs | 8 +-- src/Liber.Forms/data/reports.json | 21 ++----- src/Liber.Forms/styles/account-summary.xslt | 64 ++++++++++++++++++++ src/Liber.Sqlite/SqliteSerializer.cs | 6 +- src/Liber/Account.cs | 1 + src/Liber/Company.cs | 1 - src/Liber/{EquityModes.cs => ReportTypes.cs} | 7 ++- 11 files changed, 94 insertions(+), 42 deletions(-) delete mode 100644 src/Liber.Forms/Reports/ReportData.cs create mode 100644 src/Liber.Forms/styles/account-summary.xslt rename src/Liber/{EquityModes.cs => ReportTypes.cs} (67%) diff --git a/src/Liber.Forms/FormattedStrings.resx b/src/Liber.Forms/FormattedStrings.resx index 52f5a77..94d42d5 100644 --- a/src/Liber.Forms/FormattedStrings.resx +++ b/src/Liber.Forms/FormattedStrings.resx @@ -127,6 +127,9 @@ Account + + Account Summary + ({0:n0} accounts) diff --git a/src/Liber.Forms/Liber.Forms.csproj b/src/Liber.Forms/Liber.Forms.csproj index 9a167a7..abc6361 100644 --- a/src/Liber.Forms/Liber.Forms.csproj +++ b/src/Liber.Forms/Liber.Forms.csproj @@ -31,6 +31,7 @@ + @@ -119,6 +120,9 @@ Always + + Always + Always diff --git a/src/Liber.Forms/Reports/ReportData.cs b/src/Liber.Forms/Reports/ReportData.cs deleted file mode 100644 index 5203076..0000000 --- a/src/Liber.Forms/Reports/ReportData.cs +++ /dev/null @@ -1,11 +0,0 @@ -// ReportData.cs -// Copyright (c) 2023-2024 Ishan Pranav. All rights reserved. -// Licensed under the MIT License. - -namespace Liber.Forms.Reports; - -public class ReportData -{ - public EquityModes EquityMode { get; set; } - public bool CashBasis { get; set; } -} diff --git a/src/Liber.Forms/Reports/Xsl/XslReport.cs b/src/Liber.Forms/Reports/Xsl/XslReport.cs index 9ed777f..3989814 100644 --- a/src/Liber.Forms/Reports/Xsl/XslReport.cs +++ b/src/Liber.Forms/Reports/Xsl/XslReport.cs @@ -110,7 +110,7 @@ public DateTime Posted public Regex Filter { get; set; } = Filters.Any(); [Browsable(false)] - public ReportData Metadata { get; set; } = new ReportData(); + public ReportTypes Type { get; set; } [LocalizedCategory(nameof(Accounts))] [LocalizedDescription(nameof(Accounts))] @@ -226,7 +226,7 @@ void IXmlSerializable.ReadXml(XmlReader reader) private void WriteAccountXml(XmlWriter writer, Account value) { - if (Metadata.CashBasis && value.Adjustment) + if (Type.HasFlag(ReportTypes.CashBasis) && value.Adjustment) { return; } @@ -244,14 +244,14 @@ private void WriteAccountXml(XmlWriter writer, Account value) { writer.WriteElementString("equity", XmlConvert.ToString(true)); - if (Metadata.EquityMode.HasFlag(EquityModes.CurrentPosted)) + if (Type.HasFlag(ReportTypes.CurrentPosted)) { balance = Company.GetEquity(Posted, Filter); } - if (Metadata.EquityMode.HasFlag(EquityModes.CurrentStarted)) + if (Type.HasFlag(ReportTypes.CurrentStarted)) { - balance = Company.GetEquity(Started, Filter); + balance = Company.GetEquity(Started.AddDays(-1), Filter); } previous = Company.GetEquity(Started, Filter); diff --git a/src/Liber.Forms/Reports/Xsl/XslReportView.cs b/src/Liber.Forms/Reports/Xsl/XslReportView.cs index f10bd63..6855377 100644 --- a/src/Liber.Forms/Reports/Xsl/XslReportView.cs +++ b/src/Liber.Forms/Reports/Xsl/XslReportView.cs @@ -14,7 +14,7 @@ internal sealed class XslReportView : IReportView { private static readonly Dictionary s_styles = new Dictionary(); - private static Dictionary? s_reports; + private static Dictionary? s_reports; private readonly string _path; private readonly XslReport _report; @@ -45,9 +45,9 @@ public object Properties public void InitializeReport() { - if (s_reports != null && s_reports.TryGetValue(Path.GetFileNameWithoutExtension(_path), out ReportData? value)) + if (s_reports != null && s_reports.TryGetValue(Path.GetFileNameWithoutExtension(_path), out ReportTypes value)) { - _report.Metadata = value; + _report.Type = value; } if (!s_styles.TryGetValue(_path, out XslCompiledTransform? style)) @@ -73,6 +73,6 @@ public static void InitializeReports(string path) using FileStream input = File.OpenRead(path); - s_reports = JsonSerializer.Deserialize>(input, FormattedStrings.JsonOptions); + s_reports = JsonSerializer.Deserialize>(input, FormattedStrings.JsonOptions); } } diff --git a/src/Liber.Forms/data/reports.json b/src/Liber.Forms/data/reports.json index 75d713f..1b1a469 100644 --- a/src/Liber.Forms/data/reports.json +++ b/src/Liber.Forms/data/reports.json @@ -1,17 +1,8 @@ { - "trial-balance": { - "equityMode": "CurrentStarted" - }, - "balance-sheet": { - "equityMode": "CurrentPosted" - }, - "comparative-balance-sheet": { - "equityMode": "CurrentPosted" - }, - "equity-statement": { - "equityMode": "CurrentPosted" - }, - "cash-flow-statement": { - "cashBasis": true - } + "trial-balance": "CurrentStarted", + "balance-sheet": "CurrentPosted", + "comparative-balance-sheet": "CurrentPosted", + "equity-statement": "CurrentPosted", + "cash-flow-statement": "CashBasis", + "account-summary": "CurrentStarted" } diff --git a/src/Liber.Forms/styles/account-summary.xslt b/src/Liber.Forms/styles/account-summary.xslt new file mode 100644 index 0000000..0fae3a6 --- /dev/null +++ b/src/Liber.Forms/styles/account-summary.xslt @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Liber.Sqlite/SqliteSerializer.cs b/src/Liber.Sqlite/SqliteSerializer.cs index a2a35c0..9dee5cc 100644 --- a/src/Liber.Sqlite/SqliteSerializer.cs +++ b/src/Liber.Sqlite/SqliteSerializer.cs @@ -202,9 +202,9 @@ public static async Task DeserializeAsync(string path, string password) Description = await GetStringAsync(reader, 6), Memo = await GetStringAsync(reader, 7), Color = await GetColorAsync(reader, 8), - TaxType = TaxType.None, - Inactive = reader.GetBoolean(9), - Adjustment = reader.GetBoolean(10) + TaxType = await reader.GetFieldValueAsync(9), + Inactive = reader.GetBoolean(10), + Adjustment = reader.GetBoolean(11) }); } } diff --git a/src/Liber/Account.cs b/src/Liber/Account.cs index 3d57a59..816a568 100644 --- a/src/Liber/Account.cs +++ b/src/Liber/Account.cs @@ -127,6 +127,7 @@ public Account(Guid parentId) /// Gets or sets the color associated with the account. /// /// The color associated with the account. + [Browsable(false)] [Index(5)] [Key(7)] [LocalizedDisplayName(nameof(Color))] diff --git a/src/Liber/Company.cs b/src/Liber/Company.cs index 9b238fb..7f9b862 100644 --- a/src/Liber/Company.cs +++ b/src/Liber/Company.cs @@ -34,7 +34,6 @@ public Company() EquityAccountId = AddAccount(new Account() { Name = Resources.DefaultEquityAccountName, - Placeholder = true, Type = AccountType.Equity }, Guid.Empty); OtherEquityAccountId = AddAccount(new Account() diff --git a/src/Liber/EquityModes.cs b/src/Liber/ReportTypes.cs similarity index 67% rename from src/Liber/EquityModes.cs rename to src/Liber/ReportTypes.cs index 8004e76..ca5ebec 100644 --- a/src/Liber/EquityModes.cs +++ b/src/Liber/ReportTypes.cs @@ -1,4 +1,4 @@ -// EquityModes.cs +// ReportTypes.cs // Copyright (c) 2023-2024 Ishan Pranav. All rights reserved. // Licensed under the MIT License. @@ -7,9 +7,10 @@ namespace Liber; [Flags] -public enum EquityModes +public enum ReportTypes { None = 0, CurrentStarted = 1, - CurrentPosted = 2 + CurrentPosted = 2, + CashBasis = 4 }