diff --git a/README.md b/README.md index 0f82717..b941097 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ The API-wrapper supports all these methods: - Products - `GetProductsAsync()` - `GetProductAsync(int productId)` +- General ledger accounts + - `GetGeneralLedgerAccountsAsync(DateTime startDate, DateTime endDate)` ## Getting started diff --git a/samples/Orneholm.PEAccountingNet.ConsoleSample/Program.cs b/samples/Orneholm.PEAccountingNet.ConsoleSample/Program.cs index b26a34a..3ef3062 100644 --- a/samples/Orneholm.PEAccountingNet.ConsoleSample/Program.cs +++ b/samples/Orneholm.PEAccountingNet.ConsoleSample/Program.cs @@ -112,6 +112,13 @@ static async Task App(int companyId, string companyToken) () => api.GetExpensesAsync(), x => $"{x.Date} ({x.Id}): {x.Amount} {x.CurrencyType}, Nr: {x.Nr}"); + // General ledger accounts for previous quarter + var previousQuarterStart = firstDayOfMonth.AddMonths(-3); + var previousQuarterEnd = firstDayOfMonth.AddDays(-1); + await PlotSectionAsync("General ledger accounts for previous quarter", + () => api.GetGeneralLedgerAccountsAsync(previousQuarterStart, previousQuarterEnd), + x => $"{x.AccountNr} ({x.Description}): {x.InBalance} in, {x.OutBalance} out, {x.DebitCount} debits, {x.CreditCount} credits, Disabled: {x.Disabled}"); + Console.ReadLine(); } @@ -178,7 +185,7 @@ private static async Task CreateInvoice(IPeaApi api, string clientForeignId) { new ClientInvoiceRowCreate() { - + } } }; diff --git a/src/Orneholm.PEAccountingNet/Models/Account.cs b/src/Orneholm.PEAccountingNet/Models/Account.cs new file mode 100644 index 0000000..8c5b220 --- /dev/null +++ b/src/Orneholm.PEAccountingNet/Models/Account.cs @@ -0,0 +1,27 @@ +using Orneholm.PEAccountingNet.Models.Native; + +namespace Orneholm.PEAccountingNet.Models; +public class Account +{ + public int AccountNr { get; set; } + public string Description { get; set; } + public long InBalance { get; set; } + public long OutBalance { get; set; } + public int DebitCount { get; set; } + public int CreditCount { get; set; } + public bool Disabled { get; set; } + + internal static Account FromNative(accountmetadata native) + { + return new Account + { + AccountNr = native.accountNr, + Description = native.description, + InBalance = native.inbalance, + OutBalance = native.outbalance, + DebitCount = native.debitcount, + CreditCount = native.creditcount, + Disabled = native.disabled, + }; + } +} diff --git a/src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj b/src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj index 6eb0ae6..50bf32e 100644 --- a/src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj +++ b/src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj @@ -11,7 +11,7 @@ Orneholm.PEAccountingNet OrneholmPEAccountingNet - 1.2.0 + 1.3.0 1.0.0.0 $(VersionPrefix).0 @@ -50,3 +50,4 @@ +3 diff --git a/src/Orneholm.PEAccountingNet/PeaApi.cs b/src/Orneholm.PEAccountingNet/PeaApi.cs index 3b7de76..48acec6 100644 --- a/src/Orneholm.PEAccountingNet/PeaApi.cs +++ b/src/Orneholm.PEAccountingNet/PeaApi.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -217,5 +218,13 @@ public Task GetProductAsync(int productId) { return _httpClient.GetSingleAsync($"/product/{productId}", Product.FromNative); } + + /// + /// Fetch all general ledger accounts + /// + public Task> GetGeneralLedgerAccountsAsync(DateTime startDate, DateTime endDate) + { + return _httpClient.GetListAsync($"/accounting/account/{startDate:yyyy-MM-dd}/{endDate:yyyy-MM-dd}/metadata", x => x.account, Account.FromNative); + } } }