-
Notifications
You must be signed in to change notification settings - Fork 0
/
qbwcDataExtAdd.go
47 lines (41 loc) · 1.17 KB
/
qbwcDataExtAdd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package qbwcGo
import (
"bytes"
"encoding/json"
"io/ioutil"
"github.com/Sirupsen/logrus"
)
//DataExtAddQB will add a custom field value to a quickbooks object
func DataExtAddQB(TxnID string) string {
var dataExts = LoadDataExtFile()
var templateBuff = bytes.Buffer{}
for _, dataExtAdd := range *dataExts {
dataExtAdd.OwnerID = "0"
dataExtAdd.TxnID = TxnID
dataExtAdd.UseMacro = TxnID
var tPath = `./templates/qbDataExtAdd.t`
LoadTemplate(&tPath, dataExtAdd, &templateBuff)
}
return templateBuff.String()
}
//LoadDataExtFile will load the data ext set in the dataExtConfig file
func LoadDataExtFile() *[]DataExtAddRq {
var dataExts = make([]DataExtAddRq, 0)
var dataExtPath = "./config/qbwcDataExtConfig.json"
dataExtFile, err := ioutil.ReadFile(dataExtPath)
if err != nil {
getLastErrChan <- err.Error()
Log.WithFields(logrus.Fields{
"error": err,
"dataExtPath": dataExtPath,
}).Error("Error loading dataExt config file")
}
err = json.Unmarshal([]byte(dataExtFile), &dataExts)
if err != nil {
getLastErrChan <- err.Error()
Log.WithFields(logrus.Fields{
"error": err,
}).Error("Error unmarshalling DataExt JSON")
}
return &dataExts
}