Skip to content

Commit

Permalink
Fetch general ledger accounts (#3)
Browse files Browse the repository at this point in the history
* Add General ledger accounts endpoint

* Add documentation
  • Loading branch information
AndreasDellrud authored Mar 22, 2024
1 parent 898dfcd commit 7fa1ff5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion samples/Orneholm.PEAccountingNet.ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ await PlotSectionAsync("Expenses",
() => 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();
}

Expand Down Expand Up @@ -178,7 +185,7 @@ private static async Task CreateInvoice(IPeaApi api, string clientForeignId)
{
new ClientInvoiceRowCreate()
{

}
}
};
Expand Down
27 changes: 27 additions & 0 deletions src/Orneholm.PEAccountingNet/Models/Account.cs
Original file line number Diff line number Diff line change
@@ -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,
};
}
}
9 changes: 9 additions & 0 deletions src/Orneholm.PEAccountingNet/PeaApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -217,5 +218,13 @@ public Task<Product> GetProductAsync(int productId)
{
return _httpClient.GetSingleAsync<product, Product>($"/product/{productId}", Product.FromNative);
}

/// <summary>
/// Fetch all general ledger accounts
/// </summary>
public Task<IEnumerable<Account>> GetGeneralLedgerAccountsAsync(DateTime startDate, DateTime endDate)
{
return _httpClient.GetListAsync<accountmetadatas, accountmetadata, Account>($"/accounting/account/{startDate:yyyy-MM-dd}/{endDate:yyyy-MM-dd}/metadata", x => x.account, Account.FromNative);
}
}
}

0 comments on commit 7fa1ff5

Please sign in to comment.