-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): Add American Express (NL) plugin (#38)
* feat(plugin): Add Amex * Consolidate packages * fix: assembly name and InnoSetup
- Loading branch information
1 parent
9dc26d7
commit 9e4387f
Showing
17 changed files
with
118 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Datum,Omschrijving,Kaartlid,Rekening #,Bedrag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace TransactionQL.Plugins | ||
|
||
open System | ||
open System.Globalization | ||
open FSharp.Data | ||
open TransactionQL.Parser.AST | ||
open TransactionQL.Parser.QLInterpreter | ||
open TransactionQL.Input.Converters | ||
open TransactionQL.Shared.Disposables | ||
|
||
module Amex = | ||
|
||
let private dateFormat = "MM/dd/yyyy" | ||
|
||
type AmexTransactions = CsvProvider<"Amex.csv"> | ||
|
||
type AmexReader() = | ||
let toMap (row: AmexTransactions.Row) = | ||
let amount = | ||
-1m * Decimal.Parse(row.Bedrag, NumberStyles.AllowLeadingSign ||| NumberStyles.AllowDecimalPoint) | ||
|
||
let isSent = amount < 0m | ||
|
||
Map.ofList | ||
[ ("Sender", if isSent then row.Omschrijving else row.Kaartlid) | ||
("Receiver", if isSent then row.Kaartlid else row.Omschrijving) | ||
("Amount", string amount) | ||
("Total", (string <| Math.Abs amount)) | ||
("Date", row.Datum) | ||
("Description", row.Omschrijving) | ||
("Name", row.Omschrijving) ] | ||
|
||
interface IConverter with | ||
member this.DateFormat = dateFormat | ||
|
||
member this.Read lines = | ||
using (Disposables.changeCulture "nl-NL") (fun _ -> | ||
lines |> AmexTransactions.ParseRows |> Array.map toMap | ||
) | ||
|
||
member this.Map row = | ||
let fromRow col = Map.find col row | ||
|
||
{ Header = | ||
Header( | ||
DateTime.ParseExact(fromRow "Date", dateFormat, CultureInfo.InvariantCulture), | ||
fromRow "Name" | ||
) | ||
Lines = | ||
[ { Account = Account [ fromRow "Receiver" ] | ||
Amount = (Commodity "EUR", float (fromRow "Total")) |> Some | ||
Tag = None } | ||
{ Account = Account [ fromRow "Sender" ] | ||
Amount = None | ||
Tag = None } ] | ||
Comments = [ fromRow "Description" ] } |
20 changes: 20 additions & 0 deletions
20
src/TransactionQL.Plugins.Amex/TransactionQL.Plugins.Amex.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<AssemblyTitle>Amex</AssemblyTitle> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="Amex.csv" /> | ||
<Compile Include="Amex.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TransactionQL.Input\TransactionQL.Input.fsproj" /> | ||
<ProjectReference Include="..\TransactionQL.Parser\TransactionQL.Parser.fsproj" /> | ||
<ProjectReference Include="..\TransactionQL.Shared\TransactionQL.Shared.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace TransactionQL.Shared.Disposables | ||
|
||
module Disposables = | ||
open System | ||
open System.Globalization | ||
|
||
let private createDisposable f = | ||
{ | ||
new IDisposable with | ||
member x.Dispose() = f() | ||
} | ||
|
||
let changeCulture (culture:string) = | ||
let current = CultureInfo.CurrentCulture | ||
CultureInfo.CurrentCulture <- CultureInfo.GetCultureInfo(culture) | ||
createDisposable(fun () -> CultureInfo.CurrentCulture <- current) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters