gnucash2bmd 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gnucash2bmd.gemspec +1 -1
- data/history.md +4 -0
- data/lib/gnucash2bmd/version.rb +1 -1
- data/lib/gnucash2bmd.rb +101 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec98047035b2e2fd232e4450a0f18037ed59176
|
4
|
+
data.tar.gz: 7a0813cad9b10972ec58dfdfad208ad7f5f81836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a981030fc377f59f39258f8219f272e44f0883796729233f598eea30ce84ef5d5cce482d846cedbd34e5140fb0d55c7aeb46e5d9ac75013b9614caf76333e740
|
7
|
+
data.tar.gz: b77bd6342f27e07b6be1e01c832aa276e2811deb9eee7156990a0ed419683570389d49b2ad6f301999c5602c598b572ea17bcb1881c118af80c92d094e0eb85e
|
data/gnucash2bmd.gemspec
CHANGED
data/history.md
CHANGED
data/lib/gnucash2bmd/version.rb
CHANGED
data/lib/gnucash2bmd.rb
CHANGED
@@ -6,6 +6,9 @@ require 'csv'
|
|
6
6
|
require 'ostruct'
|
7
7
|
require 'gnucash2bmd/version'
|
8
8
|
require 'pp'
|
9
|
+
require "gnucash"
|
10
|
+
require 'zlib'
|
11
|
+
|
9
12
|
begin
|
10
13
|
require 'pry'
|
11
14
|
rescue LoadError
|
@@ -34,6 +37,7 @@ Wobei folgende Optionen vorhanden sind:
|
|
34
37
|
EOS
|
35
38
|
opt :jahr, "Jahr des Gnucas-Exports", :type => :integer, :default=> OLD_YEAR
|
36
39
|
opt :ausgabe, "Name der erstellten Datei", :type => :string, :default =>"bmd_#{OLD_YEAR}.csv"
|
40
|
+
opt :gnucash, "Name der zu lesenden Gnucash-Datei", :type => :string, :default => nil
|
37
41
|
end
|
38
42
|
|
39
43
|
files_read = [
|
@@ -41,6 +45,8 @@ files_read = [
|
|
41
45
|
]
|
42
46
|
|
43
47
|
AUSGABE = opts[:ausgabe]
|
48
|
+
GNUCASH = opts[:gnucash]
|
49
|
+
DATE_FORMAT= '%Y.%m.%d'
|
44
50
|
|
45
51
|
KONTEN_GNUCASH_HEADERS = {
|
46
52
|
'type' => nil,
|
@@ -76,7 +82,6 @@ KONTEN_JOURNAL_HEADERS = {
|
|
76
82
|
}
|
77
83
|
Mandant_ID = 1
|
78
84
|
|
79
|
-
BMD_LINE = OpenStruct.new
|
80
85
|
BANK_GUIDS ||= {}
|
81
86
|
IDS = {
|
82
87
|
:satzart => 'satzart',
|
@@ -91,6 +96,13 @@ KONTEN_JOURNAL_HEADERS = {
|
|
91
96
|
:belegnr => 'belegnr',
|
92
97
|
:buchcode => 'buchcode',
|
93
98
|
}
|
99
|
+
BMD_LINE = eval("Struct.new( :#{IDS.keys.join(', :')})")
|
100
|
+
class BMD_LINE
|
101
|
+
attr_accessor :name, :name_voll
|
102
|
+
def satzart
|
103
|
+
0
|
104
|
+
end
|
105
|
+
end
|
94
106
|
class Helpers
|
95
107
|
IDS.each do |id, name|
|
96
108
|
eval("attr_accessor :#{id}")
|
@@ -98,10 +110,6 @@ KONTEN_JOURNAL_HEADERS = {
|
|
98
110
|
def id_to_name(id)
|
99
111
|
return @@ids[ide]
|
100
112
|
end
|
101
|
-
def self.new_account
|
102
|
-
info = OpenStruct.new(:satzart =>0)
|
103
|
-
return info
|
104
|
-
end
|
105
113
|
def self.search_bank_guid(konto_bezeichung)
|
106
114
|
if value = BANK_GUIDS.key(konto_bezeichung)
|
107
115
|
return value
|
@@ -127,7 +135,7 @@ def read_accounts(filename)
|
|
127
135
|
name_voll = row[1]
|
128
136
|
bezeichung = row[2]
|
129
137
|
next unless bezeichung && bezeichung.size > 0
|
130
|
-
bmd =
|
138
|
+
bmd = BMD_LINE.new
|
131
139
|
bmd.bank_guid = Helpers.search_bank_guid(bezeichung)
|
132
140
|
bmd.account_nr = bezeichung
|
133
141
|
@contents << bmd
|
@@ -144,7 +152,7 @@ end
|
|
144
152
|
def read_journal(filename)
|
145
153
|
line_nr = 0
|
146
154
|
@bmd = nil
|
147
|
-
@mehrteilig
|
155
|
+
@mehrteilig = nil
|
148
156
|
@buchungs_nr = 0 # Will be added by column Aktion
|
149
157
|
puts "reading journal from #{filename}"
|
150
158
|
CSV.foreach(filename) do |row|
|
@@ -161,7 +169,7 @@ def read_journal(filename)
|
|
161
169
|
@contents << @bmd if @bmd # save terminated
|
162
170
|
@buchungs_nr += 1
|
163
171
|
@mehrteilig = row[6] && /mehrteilig/i.match(row[6])
|
164
|
-
@bmd =
|
172
|
+
@bmd = BMD_LINE.new
|
165
173
|
@bmd.buchdatum = row[0]
|
166
174
|
@bmd.konto = Helpers.search_bank_guid(row[1])
|
167
175
|
@bmd.buchungstext = row[3]
|
@@ -202,15 +210,15 @@ def check_cmd(filename)
|
|
202
210
|
exit 2
|
203
211
|
end
|
204
212
|
end
|
205
|
-
puts "
|
213
|
+
puts "Alle #{idx} Zeilen von #{filename} haben #{nr_rows} Elemente"
|
206
214
|
rescue => error
|
207
215
|
puts "got #{error} at line #{idx}"
|
208
216
|
end
|
209
217
|
|
210
218
|
def emit_bmd(filename)
|
211
|
-
CSV.open(filename, "wb", :encoding => 'UTF-8', :
|
219
|
+
CSV.open(filename, "wb", :encoding => 'UTF-8', :col_sep => ';') do |csv|
|
212
220
|
csv << IDS.values
|
213
|
-
@contents.each do |content|
|
221
|
+
@contents.uniq.each do |content|
|
214
222
|
value_array = []
|
215
223
|
IDS.keys.each do |key|
|
216
224
|
begin
|
@@ -224,12 +232,89 @@ def emit_bmd(filename)
|
|
224
232
|
end
|
225
233
|
end
|
226
234
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
235
|
+
def read_gnucash(filename)
|
236
|
+
puts "Lese GnuCash Datei #{filename}"
|
237
|
+
book = Gnucash.open(filename)
|
238
|
+
book.accounts.each do |account|
|
239
|
+
bmd = BMD_LINE.new
|
240
|
+
# bmd.bank_guid = Helpers.search_bank_guid(account.name)
|
241
|
+
bmd.bank_guid = account.id
|
242
|
+
bmd.name = account.name
|
243
|
+
bmd.name_voll = account.full_name
|
244
|
+
bmd.account_nr = account.description
|
245
|
+
$stdout.puts "bmd; #{bmd}" if $VERBOSE
|
246
|
+
@contents << bmd
|
247
|
+
end
|
248
|
+
@first_transaction_date = nil
|
249
|
+
@last_transaction_date = nil
|
250
|
+
@buchungs_nr = 0
|
251
|
+
book.accounts.each do |account|
|
252
|
+
balance = Gnucash::Value.zero
|
253
|
+
account.transactions.each do |txn|
|
254
|
+
balance += txn.value
|
255
|
+
@buchungs_nr += 1
|
256
|
+
# $VERBOSE = true if /-408.00/.match(txn.value.to_s)
|
257
|
+
$stdout.puts(sprintf("%s %8s %8s %s",
|
258
|
+
txn.date,
|
259
|
+
txn.value,
|
260
|
+
balance,
|
261
|
+
txn.description)) if $VERBOSE
|
262
|
+
@buchung = BMD_LINE.new
|
263
|
+
@buchung.buchdatum = txn.date.strftime(DATE_FORMAT)
|
264
|
+
@last_transaction_date = @buchung.buchdatum if !@last_transaction_date || @last_transaction_date < @buchung.buchdatum
|
265
|
+
@first_transaction_date = @buchung.buchdatum if !@first_transaction_date || @first_transaction_date > @buchung.buchdatum
|
266
|
+
@buchung.buchungstext = txn.description
|
267
|
+
@buchung.belegnr = txn.id # or @buchungs_nr ?? TODO
|
268
|
+
|
269
|
+
if txn.splits.size == 2
|
270
|
+
@buchung.konto = txn.splits.first[:account].id
|
271
|
+
@buchung.gkonto = txn.splits.last[:account].id
|
272
|
+
@buchung.betrag = txn.splits.first[:value]
|
273
|
+
@buchung.buchcode = getBuchcode(txn.splits.first[:value])
|
274
|
+
@contents << @buchung
|
275
|
+
else
|
276
|
+
# Splittbuchungen werden vom Programm automatisch erkannt, wenn in mehreren aufeinanderfolgenden Buchungszeilen folgende Felder identisch sind:
|
277
|
+
# Konto
|
278
|
+
# Belegnr
|
279
|
+
# Belegdatum
|
280
|
+
gegenbuchungen = []
|
281
|
+
txn.splits.each_with_index do |split, idx|
|
282
|
+
$stdout.puts(sprintf("idx %d: %s %8s %8s",
|
283
|
+
idx,
|
284
|
+
split[:quantity],
|
285
|
+
split[:value],
|
286
|
+
split[:account].id,
|
287
|
+
))
|
288
|
+
end if $VERBOSE
|
289
|
+
txn.splits.each_with_index do |split, idx|
|
290
|
+
if txn.value.to_s.eql?(split[:value].to_s)
|
291
|
+
@buchung.konto = split[:account].id
|
292
|
+
@buchung.betrag = split[:value]
|
293
|
+
@buchung.buchcode = getBuchcode(split[:value])
|
294
|
+
else
|
295
|
+
gegenbuchung = @buchung.clone
|
296
|
+
gegenbuchung.gkonto = split[:account].id
|
297
|
+
gegenbuchung.betrag = split[:value]
|
298
|
+
gegenbuchung.buchcode = getBuchcode(split[:value])
|
299
|
+
gegenbuchungen << gegenbuchung
|
300
|
+
end
|
301
|
+
end
|
302
|
+
gegenbuchungen.each do |info| info.konto = @buchung.konto; @contents << info; end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
puts "Las #{@buchungs_nr} Buchungen von #{filename} vom #{@first_transaction_date} bis zum #{@last_transaction_date}"
|
307
|
+
end
|
308
|
+
if GNUCASH
|
309
|
+
read_gnucash(GNUCASH)
|
310
|
+
else
|
311
|
+
read_accounts("Konten#{OLD_YEAR}.csv")
|
312
|
+
BANK_GUIDS.freeze
|
313
|
+
files_read.each do |filename|
|
314
|
+
read_journal(filename)
|
315
|
+
end
|
231
316
|
end
|
232
317
|
emit_bmd(AUSGABE)
|
233
318
|
check_cmd(AUSGABE)
|
234
319
|
|
235
|
-
puts "
|
320
|
+
puts "Erstellte #{AUSGABE} mit #{@contents.size} Zeilen"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnucash2bmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niklaus Giger
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: gnucash
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|