Compare commits

...

2 Commits

  1. 20
      cmd/createbatch/import_csv.go

20
cmd/createbatch/import_csv.go

@ -10,14 +10,15 @@ import (
) )
// FieldsPerBatchLine are the expected number of fields in each CSV line. // FieldsPerBatchLine are the expected number of fields in each CSV line.
const FieldsPerBatchLine = 9 const FieldsPerBatchLine = 11
// ImportIndex keeps track of what column corresponds to what data. // ImportIndex keeps track of what column corresponds to what data.
type ImportIndex int type ImportIndex int
// These are our numbered input fields // These are our numbered input fields
const ( const (
ImportName ImportIndex = iota ImportCustomerId ImportIndex = iota
ImportName
ImportAddr1 ImportAddr1
ImportAddr2 ImportAddr2
ImportCountry ImportCountry
@ -26,6 +27,7 @@ const (
ImportSignatureDate ImportSignatureDate
ImportAmount ImportAmount
ImportInfo ImportInfo
ImportInfoLength
) )
func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) { func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) {
@ -45,7 +47,7 @@ func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) {
ret := make([]pain.DrctDbtTxInf, len(all)) ret := make([]pain.DrctDbtTxInf, len(all))
for i, line := range all { for i, line := range all {
if line[0] == "name" { if line[ImportCustomerId] == "customer_id" {
// Header line // Header line
continue continue
} }
@ -57,8 +59,18 @@ func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("error importing line %d, cannot parse amount: %v", i, err) return nil, fmt.Errorf("error importing line %d, cannot parse amount: %v", i, err)
} }
if amount == 0.0 {
continue
}
info := line[ImportInfo]
if info == "" {
info = EMPTY_INFO
}
if len(info) > MAXLEN_INFO {
return nil, fmt.Errorf("error: info field larger (%d) than allowed (%d)", len(info), MAXLEN_INFO)
}
ret[i] = pain.NewDirectDebitTransaction(dbtr, dbtrAcct, mandateInfo, amount, line[ImportInfo], i) ret[i] = pain.NewDirectDebitTransaction(dbtr, dbtrAcct, mandateInfo, amount, info, i)
} }
return ret, nil return ret, nil
} }

Loading…
Cancel
Save