gnucash2bmd 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ec98047035b2e2fd232e4450a0f18037ed59176
4
- data.tar.gz: 7a0813cad9b10972ec58dfdfad208ad7f5f81836
3
+ metadata.gz: e31559ee180d73a140b98f2bdf6af15f466d4647
4
+ data.tar.gz: 67afd43f223ba20cc44727893c9ef3946333a898
5
5
  SHA512:
6
- metadata.gz: a981030fc377f59f39258f8219f272e44f0883796729233f598eea30ce84ef5d5cce482d846cedbd34e5140fb0d55c7aeb46e5d9ac75013b9614caf76333e740
7
- data.tar.gz: b77bd6342f27e07b6be1e01c832aa276e2811deb9eee7156990a0ed419683570389d49b2ad6f301999c5602c598b572ea17bcb1881c118af80c92d094e0eb85e
6
+ metadata.gz: 2273ce89f5b71c54a8a795c9f7b616768dd945eaea8545ff66d5e9624fa7d723375ec1c4c108a4260a4e79bdc31a8dd84bf9a6524436b481c863ae917ec63c4e
7
+ data.tar.gz: e8997043870bbefa0a93f886cf287f2a217d1c52b6a7c969cccfb773894662763bc0c0bbe00f0cbd24abd8bba735f9c08a5d3d58a2a765ca2f94a4317a280a42
data/history.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.4 of 2017.05.30
2
+
3
+ - Added some default values. Fixed date format
4
+ - Use small integer values for accounts and buchungsnr
5
+
1
6
  ## 0.0.3 of 2017.05.26
2
7
 
3
8
  - Added reading gnucash files directly
