-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.go
334 lines (295 loc) · 12.2 KB
/
converter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strconv"
"strings"
"github.com/tealeg/xlsx/v3"
)
type company struct {
Name string `json:"company_name"`
AnnualReports []annualReport `json:"annual_report"`
}
type annualReport struct {
Year int64 `json:"year"`
Assets assets `json:"assets"`
Pasiva pasiva `json:"pasiva"`
Profits profits `json:"profits"`
Loss loss `json:"losses"`
}
type assets struct {
// Activa | Assets
FixedAssets int64 `json:"fixed_assets"` // Anlagevermögen
CurrentAssets int64 `json:"current_assets"` // Umlaufvermögen
PrepaidExpenses int64 `json:"prepaid_expenses"` // Rechnungsabgrenzungsposten
NotCoveredEquity int64 `json:"not_covered_equity"` // Nicht durch EK gedeckter Fehlbetrag
OwnAccountTransport int64 `json:"own_account_transport"` // Ausgleichsposten Eigenmittelbefö.
}
type pasiva struct {
// Pasiva
Equity int64 `json:"equity"` // Eigenkapital
SpecialItems int64 `json:"special_items"` // Sonderposten + Ertragszuschüsse
Provisions int64 `json:"provisions"` // Rückstellungen
Liabilities int64 `json:"liabilities"` // Verbindlichkeiten
DeferredIncome int64 `json:"deferred_income"` // Rechnungsabgrenzungsposten
ShareholderLoan int64 `json:"shareholder_loan"` // Gesellschafterdarlehen
LoanSubsidiesAdjustment int64 `json:"loan_subsidies_adjustment"` // Ausgleichsposten aus Darlehensfö.
}
type profits struct {
Revenues int64 `json:"Revenues"` // Umsatzerlöse
OtherOperating int64 `json:"other_operating"` // Sonstige betriebliche/sonst. Erträge
OtherInterest int64 `json:"other_interest"` // Sonstige Zinsen und ähnliche Erträge
LossAbsorption int64 `json:"loss_absorption"` // Erträge aus Verlustübernahme
CitySubsidies int64 `json:"city_subsidies"` //Zuschüsse Stadt
WorkProgressInventory int64 `json:"work_in_progress_inventory"` // Bestand in Arbeit befindliche Aufträge
}
type loss struct {
MaterialExpenses int64 `json:"material_expenses"` // Materialaufwand
PersonnelExpenses int64 `json:"personnel_expenses"` // Personalaufwand
Depreciation int64 `json:"depreciation"` // Abschreibungen
OperatingExpenses int64 `json:"operating_expenses"` // Sonstige betriebliche Aufwendungen
InterestExpenses int64 `json:"interest_expenses"` // Zinsen und ähnliche Aufwendungen
Taxes int64 `json:"taxes"` // Steuern
LossAbsorption int64 `json:"loss_absorption"` //Aufwendungen aus Verlustübernahme
RelatedServices int64 `json:"related_services"` // Aufwendungen für bez. Leistungen
ExtraordinaryResult int64 `json:"extraordinary_result"` // a.o. Ergebnis --- gibt es seit 2016 nicht me
}
func rowVisitor(r *xlsx.Row) error {
rowBuffer = []string{}
cv := func(c *xlsx.Cell) error {
value, err := c.FormattedValue()
if err != nil {
fmt.Println(err.Error())
} else {
if strings.TrimSpace(value) != "" {
rowBuffer = append(rowBuffer, value)
}
}
return err
}
err := r.ForEachCell(cv)
sheetbuffer = append(sheetbuffer, rowBuffer)
cellCount = 0
rowCount++
return err
}
var sheetbuffer [][]string
var rowBuffer []string
var rowCount int = 0
var cellCount int = 0
func main() {
filename := "./res/Beteiligungsdaten-2018-mod.xlsx"
wb, err := xlsx.OpenFile(filename)
if err != nil {
panic(err)
}
var companies []company
//todo for each sheet
for _, sh := range wb.Sheets {
comp := company{}
comp.Name = sh.Name
sh.ForEachRow(rowVisitor)
fmt.Printf("----------------------------------->> %s\n", sh.Name)
// there are dublicated names we switch to pasiva if reacht the first occurence
pasiva := false
// use a switch for each column because properties are not fixed
for r, sl := range sheetbuffer {
// fmt.Printf("%v\n", r)
for _, value := range sl {
// fmt.Printf(">%v> %v\n", c, value)
switch {
case value == "Bilanz":
fallthrough
case value == "Konzern-Bilanz":
fallthrough
case value == "Bilanz:":
// YEARS: find "Bilanz:" -> row -1
for _, yearValue := range sheetbuffer[r-1] {
// if year is longer 4 use the last 4 digits
if len(yearValue) >= 4 {
year, err := strconv.ParseInt(yearValue[len(yearValue)-4:], 10, 64)
if err != nil {
//do nothing if it's not a year
} else {
report := annualReport{}
report.Year = year
comp.AnnualReports = append(comp.AnnualReports, report)
}
}
}
case strings.HasPrefix(value, "Anlagevermögen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Assets.FixedAssets = v * 1000
}
case strings.HasPrefix(value, "Umlaufvermögen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Assets.CurrentAssets = v * 1000
}
case strings.HasPrefix(value, "Rechnungsabgrenzungsposten"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
if pasiva {
comp.AnnualReports[i].Pasiva.DeferredIncome = v * 1000
} else {
comp.AnnualReports[i].Assets.PrepaidExpenses = v * 1000
pasiva = true
}
}
case strings.HasPrefix(value, "Nicht durch Eigenkapital gedeckter Fehlbetrag"):
fallthrough
case strings.HasPrefix(value, "Nicht durch Vermögenseinlagen gedeckter"):
fallthrough
case strings.HasPrefix(value, "Nicht durch EK gedeckter Fehlbetrag"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Assets.NotCoveredEquity = v * 1000
}
case strings.HasPrefix(value, "Ausgleichsposten Eigenmittelbef"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Assets.OwnAccountTransport = v * 1000
}
case strings.HasPrefix(value, "Eigenkapital"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.Equity = v * 1000
}
case strings.HasPrefix(value, "Sonderposten"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.SpecialItems = v * 1000
}
case strings.HasPrefix(value, "Rückstellungen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.Provisions = v * 1000
}
case strings.HasPrefix(value, "Verbindlichkeiten"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.Liabilities = v * 1000
}
case strings.HasPrefix(value, "Gesellschafterdarlehen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.ShareholderLoan = v * 1000
}
case strings.HasPrefix(value, "Ausgleichsposten aus Darlehensf"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Pasiva.LoanSubsidiesAdjustment = v * 1000
}
case strings.HasPrefix(value, "Zuschüsse Stadt"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.CitySubsidies = v * 1000
}
case strings.HasPrefix(value, "Umsatzerlöse"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.Revenues = v * 1000
}
case strings.HasPrefix(value, "Sonstige betriebliche/sonst. Erträge"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.OtherOperating = v * 1000
}
case strings.HasPrefix(value, "Sonstige Zinsen und ähnliche Erträge"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.OtherInterest = v * 1000
}
case strings.HasPrefix(value, "Erträge aus Verlustübernahme"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.LossAbsorption = v * 1000
}
case strings.HasPrefix(value, "Bestand in Arbeit befindliche Aufträge"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Profits.WorkProgressInventory = v * 1000
}
case strings.HasPrefix(value, "Materialaufwand"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.MaterialExpenses = v * 1000
}
case strings.HasPrefix(value, "Personalaufwand"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.PersonnelExpenses = v * 1000
}
case strings.HasPrefix(value, "Abschreibungen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.Depreciation = v * 1000
}
case strings.HasPrefix(value, "Aufwendungen für bez. Leistungen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.RelatedServices = v * 1000
}
case strings.HasPrefix(value, "Sonstige/ betriebliche Aufwendungen"):
fallthrough
case strings.HasPrefix(value, "Sonstige betriebl. Aufwendungen"):
fallthrough
case strings.HasPrefix(value, "Sonstige/betriebliche Aufwendungen"):
fallthrough
case strings.HasPrefix(value, "Sonstige betriebliche Aufwendungen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.OperatingExpenses = v * 1000
}
case strings.HasPrefix(value, "Zinsen und ähnliche Aufwendungen"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.InterestExpenses = v * 1000
}
case strings.HasPrefix(value, "Steuern"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.Taxes = v * 1000
}
case strings.HasPrefix(value, "Aufwand aus Verlustübernahme"):
fallthrough
case strings.HasPrefix(value, "Aufwendungen aus Verlustübernahme"):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.LossAbsorption = v * 1000
}
case strings.HasPrefix(value, "a.o. Ergebnis "):
for i := 0; i < len(sheetbuffer[r])-1; i++ {
v, _ := strconv.ParseInt(sheetbuffer[r][i+1], 10, 64)
comp.AnnualReports[i].Loss.ExtraordinaryResult = v * 1000
}
default:
_, err := strconv.ParseFloat(value, 64)
if err != nil {
if contains(value) != true {
fmt.Printf("ERROR: --------- %v\n", value)
}
}
}
}
}
companies = append(companies, comp)
//reset slice
sheetbuffer = nil
rowCount = 0
cellCount = 0
}
file, _ := json.MarshalIndent(companies, "", " ")
_ = ioutil.WriteFile("./out/Beteiligungsbilanzen-2018.json", file, 0644)
}
func contains(str string) bool {
knownStrings := []string{"Jahresergebnis", "Aktiva in T €", "Passiva in T €", "EK Quote", "Jahresüberschuss / Fehlbetrag", "Gewinn- und Verlustrechnung in T€", "Gewinn- und Verlustrechnung in T€:"}
for _, a := range knownStrings {
if a == str {
return true
}
}
return false
}