feat(#18): import de extratos OFX e CSV — parser, dedup, preview e confirmação
Parser OFX tolerante ao formato SGML de bancos brasileiros (sem closing tags, BOM, timezone suffix). Parser CSV com separador de campo/decimal configurável. Dedup por FITID (OFX) ou date+amount+desc normalizado. Fluxo: POST /preview → revisão na UI → POST /confirm salva e loga. Migration 002 adiciona external_id com unique index. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Transaction struct {
|
||||
ID int `json:"id"`
|
||||
Date string `json:"date"` // YYYY-MM-DD
|
||||
Amount float64 `json:"amount"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"` // income | expense
|
||||
Source string `json:"source"` // manual | import
|
||||
CategoryID *int `json:"category_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ImportRow is a parsed-but-not-yet-saved transaction from a file.
|
||||
type ImportRow struct {
|
||||
Date string `json:"date"`
|
||||
Amount float64 `json:"amount"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
ExternalID string `json:"external_id,omitempty"` // FITID from OFX
|
||||
IsDuplicate bool `json:"is_duplicate"`
|
||||
}
|
||||
|
||||
// ImportResult is the response after confirming an import.
|
||||
type ImportResult struct {
|
||||
Imported int `json:"imported"`
|
||||
Duplicates int `json:"duplicates"`
|
||||
Errors int `json:"errors"`
|
||||
}
|
||||
|
||||
// CSVMapping tells the parser which CSV column index holds each field.
|
||||
type CSVMapping struct {
|
||||
DateColumn int `json:"date_column"`
|
||||
AmountColumn int `json:"amount_column"`
|
||||
DescriptionColumn int `json:"description_column"`
|
||||
DateFormat string `json:"date_format"` // Go time format, e.g. "02/01/2006"
|
||||
HasHeader bool `json:"has_header"`
|
||||
DecimalSeparator string `json:"decimal_separator"` // "." or ","
|
||||
FieldSeparator string `json:"field_separator"` // "," or ";"
|
||||
}
|
||||
Reference in New Issue
Block a user