12 // hardcoded account ids we have to look at
15 // wareneingang 19% and 7%
16 const pid_buy_n = string("8e3b7c42e3173ed85f3d4736e82afb4d")
17 const pid_buy_s = string("0cfd2ceb45fff89b9d1b7ce3af66cdf3")
18 const pid_misc = string("e3acc2865dbf931e41cf2b90240de5c2")
19 const pid_rep = string("b1d04ad157cac569f4299d4ddf94ed6f")
20 const pid_room = string("4394ed4ffa7266f8f8731080926a7a61")
21 const pid_cap = string("4196ee026d1bdb785df2c975fca91ae0")
22 // abziehbare vst 19% and 7%
23 const aid_vst_n = string("7c449e13125d6b93043f963628106db2")
24 const aid_vst_s = string("006643c1c0a91f2b40614c75a49c6295")
27 const aid_rec_n = string("f3e905732b729ba096a50dab60559ce7")
28 const aid_rec_s = string("66c1b04bd897766cb2be538094e1db6a")
29 const aid_tip = string("1d20024badc11a99a8e1cf3a9a64a501")
30 const aid_dep = string("9772f4e231f6f5e3100132cc53eb3447")
32 const aid_ust_n = string("e4bd6ff52408be8076f24aeb105893d9")
33 const aid_ust_s = string("38bf40d16529f2a1e611c073c6c1dc9c")
37 pid string // parent id
38 num int // account number
40 buy bool // buy or sales
41 tax bool // tax or non-tax(=goods) account
42 rid []string // required transaction account(s)
47 XMLName xml.Name `xml:"account"`
48 Name string `xml:"name"`
49 AccountId string `xml:"id"`
50 ParentId string `xml:"parent"`
53 XMLName xml.Name `xml:"split"`
55 Value string `xml:"value"`
56 Quantity string `xml:"quantity"`
57 AccountId string `xml:"account"`
59 type Transaction struct {
60 XMLName xml.Name `xml:"transaction"`
62 Date string `xml:"date-posted>date"`
63 Description string `xml:"description"`
64 Spl []Split `xml:"splits>split"`
66 type ParsedData struct {
67 XMLName xml.Name `xml:"gnc-v2"`
68 DataCnt []string `xml:"count-data"`
69 Accnt []Account `xml:"book>account"`
70 Trn []Transaction `xml:"book>transaction"`
79 file, err := os.Open("c13_skr03.gnucash")
81 fmt.Println("Error opening file:", err)
87 xmldata, err := ioutil.ReadAll(file)
89 fmt.Println("Error reading file:", err)
94 err = xml.Unmarshal(xmldata,&data)
96 fmt.Println("Error unmarshaling xml data:", err)
100 // whooha, this is our data!
101 fmt.Println("Parsed accounts:",len(data.Accnt))
102 fmt.Println("Parsed transactions:",len(data.Trn))
104 accnt := make(map[string]amap)
106 for ac := range data.Accnt {
107 aid := data.Accnt[ac].AccountId
108 pid := data.Accnt[ac].ParentId
110 rid := make ([]string,10,10)
112 pid,ac,0,false,false,rid,
119 case pid == pid_buy_n || pid == pid_misc || pid == pid_rep || pid == pid_room || pid == pid_cap:
124 case pid == pid_buy_s:
130 case aid == aid_vst_n:
134 rid=[]string{pid_buy_n,pid_misc,pid_rep,pid_room,pid_cap,}
136 case aid == aid_vst_s:
144 case aid == aid_rec_n || aid == aid_tip || aid == aid_dep:
148 case aid == aid_rec_s:
153 case aid == aid_ust_n:
156 rid=[]string{aid_rec_n,aid_tip,aid_dep,}
158 case aid == aid_ust_s:
166 // check transactions ...
167 for tc := range data.Trn {
168 // ... and all the accounts involved
169 for tsc := range data.Trn[tc].Spl {
170 aid := data.Trn[tc].Spl[tsc].AccountId
171 if check_trn(&data.Trn[tc],accnt,aid) == false {
174 fmt.Println(data.Trn[tc].Date)
175 fmt.Println(" ",data.Trn[tc].Description)
176 fmt.Println(" ",data.Accnt[ac].Name)
183 func check_trn(ta *Transaction,accnt map[string]amap,aid string) bool {
184 //ac := accnt[aid].num
185 if accnt[aid].rid[0]=="NONE" {
188 for ra := range accnt[aid].rid {
189 for ea := range ta.Spl {
190 oaid := ta.Spl[ea].AccountId
192 case accnt[aid].tax && accnt[aid].buy:
194 if accnt[oaid].pid == accnt[aid].rid[ra] {
199 if ta.Spl[ea].AccountId == accnt[aid].rid[ra] {
203 //fmt.Println(data.Accnt[accnt[oaid].num].Name)
208 wordlist := []string{
212 "Gesundheitsbelehrung",
213 "Gewerbezentralregister",
214 "Entgeltabrechnung siehe Anlage",
218 for wc := range wordlist {
219 if strings.Contains(ta.Description,wordlist[wc]){