handle 'caisse d'epargne' export encoding
This commit is contained in:
parent
384736d313
commit
a1a19f810b
1 changed files with 16 additions and 6 deletions
|
|
@ -5,12 +5,15 @@ import (
|
|||
"encoding/csv"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitnet.fr/deblan/budget/database/manager"
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
|
|
@ -168,14 +171,14 @@ func ImportCaisseEpargneTransactions(content string, bankAccountID int) ([]Trans
|
|||
}
|
||||
|
||||
transaction := Transaction{
|
||||
ShortLabel: fields[1],
|
||||
Label: fields[2],
|
||||
ShortLabel: toUTF8(fields[1]),
|
||||
Label: toUTF8(fields[2]),
|
||||
Reference: ref,
|
||||
Information: fields[4],
|
||||
OperationType: fields[5],
|
||||
Information: toUTF8(fields[4]),
|
||||
OperationType: toUTF8(fields[5]),
|
||||
AccountedAt: toDate(fields[0], "02/01/2006"),
|
||||
BankCategory: fields[6],
|
||||
BankSubCategory: fields[7],
|
||||
BankCategory: toUTF8(fields[6]),
|
||||
BankSubCategory: toUTF8(fields[7]),
|
||||
Debit: -toFloat(fields[8]),
|
||||
Credit: toFloat(fields[9]),
|
||||
BankAccountID: bankAccountID,
|
||||
|
|
@ -321,3 +324,10 @@ func toDate(value, format string) time.Time {
|
|||
|
||||
return v
|
||||
}
|
||||
|
||||
func toUTF8(input string) string {
|
||||
reader := transform.NewReader(strings.NewReader(input), charmap.ISO8859_1.NewDecoder())
|
||||
decoded, _ := ioutil.ReadAll(reader)
|
||||
|
||||
return string(decoded)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue