11 // hardcoded account ids we have to look at
14 // wareneingang 19% and 7%
15 const pid_buy_n = string("8e3b7c42e3173ed85f3d4736e82afb4d")
16 const pid_buy_s = string("0cfd2ceb45fff89b9d1b7ce3af66cdf3")
17 const pid_misc = string("e3acc2865dbf931e41cf2b90240de5c2")
18 const pid_rep = string("b1d04ad157cac569f4299d4ddf94ed6f")
19 const pid_room = string("4394ed4ffa7266f8f8731080926a7a61")
20 const pid_cap = string("4196ee026d1bdb785df2c975fca91ae0")
21 // abziehbare vst 19% and 7%
22 const aid_vst_n = string("7c449e13125d6b93043f963628106db2")
23 const aid_vst_s = string("006643c1c0a91f2b40614c75a49c6295")
26 const aid_rec_n = string("f3e905732b729ba096a50dab60559ce7")
27 const aid_rec_s = string("66c1b04bd897766cb2be538094e1db6a")
28 const aid_tip = string("1d20024badc11a99a8e1cf3a9a64a501")
29 const aid_dep = string("9772f4e231f6f5e3100132cc53eb3447")
31 const aid_ust_n = string("e4bd6ff52408be8076f24aeb105893d9")
32 const aid_ust_s = string("38bf40d16529f2a1e611c073c6c1dc9c")
36 pid string // parent id
37 num int // account number
39 buy bool // buy or sales
40 tax bool // tax or non-tax(=goods) account
41 rid []string // required transaction account(s)
46 XMLName xml.Name `xml:"account"`
47 Name string `xml:"name"`
48 AccountId string `xml:"id"`
49 ParentId string `xml:"parent"`
52 XMLName xml.Name `xml:"split"`
54 Value string `xml:"value"`
55 Quantity string `xml:"quantity"`
56 AccountId string `xml:"account"`
58 type Transaction struct {
59 XMLName xml.Name `xml:"transaction"`
61 Date string `xml:"date-posted>date"`
62 Description string `xml:"description"`
63 Spl []Split `xml:"splits>split"`
65 type ParsedData struct {
66 XMLName xml.Name `xml:"gnc-v2"`
67 DataCnt []string `xml:"count-data"`
68 Accnt []Account `xml:"book>account"`
69 Trn []Transaction `xml:"book>transaction"`
78 file, err := os.Open("c13_skr03.gnucash")
80 fmt.Println("Error opening file:", err)
86 xmldata, err := ioutil.ReadAll(file)
88 fmt.Println("Error reading file:", err)
93 err = xml.Unmarshal(xmldata,&data)
95 fmt.Println("Error unmarshaling xml data:", err)
99 // whooha, this is our data!
100 fmt.Println("Parsed accounts:",len(data.Accnt))
101 fmt.Println("Parsed transactions:",len(data.Trn))
103 accnt := make(map[string]amap)
105 for ac := range data.Accnt {
106 aid := data.Accnt[ac].AccountId
107 pid := data.Accnt[ac].ParentId
109 rid := make ([]string,10,10)
111 pid,ac,0,false,false,rid,
118 case pid == pid_buy_n || pid == pid_misc || pid == pid_rep || pid == pid_room || pid == pid_cap:
123 case pid == pid_buy_s:
129 case aid == aid_vst_n:
133 rid=[]string{pid_buy_n,pid_misc,pid_rep,pid_room,pid_cap,}
135 case aid == aid_vst_s:
143 case aid == aid_rec_n || aid == aid_tip || aid == aid_dep:
147 case aid == aid_rec_s:
152 case aid == aid_ust_n:
155 rid=[]string{aid_rec_n,aid_tip,aid_dep,}
157 case aid == aid_ust_s:
165 // check transactions ...
166 for tc := range data.Trn {
167 // ... and all the accounts involved
168 for tsc := range data.Trn[tc].Spl {
169 aid := data.Trn[tc].Spl[tsc].AccountId
170 if check_trn(&data.Trn[tc],accnt,aid) == false {
172 fmt.Println("P:",data.Accnt[ac].Name,"at",data.Trn[tc].Date)
180 func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool {
181 //ac := accnt[aid].num
182 if accnt[aid].rid[0]=="NONE" {
185 for ra := range accnt[aid].rid {
186 for ea := range ta.Spl {
187 oaid := ta.Spl[ea].AccountId
189 case accnt[aid].tax && accnt[aid].buy:
191 if accnt[oaid].pid == accnt[aid].rid[ra] {
196 if ta.Spl[ea].AccountId == accnt[aid].rid[ra] {
200 //fmt.Println(data.Accnt[accnt[oaid].num].Name)