Skip to content

Commit

Permalink
Add account summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanpranav committed Aug 20, 2024
1 parent ccebb5f commit 576745c
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/Liber.Forms/FormattedStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<data name="account" xml:space="preserve">
<value>Account</value>
</data>
<data name="account-summary" xml:space="preserve">
<value>Account Summary</value>
</data>
<data name="AccountCount{0}" xml:space="preserve">
<value>({0:n0} accounts)</value>
</data>
Expand Down
4 changes: 4 additions & 0 deletions src/Liber.Forms/Liber.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<None Remove="scripts\analysis.js" />
<None Remove="scripts\chart.js" />
<None Remove="scripts\time-series.js" />
<None Remove="styles\account-summary.xslt" />
<None Remove="styles\balance-sheet.xslt" />
<None Remove="styles\base\general-ledger.xslt" />
<None Remove="styles\cash-flow-statement.xslt" />
Expand Down Expand Up @@ -119,6 +120,9 @@
<Content Include="styles\income-statement.xslt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="styles\account-summary.xslt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="styles\trial-balance.xslt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
11 changes: 0 additions & 11 deletions src/Liber.Forms/Reports/ReportData.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/Liber.Forms/Reports/Xsl/XslReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Liber.Forms/Reports/Xsl/XslReportView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class XslReportView : IReportView
{
private static readonly Dictionary<string, XslCompiledTransform> s_styles = new Dictionary<string, XslCompiledTransform>();

private static Dictionary<string, ReportData>? s_reports;
private static Dictionary<string, ReportTypes>? s_reports;

private readonly string _path;
private readonly XslReport _report;
Expand Down Expand Up @@ -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))
Expand All @@ -73,6 +73,6 @@ public static void InitializeReports(string path)

using FileStream input = File.OpenRead(path);

s_reports = JsonSerializer.Deserialize<Dictionary<string, ReportData>>(input, FormattedStrings.JsonOptions);
s_reports = JsonSerializer.Deserialize<Dictionary<string, ReportTypes>>(input, FormattedStrings.JsonOptions);
}
}
21 changes: 6 additions & 15 deletions src/Liber.Forms/data/reports.json
Original file line number Diff line number Diff line change
@@ -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"
}
64 changes: 64 additions & 0 deletions src/Liber.Forms/styles/account-summary.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
account-summary.xslt
Copyright (c) 2023-2024 Ishan Pranav. All rights reserved.
Licensed under the MIT License.
-->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:liber="urn:liber"
exclude-result-prefixes="msxsl">
<xsl:include href="base/financial-statement.xslt"/>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/report">
<xsl:call-template name="financial-statement">
<xsl:with-param name="title" select="title"/>
<xsl:with-param name="table">
<thead>
<tr>
<th colspan="2" class="subtitle">
<xsl:value-of select="company/name"/>
</th>
</tr>
<tr>
<th colspan="2" class="title">
<xsl:value-of select="title"/>
</th>
</tr>
<tr>
<th colspan="2" class="bar dateline">
<xsl:value-of select="liber:fdatel(posted)"/>
</th>
</tr>
<tr>
<th></th>
<th class="heading">
<xsl:value-of select="liber:fdates(posted)"/>
</th>
</tr>
<tr>
<th></th>
<th class="heading">
<xsl:value-of select="liber:gets('balance')"/>
</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="company/account">
<tr>
<td class="left account">
<xsl:value-of select="name"/>
</td>
<td class="right">
<xsl:value-of select="liber:fm(type, balance)"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
6 changes: 3 additions & 3 deletions src/Liber.Sqlite/SqliteSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public static async Task<Company> 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<TaxType>(9),
Inactive = reader.GetBoolean(10),
Adjustment = reader.GetBoolean(11)
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Liber/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public Account(Guid parentId)
/// Gets or sets the color associated with the account.
/// </summary>
/// <value>The color associated with the account.</value>
[Browsable(false)]
[Index(5)]
[Key(7)]
[LocalizedDisplayName(nameof(Color))]
Expand Down
1 change: 0 additions & 1 deletion src/Liber/Company.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public Company()
EquityAccountId = AddAccount(new Account()
{
Name = Resources.DefaultEquityAccountName,
Placeholder = true,
Type = AccountType.Equity
}, Guid.Empty);
OtherEquityAccountId = AddAccount(new Account()
Expand Down
7 changes: 4 additions & 3 deletions src/Liber/EquityModes.cs → src/Liber/ReportTypes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// EquityModes.cs
// ReportTypes.cs
// Copyright (c) 2023-2024 Ishan Pranav. All rights reserved.
// Licensed under the MIT License.

Expand All @@ -7,9 +7,10 @@
namespace Liber;

[Flags]
public enum EquityModes
public enum ReportTypes
{
None = 0,
CurrentStarted = 1,
CurrentPosted = 2
CurrentPosted = 2,
CashBasis = 4
}

0 comments on commit 576745c

Please sign in to comment.