data/lib/gnucash2bmd.rb CHANGED
@@ -46,7 +46,7 @@ files_read = [
46
46
 
47
47
  AUSGABE = opts[:ausgabe]
48
48
  GNUCASH = opts[:gnucash]
49
- DATE_FORMAT= '%Y.%m.%d'
49
+ DATE_FORMAT= '%d.%m.%Y'
50
50
 
51
51
  KONTEN_GNUCASH_HEADERS = {
52
52
  'type' => nil,
@@ -83,6 +83,26 @@ KONTEN_JOURNAL_HEADERS = {
83
83
  Mandant_ID = 1
84
84
 
85
85
  BANK_GUIDS ||= {}
86
+ NOTWNDIG = %(
87
+ Notwendige Felder für den BuErf Import:
88
+ Grundsätzlich alle Felder, die Sie auch beim "manuellen" Buchen in der Buchungsmaske eingeben:
89
+ Konto Führendes Buchungskonto
90
+ Gkonto Gegenkonto
91
+ Belegnr Belegnummer, Rechnungsnummer
92
+ Buchdatum Buchungsdatum
93
+ Belegdatum Belegdatum, Rechnungsdatum
94
+ Buchcode Code, ob Soll oder Haben
95
+ Betrag Buchungsbetrag für führendes Konto
96
+ Text Buchungstext
97
+
98
+ Buchsymbol Buchungssymbol AR
99
+ Steuercode Code, ob Vorsteuer oder Umsatzsteuer usw.
100
+ Prozent Steuerprozentsatz
101
+ Steuer Steuerbetrag
102
+ ZZiel Nettozahlungsziel in Tagen
103
+ Skontopz Skontoprozentsatz
104
+ Skontotage Skontozahlungsziel in Tagen
105
+ )
86
106
  IDS = {
87
107
  :satzart => 'satzart',
88
108
  # :mandant => 'Mandats-IDs',
@@ -91,10 +111,28 @@ KONTEN_JOURNAL_HEADERS = {
91
111
  :konto => 'konto',
92
112
  :gkonto => 'gkonto',
93
113
  :buchdatum => 'buchdatum',
94
- :buchungstext => 'buchungstext',
114
+ :belegdatum => 'belegdatum',
115
+ :buchungstext => 'text',
95
116
  :betrag => 'betrag',
96
117
  :belegnr => 'belegnr',
97
118
  :buchcode => 'buchcode',
119
+
120
+ :buchsymbol => 'buchsymbol',
121
+ :steuercode => 'steuercode',
122
+ :prozent => 'prozent',
123
+ :steuer => 'steuer',
124
+ :zziel => 'zziel',
125
+ :skontopz => 'skontopz',
126
+ :skontotage => 'skontotage',
127
+ }
128
+ DEFAULTS = {
129
+ :buchsymbol => 'AR',
130
+ :steuercode => '0,0',
131
+ :prozent => '0,0',
132
+ :steuer => '0,0',
133
+ :zziel => '30',
134
+ :skontopz => '0,0',
135
+ :skontotage => '10',
98
136
  }
99
137
  BMD_LINE = eval("Struct.new( :#{IDS.keys.join(', :')})")
100
138
  class BMD_LINE
@@ -116,7 +154,6 @@ KONTEN_JOURNAL_HEADERS = {
116
154
  end
117
155
  new_id = BANK_GUIDS.size + 1
118
156
  BANK_GUIDS[new_id] = konto_bezeichung
119
- new_id
120
157
  end
121
158
  def Helpers.get_ids_sorted_by_value
122
159
  IDS.sort_by.reverse_each{ |k, v| v }.to_h
@@ -155,6 +192,7 @@ def read_journal(filename)
155
192
  @mehrteilig = nil
156
193
  @buchungs_nr = 0 # Will be added by column Aktion
157
194
  puts "reading journal from #{filename}"
195
+ konto = KONTEN_JOURNAL_HEADERS.values.index('konto')
158
196
  CSV.foreach(filename) do |row|
159
197
  line_nr += 1
160
198
  if line_nr == 1
@@ -201,6 +239,10 @@ end
201
239
  def check_cmd(filename)
202
240
  nr_rows = nil
203
241
  idx = 0
242
+ konto_row = IDS.keys.index(:konto)
243
+ gkonto_row = IDS.keys.index(:gkonto)
244
+ guid_row = IDS.keys.index(:bank_guid)
245
+ belegnr_row = IDS.keys.index(:belegnr)
204
246
  CSV.foreach(filename, :col_sep => ';') do |row|
205
247
  idx += 1
206
248
  nr_rows ||= row.size
@@ -209,6 +251,25 @@ def check_cmd(filename)
209
251
  puts " #{row}"
210
252
  exit 2
211
253
  end
254
+ next if idx == 1
255
+ if row[belegnr_row]
256
+ value = row[belegnr_row]
257
+ raise "Zeile #{idx} für Beleg-Nr '#{value}' darf maximal 20 Zeichen lang sein (ist #{value.length})." if value.length > 20
258
+ raise "Zeile #{idx} für Beleg-Nr '#{value}' muss alphanumerisch sein." unless /^[a-z0-9]+$/i.match(value)
259
+ end
260
+ if row[guid_row]
261
+ value = row[guid_row]
262
+ raise "Zeile #{idx} für GUID '#{value}' darf maximal 36 Zeichen lang sein (ist #{value.length})." if value.length > 36
263
+ raise "Zeile #{idx} für GUID '#{value}' muss alphanumerisch sein." unless /^[a-z0-9]+$/i.match(value)
264
+ end
265
+ if row[gkonto_row]
266
+ value = row[gkonto_row]
267
+ raise "Zeile #{idx} für Gkonto '#{value}' muss eine Zeile angegeben werden" unless value.to_i > 0 && value.size < 10
268
+ end
269
+ if row[konto_row]
270
+ value = row[konto_row]
271
+ raise "Zeile #{idx} für Konto '#{value}' muss eine Zeile angegeben werden" unless value.to_i > 0 && value.size < 10
272
+ end
212
273
  end
213
274
  puts "Alle #{idx} Zeilen von #{filename} haben #{nr_rows} Elemente"
214
275
  rescue => error
@@ -237,8 +298,8 @@ def read_gnucash(filename)
237
298
  book = Gnucash.open(filename)
238
299
  book.accounts.each do |account|
239
300
  bmd = BMD_LINE.new
240
- # bmd.bank_guid = Helpers.search_bank_guid(account.name)
241
- bmd.bank_guid = account.id
301
+ bmd.bank_guid = Helpers.search_bank_guid(account.id)
302
+ # bmd.bank_guid = account.id
242
303
  bmd.name = account.name
243
304
  bmd.name_voll = account.full_name
244
305
  bmd.account_nr = account.description
@@ -264,11 +325,17 @@ def read_gnucash(filename)
264
325
  @last_transaction_date = @buchung.buchdatum if !@last_transaction_date || @last_transaction_date < @buchung.buchdatum
265
326
  @first_transaction_date = @buchung.buchdatum if !@first_transaction_date || @first_transaction_date > @buchung.buchdatum
266
327
  @buchung.buchungstext = txn.description
267
- @buchung.belegnr = txn.id # or @buchungs_nr ?? TODO
328
+ @buchung.belegnr = @buchungs_nr # txn.id ist 32 Zeichen lang. Ungültig!!
329
+ @buchung.belegdatum = @buchung.buchdatum
330
+ DEFAULTS.each do |key, value|
331
+ cmd = "@buchung.#{key} = '#{value}'"
332
+ eval cmd
333
+ end
334
+
268
335
 
269
336
  if txn.splits.size == 2
270
- @buchung.konto = txn.splits.first[:account].id
271
- @buchung.gkonto = txn.splits.last[:account].id
337
+ @buchung.konto = Helpers.search_bank_guid(txn.splits.first[:account].id)
338
+ @buchung.gkonto = Helpers.search_bank_guid(txn.splits.last[:account].id)
272
339
  @buchung.betrag = txn.splits.first[:value]
273
340
  @buchung.buchcode = getBuchcode(txn.splits.first[:value])
274
341
  @contents << @buchung
@@ -288,12 +355,12 @@ def read_gnucash(filename)
288
355
  end if $VERBOSE
289
356
  txn.splits.each_with_index do |split, idx|
290
357
  if txn.value.to_s.eql?(split[:value].to_s)
291
- @buchung.konto = split[:account].id
358
+ @buchung.konto = Helpers.search_bank_guid(split[:account].id)
292
359
  @buchung.betrag = split[:value]
293
360
  @buchung.buchcode = getBuchcode(split[:value])
294
361
  else
295
362
  gegenbuchung = @buchung.clone
296
- gegenbuchung.gkonto = split[:account].id
363
+ gegenbuchung.gkonto = Helpers.search_bank_guid(split[:account].id)
297
364
  gegenbuchung.betrag = split[:value]
298
365
  gegenbuchung.buchcode = getBuchcode(split[:value])
299
366
  gegenbuchungen << gegenbuchung
@@ -1,3 +1,3 @@
1
1
  module Gnucash2Bmd
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnucash2bmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklaus Giger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop