Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterOrneholm committed Apr 7, 2024
2 parents ff4c97a + 1848ea7 commit e85a7a2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
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,
};
}
}
3 changes: 2 additions & 1 deletion src/Orneholm.PEAccountingNet/Orneholm.PEAccountingNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageId>Orneholm.PEAccountingNet</PackageId>
<Product>OrneholmPEAccountingNet</Product>

<VersionPrefix>1.2.0</VersionPrefix>
<VersionPrefix>1.3.0</VersionPrefix>
<!--<VersionSuffix>beta-1</VersionSuffix>-->
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion Condition="'$(BUILD_BUILDNUMBER)' == ''">$(VersionPrefix).0</FileVersion>
Expand Down Expand Up @@ -50,3 +50,4 @@
<Folder Include="Models\Native\" />
</ItemGroup>
</Project>
3
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 e85a7a2

Please sign in to comment.