You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
package main
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"src.wolkict.net/sepa/pain"
|
|
)
|
|
|
|
var (
|
|
csvFile = flag.String("csv", "", "use this batch import CSV file")
|
|
execDate = flag.String("date", time.Now().AddDate(0, 0, 7).Format("2006-01-02"), "manually set batch execution date")
|
|
msgId = flag.String("msgId", time.Now().Format("20060102T150405"), "manually set this msgId")
|
|
)
|
|
|
|
func usage() {
|
|
fmt.Println("Usage: createbatch -csv <file.csv>")
|
|
flag.PrintDefaults()
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *csvFile == "" {
|
|
usage()
|
|
log.Fatalf("mandatory -csv not set")
|
|
}
|
|
|
|
if _, err := os.Open(*csvFile); err != nil {
|
|
log.Fatalf("cannot access CSV %q: %v", *csvFile, err)
|
|
}
|
|
|
|
collectionDate, err := time.Parse("2006-01-02", *execDate)
|
|
if err != nil {
|
|
log.Fatalf("could not parse execution date: %v", err)
|
|
}
|
|
|
|
batchLines, err := ImportCSV(*csvFile)
|
|
if err != nil {
|
|
log.Fatalf("cannot import batch CSV: %v", err)
|
|
}
|
|
|
|
d := pain.NewDocument(INITIATOR_NAME)
|
|
d.SetMeta(CREDITOR_NAME, CREDITOR_ADDR1, CREDITOR_ADDR2, CREDITOR_IBAN, CREDITOR_BIC, CREDITOR_ID, collectionDate, "RCUR")
|
|
for _, tx := range batchLines {
|
|
if tx.Id == (pain.PaymentId{}) {
|
|
continue
|
|
}
|
|
d.AddTransaction(tx)
|
|
}
|
|
|
|
err = d.Finalize(*msgId)
|
|
if err != nil {
|
|
log.Fatalf("finalizing failed: %v", err)
|
|
}
|
|
|
|
xmlBytes, err := xml.Marshal(d)
|
|
if err != nil {
|
|
log.Fatalf("marshaling failed: %v", err)
|
|
}
|
|
|
|
fmt.Printf("%v%v", xml.Header, string(xmlBytes))
|
|
}
|
|
|