king_dtaus 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +29 -9
- data/VERSION +1 -1
- data/king_dtaus.gemspec +57 -0
- data/lib/king_dta/account.rb +20 -16
- data/lib/king_dta/booking.rb +34 -33
- data/lib/king_dta/dtaus.rb +138 -130
- data/lib/king_dta/exception.rb +5 -0
- data/lib/king_dta/helper.rb +4 -16
- data/lib/king_dtaus.rb +1 -0
- data/spec/account_spec.rb +21 -0
- data/spec/booking_spec.rb +19 -0
- data/spec/dtaus_spec.rb +44 -8
- data/spec/helper_spec.rb +3 -1
- data/spec/spec_helper.rb +16 -16
- metadata +14 -12
- data/.gitignore +0 -4
- data/init.rb +0 -1
data/README.rdoc
CHANGED
@@ -1,24 +1,44 @@
|
|
1
1
|
= Dtaus
|
2
2
|
|
3
|
-
DTAUS is a format for
|
3
|
+
DTAUS is a format for German bank transfers and is short for
|
4
4
|
"Datenträgeraustausch". The format itself totally sucks because it was
|
5
5
|
established in the last century, to be used on floppy disks. Still almost
|
6
|
-
all
|
6
|
+
all German banks use it(they only seem innovative at robbing), and it is
|
7
7
|
therefore supported in common banking programs too.
|
8
8
|
|
9
9
|
This gem saves you all the trouble when generating dtaus-text.
|
10
10
|
|
11
11
|
== Install
|
12
12
|
|
13
|
-
gem install king_dtaus
|
13
|
+
gem install king_dtaus
|
14
14
|
|
15
15
|
== Features
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
|
17
|
+
* create lastschrift
|
18
|
+
* create gutschrift
|
19
|
+
|
20
|
+
|
21
|
+
== Example
|
22
|
+
|
23
|
+
#create a new dtaus object
|
24
|
+
dta = KingDta::Dtaus.new('LK')
|
25
|
+
# set sender account
|
26
|
+
dta.account = KingDta::Account.new( "bank_account_number", "bank_number", "bank_owner")
|
27
|
+
# the following should be done in a loop to add multiple bookings
|
28
|
+
# create receiving account
|
29
|
+
rec_acnt = KingDta::Account.new( "bank_account_number", "bank_number", "bank_owner" )
|
30
|
+
# create booking
|
31
|
+
booking = KingDta::Booking.new(rec_acnt, 100.00 )
|
32
|
+
# set booking text if you want to
|
33
|
+
booking.text = "Thanks for your purchase"
|
34
|
+
# add booking
|
35
|
+
dta.add( booking )
|
36
|
+
# end loop
|
37
|
+
|
38
|
+
# create datausstring and do with it whatever fits your workflow
|
39
|
+
my_str = dta.create
|
40
|
+
|
41
|
+
also make sure to read the specs
|
22
42
|
|
23
43
|
|
24
44
|
== Credits
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/king_dtaus.gemspec
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{king_dtaus}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Georg Leciejewski", "Georg Ledermann"]
|
12
|
+
s.date = %q{2011-02-09}
|
13
|
+
s.description = %q{DTAUS is a text-based format, to create bank transfers for german banks. This gem helps with the creation of those transfer files.}
|
14
|
+
s.email = %q{gl@salesking.eu}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"king_dtaus.gemspec",
|
24
|
+
"lib/king_dta/account.rb",
|
25
|
+
"lib/king_dta/booking.rb",
|
26
|
+
"lib/king_dta/dtaus.rb",
|
27
|
+
"lib/king_dta/exception.rb",
|
28
|
+
"lib/king_dta/helper.rb",
|
29
|
+
"lib/king_dtaus.rb",
|
30
|
+
"spec/account_spec.rb",
|
31
|
+
"spec/booking_spec.rb",
|
32
|
+
"spec/dtaus_spec.rb",
|
33
|
+
"spec/helper_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/salesking/king_dtaus}
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.4.1}
|
39
|
+
s.summary = %q{Generate DTAUS strings and files}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/account_spec.rb",
|
42
|
+
"spec/booking_spec.rb",
|
43
|
+
"spec/dtaus_spec.rb",
|
44
|
+
"spec/helper_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
else
|
53
|
+
end
|
54
|
+
else
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/lib/king_dta/account.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module KingDta
|
2
|
-
|
3
|
-
|
3
|
+
#Kontodaten verwalten mit Name des Inhabers und Bank, Bankleitzahl und Kontonummer.
|
4
|
+
class Account
|
4
5
|
include KingDta::Helper
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
# dta~ jeweilige Feld in DTAUS-Norm
|
7
|
+
attr_reader :bank_account_number, :bank_number, :owner, :kunnr, :dtakunnr
|
8
|
+
|
9
|
+
def initialize( ban, bank_number, owner, kunnr="" )
|
10
|
+
@bank_account_number = ban.kind_of?( Integer ) ? ban : ban.gsub(/\s/, '').to_i
|
11
|
+
@bank_number = bank_number.kind_of?( Integer ) ? bank_number : bank_number.gsub(/\s/, '').to_i
|
12
|
+
@owner= convert_text( owner )
|
13
|
+
@kunnr = kunnr.gsub(/\s/, '').to_i
|
14
|
+
|
15
|
+
raise Exception.new("Invalid bank account number #{ban}") if @bank_account_number == 0
|
16
|
+
raise Exception.new("BLZnummer #{bank_number} ungültig") if @bank_number == 0
|
17
|
+
raise Exception.new("Invalid account owner #{owner}") unless @owner.kind_of?(String) # not possible
|
18
|
+
# @dtakunnr = convert_text( @kunnr )
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/king_dta/booking.rb
CHANGED
@@ -1,47 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module KingDta
|
2
|
-
|
3
|
+
class Booking
|
3
4
|
include KingDta::Helper
|
4
|
-
|
5
|
+
|
5
6
|
# Die am häufigsten benötigten Textschlüssel
|
6
7
|
LASTSCHRIFT_ABBUCHUNG = '04000'
|
7
8
|
LASTSCHRIFT_EINZUGSERMAECHTIGUNG = '05000'
|
8
9
|
UEBERWEISUNG_GUTSCHRIFT = '51000'
|
9
10
|
|
10
11
|
attr_reader :value, :account, :text, :schluessel
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
raise "Hey, a booking should have an Account" unless account.kind_of?( Account )
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
12
|
+
#Eine Buchung ist definiert durch:
|
13
|
+
#- Konto (siehe Klasse Konto
|
14
|
+
#- Betrag
|
15
|
+
# Der Betrag kann , oder . als Dezimaltrenner enthalten.
|
16
|
+
#- optional Buchungstext
|
17
|
+
def initialize( account, value, text=nil, schluessel=nil )
|
18
|
+
raise Exception.new("Hey, a booking should have an Account") unless account.kind_of?( Account )
|
19
|
+
@account = account
|
20
|
+
@text = text ? convert_text( text ) : text
|
21
|
+
@schluessel = schluessel
|
22
|
+
if value.is_a?(String)
|
23
|
+
value = BigDecimal.new value.sub(',', '.')
|
24
|
+
elsif value.is_a?(Numeric)
|
25
|
+
value = BigDecimal.new value.to_s
|
26
|
+
else
|
27
|
+
raise Exception.new("Gimme a value as a String or Numeric. You gave me a #{value.class}")
|
28
|
+
end
|
29
|
+
value = ( value * 100 ).to_i #€-Cent
|
30
|
+
if value == 0
|
31
|
+
raise Exception.new("A booking of 0.00 € makes no sence")
|
32
|
+
elsif value > 0
|
33
|
+
@value = value
|
34
|
+
@pos = true
|
35
|
+
else
|
36
|
+
@value = -value
|
37
|
+
@pos = false
|
38
|
+
end
|
39
|
+
end
|
39
40
|
|
40
41
|
def text=(text)
|
41
42
|
@text = convert_text( text )
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
+
def pos?; @pos end
|
45
46
|
|
46
|
-
|
47
|
-
end
|
47
|
+
end #class Buchung
|
48
|
+
end #module dtaus
|
data/lib/king_dta/dtaus.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
#Erstelle eine DTAUS-Datei.
|
2
3
|
#Typ ist 'LK' (Lastschrift Kunde) oder 'GK' (Gutschrift Kunde)
|
3
4
|
#
|
4
5
|
#Infos zu DTAUS: http://www.infodrom.org/projects/dtaus/dtaus.php3
|
5
|
-
|
6
|
-
#Die Methoden müssen in der Reihenfolge:
|
7
|
-
#- account (definieren des eigenen Kontos)
|
8
|
-
#- bookings
|
9
|
-
#- dtaDatei/begleitblatt
|
10
|
-
#abgearbeitet werden.
|
11
|
-
#
|
12
|
-
#Kontodaten verwalten mit Name des Inhabers und Bank, Bankleitzahl und Kontonummer.
|
6
|
+
|
13
7
|
module KingDta
|
14
8
|
class Dtaus
|
15
9
|
include KingDta::Helper
|
16
|
-
attr_reader :sum_bank_account_numbers, :sum_bank_numbers, :
|
10
|
+
attr_reader :sum_bank_account_numbers, :sum_bank_numbers, :sum_values, :default_text
|
17
11
|
|
18
|
-
#
|
12
|
+
# Create a new dtaus file/string.
|
19
13
|
# ==== Parameter
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@
|
26
|
-
@
|
14
|
+
# typ<String>:: valid strings are 'LK' (Lastschrift Kunde) and 'GK' (Gutschrift Kunde)
|
15
|
+
# typ<Date>:: date when the the transfer is to be created
|
16
|
+
def initialize( typ, date=Date.today )
|
17
|
+
raise ArgumentError.new("Wrong date format. Make it a Time or Date object with yyyy-mm-dd") unless date.respond_to?(:strftime)
|
18
|
+
raise ArgumentError.new("Unknown order type: #{typ}. Allowed Values are LK, GK") unless ['LK','GK'].include?(typ)
|
19
|
+
@date = date
|
20
|
+
@typ = typ
|
21
|
+
@value_pos = true #all values are positive by default. Variable changes with first booking entry
|
22
|
+
@closed = false
|
27
23
|
@default_text = '' # default verwendungzweck
|
28
24
|
end
|
29
|
-
|
30
|
-
#
|
25
|
+
|
26
|
+
# Set the sending account(you own)
|
27
|
+
# === Parameter
|
28
|
+
# account<Account>:: the sending account, must be an instance of class
|
29
|
+
# KingDta::Account
|
31
30
|
def account=( account )
|
32
|
-
raise "Come on i need an Account object" unless account.kind_of?( Account )
|
31
|
+
raise Exception.new("Come on, i need an Account object") unless account.kind_of?( Account )
|
33
32
|
@account = account
|
34
33
|
end
|
35
34
|
|
36
|
-
# The dtaus format as string.
|
35
|
+
# The dtaus format as string. All data is appended to it during creation
|
37
36
|
def dta_string
|
38
37
|
@dta_string ||= ''
|
39
38
|
end
|
39
|
+
# Array of bookings
|
40
40
|
def bookings
|
41
41
|
@bookings ||= []
|
42
42
|
end
|
@@ -45,19 +45,25 @@ module KingDta
|
|
45
45
|
@default_text = convert_text( text )
|
46
46
|
end
|
47
47
|
|
48
|
-
#
|
48
|
+
# Add a booking. The prefix (pos/neg) is beeing checked if it is identical
|
49
|
+
# with the last one
|
50
|
+
# === Parameter
|
51
|
+
# booking<Booking>:: KingDta::Booking object
|
52
|
+
# === Raises
|
53
|
+
# error if the prefix within the bookings has changed
|
49
54
|
def add ( booking )
|
50
|
-
raise "The file has alreay been closed, cannot add new booking" if @closed
|
51
|
-
#
|
52
|
-
|
53
|
-
@value_pos
|
54
|
-
raise "The prefix within bookings changed from #{@value_pos} to #{booking.pos?}" if @value_pos != booking.pos?
|
55
|
+
raise Exception.new("The file has alreay been closed, cannot add new booking") if @closed
|
56
|
+
#the first booking decides wether all values are po or negative
|
57
|
+
@value_pos = booking.pos? if bookings.empty?
|
58
|
+
raise Exception.new("The prefix within bookings changed from #{@value_pos} to #{booking.pos?}") if @value_pos != booking.pos?
|
55
59
|
bookings << booking
|
56
60
|
end
|
57
61
|
|
58
62
|
# Creates the whole dta string(in the right order) and returns it
|
63
|
+
# === Raises
|
64
|
+
# error if there are no bookings
|
59
65
|
def create
|
60
|
-
raise "Cannot create DTAUS without bookings" if bookings.empty?
|
66
|
+
raise Exception.new("Cannot create DTAUS without bookings") if bookings.empty?
|
61
67
|
@closed = true
|
62
68
|
# cleanup before we start
|
63
69
|
@dta_string = dta_string.empty? ? dta_string : ''
|
@@ -69,60 +75,62 @@ module KingDta
|
|
69
75
|
end
|
70
76
|
|
71
77
|
def set_checksums
|
72
|
-
@sum_bank_account_numbers, @sum_bank_numbers, @
|
78
|
+
@sum_bank_account_numbers, @sum_bank_numbers, @sum_values = 0,0,0
|
73
79
|
bookings.each do |b|
|
74
|
-
@sum_bank_account_numbers
|
75
|
-
@sum_bank_numbers
|
76
|
-
@
|
80
|
+
@sum_bank_account_numbers += b.account.bank_account_number
|
81
|
+
@sum_bank_numbers += b.account.bank_number
|
82
|
+
@sum_values += b.value
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
#Create a DTA-File
|
86
|
+
# Create a DTA-File, from current dta information
|
87
|
+
# === Parameter
|
88
|
+
# filename<String>:: defaults to DTAUS0.TXT
|
81
89
|
def create_file(filename ='DTAUS0.TXT')
|
82
90
|
file = open( filename, 'w')
|
83
|
-
file
|
91
|
+
file << create
|
84
92
|
file.close()
|
85
|
-
print "#{filename}
|
93
|
+
print "#{filename} created containing #{@bookings.size} bookings\n"
|
86
94
|
end
|
87
95
|
|
88
96
|
|
89
97
|
#Erstellen A-Segment der DTAUS-Datei
|
90
98
|
#Aufbau des Segments:
|
91
|
-
# Nr.
|
92
|
-
# 1
|
93
|
-
# 2
|
94
|
-
# 3
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
# 4
|
100
|
-
# 5
|
101
|
-
# 6
|
102
|
-
# 7
|
103
|
-
# 8
|
104
|
-
# 9
|
105
|
-
# 10
|
106
|
-
# 11a 80
|
107
|
-
# 11b 95
|
108
|
-
# 11c 103
|
109
|
-
# 12
|
110
|
-
#
|
111
|
-
#
|
99
|
+
# Nr. Start Länge Beschreibung
|
100
|
+
# 1 0 4 Zeichen Länge des Datensatzes, immer 128 Bytes, also immer "0128"
|
101
|
+
# 2 4 1 Zeichen Datensatz-Typ, immer 'A'
|
102
|
+
# 3 5 2 Zeichen Art der Transaktionen
|
103
|
+
# "LB" für Lastschriften Bankseitig
|
104
|
+
# "LK" für Lastschriften Kundenseitig
|
105
|
+
# "GB" für Gutschriften Bankseitig
|
106
|
+
# "GK" für Gutschriften Kundenseitig
|
107
|
+
# 4 7 8 Zeichen Bankleitzahl des Auftraggebers
|
108
|
+
# 5 15 8 Zeichen CST, "00000000", nur belegt, wenn Diskettenabsender Kreditinstitut
|
109
|
+
# 6 23 27 Zeichen Name des Auftraggebers
|
110
|
+
# 7 50 6 Zeichen aktuelles Datum im Format DDMMJJ
|
111
|
+
# 8 56 4 Zeichen CST, " " (Blanks)
|
112
|
+
# 9 60 10 Zeichen Kontonummer des Auftraggebers
|
113
|
+
# 10 70 10 Zeichen Optionale Referenznummer
|
114
|
+
# 11a 80 15 Zeichen Reserviert, 15 Blanks
|
115
|
+
# 11b 95 8 Zeichen Ausführungsdatum im Format DDMMJJJJ. Nicht jünger als Erstellungsdatum (A7), jedoch höchstens 15 Kalendertage später. Sonst Blanks.
|
116
|
+
# 11c 103 24 Zeichen Reserviert, 24 Blanks
|
117
|
+
# 12 127 1 Zeichen Währungskennzeichen
|
118
|
+
# " " = DM
|
119
|
+
# "1" = Euro
|
112
120
|
# Insgesamt 128 Zeichen
|
113
121
|
def add_a
|
114
122
|
data = '0128'
|
115
|
-
data += 'A'
|
116
|
-
data += @typ
|
117
|
-
data += '%8i' % @account.bank_number #.rjust(8)
|
123
|
+
data += 'A' #Segment
|
124
|
+
data += @typ #Lastschriften Kunde
|
125
|
+
data += '%8i' % @account.bank_number #.rjust(8) #bank_number
|
118
126
|
data += '%08i' % 0 #belegt, wenn Bank
|
119
127
|
data += '%-27.27s' % @account.owner
|
120
|
-
data += @
|
128
|
+
data += @date.strftime("%d%m%y") #aktuelles Datum im Format DDMMJJ
|
121
129
|
data += ' ' * 4 #bankinternes Feld
|
122
130
|
data += '%010i' % @account.bank_account_number
|
123
131
|
data += '%010i' % 0 #Referenznummer
|
124
132
|
data += ' ' * 15 #Reserve
|
125
|
-
data += '%8s' % @
|
133
|
+
data += '%8s' % @date.strftime("%d%m%Y") #Ausführungsdatum (ja hier 8 Stellen, Erzeugungsdat. hat 6 Stellen)
|
126
134
|
data += ' ' * 24 #Reserve
|
127
135
|
data += '1' #Kennzeichen Euro
|
128
136
|
raise "DTAUS: Längenfehler A (#{data.size} <> 128)\n" if data.size != 128
|
@@ -131,59 +139,59 @@ module KingDta
|
|
131
139
|
|
132
140
|
#Erstellen C-Segmente (Buchungen mit Texten) der DTAUS-Datei
|
133
141
|
#Aufbau:
|
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
|
-
#
|
142
|
+
# Nr. St Länge Beschreibung
|
143
|
+
# 1 0 4 Zeichen Länge des Datensatzes, 187 + x * 29 (x..Anzahl Erweiterungsteile)
|
144
|
+
# 2 4 1 Zeichen Datensatz-Typ, immer 'C'
|
145
|
+
# 3 5 8 Zeichen Bankleitzahl des Auftraggebers (optional)
|
146
|
+
# 4 13 8 Zeichen Bankleitzahl des Kunden
|
147
|
+
# 5 21 10 Zeichen Kontonummer des Kunden
|
148
|
+
# 6 31 13 Zeichen Verschiedenes
|
149
|
+
# 1. Zeichen: "0"
|
150
|
+
# 2. - 12. Zeichen: interne Kundennummer oder Nullen
|
151
|
+
# 13. Zeichen: "0"
|
152
|
+
# Die interne Nummer wird vom erstbeauftragten Institut zum endbegünstigten Institut weitergeleitet. Die Weitergabe der internenen Nummer an den Überweisungsempfänger ist der Zahlstelle freigestellt.
|
153
|
+
# 7 44 5 Zeichen Art der Transaktion (7a: 2 Zeichen, 7b: 3 Zeichen)
|
154
|
+
# "04000" Lastschrift des Abbuchungsauftragsverfahren
|
155
|
+
# "05000" Lastschrift des Einzugsermächtigungsverfahren
|
156
|
+
# "05005" Lastschrift aus Verfügung im elektronischen Cash-System
|
157
|
+
# "05006" Wie 05005 mit ausländischen Karten
|
158
|
+
# "51000" Überweisungs-Gutschrift
|
159
|
+
# "53000" Überweisung Lohn/Gehalt/Rente
|
160
|
+
# "5400J" Vermögenswirksame Leistung (VL) ohne Sparzulage
|
161
|
+
# "5400J" Vermögenswirksame Leistung (VL) mit Sparzulage
|
162
|
+
# "56000" Überweisung öffentlicher Kassen
|
163
|
+
# Die im Textschlüssel mit J bezeichnete Stelle, wird bei Übernahme in eine Zahlung automatisch mit der jeweils aktuellen Jahresendziffer (7, wenn 97) ersetzt.
|
164
|
+
# 8 49 1 Zeichen Reserviert, " " (Blank)
|
165
|
+
# 9 50 11 Zeichen Betrag in DM
|
166
|
+
# 10 61 8 Zeichen Bankleitzahl des Auftraggebers
|
167
|
+
# 11 69 10 Zeichen Kontonummer des Auftraggebers
|
168
|
+
# 12 79 11 Zeichen Betrag in Euro einschließlich Nachkommastellen, nur belegt, wenn Euro als Währung angegeben wurde (A12, C17a), sonst Nullen
|
169
|
+
# 13 90 3 Zeichen Reserviert, 3 Blanks
|
170
|
+
# 14a 93 27 Zeichen Name des Kunden
|
171
|
+
# 14b 120 8 Zeichen Reserviert, 8 Blanks
|
164
172
|
# Insgesamt 128 Zeichen
|
165
173
|
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
174
|
+
# 15 128 27 Zeichen Name des Auftraggebers
|
175
|
+
# 16 155 27 Zeichen Verwendungszweck
|
176
|
+
# 17a 182 1 Zeichen Währungskennzeichen
|
177
|
+
# " " = DM
|
178
|
+
# "1" = Euro
|
179
|
+
# 17b 183 2 Zeichen Reserviert, 2 Blanks
|
180
|
+
# 18 185 2 Zeichen Anzahl der Erweiterungsdatensätze, "00" bis "15"
|
181
|
+
# 19 187 2 Zeichen Typ (1. Erweiterungsdatensatz)
|
182
|
+
# "01" Name des Kunden
|
183
|
+
# "02" Verwendungszweck
|
184
|
+
# "03" Name des Auftraggebers
|
185
|
+
# 20 189 27 Zeichen Beschreibung gemäß Typ
|
186
|
+
# 21 216 2 Zeichen wie C19, oder Blanks (2. Erweiterungsdatensatz)
|
187
|
+
# 22 218 27 Zeichen wie C20, oder Blanks
|
188
|
+
# 23 245 11 Zeichen 11 Blanks
|
189
|
+
# Insgesamt 256 Zeichen, kann wiederholt werden (max 3 mal)
|
182
190
|
# ==== Parameter
|
183
191
|
# booking<Object>::Booking object to be written to c-sektion
|
184
192
|
# ==== Returns
|
185
193
|
# <String>:: The current dta_string
|
186
|
-
def add_c( booking)
|
194
|
+
def add_c( booking )
|
187
195
|
zahlungsart = if @typ == 'LK'
|
188
196
|
booking.schluessel || Booking::LASTSCHRIFT_EINZUGSERMAECHTIGUNG
|
189
197
|
elsif @typ == 'GK'
|
@@ -248,7 +256,7 @@ module KingDta
|
|
248
256
|
add_ext( exts[6..9] )
|
249
257
|
add_ext( exts[10..13] )
|
250
258
|
dta_string
|
251
|
-
end
|
259
|
+
end #dataC
|
252
260
|
|
253
261
|
# Format an extension so it can be used in string substitution
|
254
262
|
# ==== Returns
|
@@ -265,31 +273,31 @@ module KingDta
|
|
265
273
|
# <Array[Array[String,String]]>:: two dim. ary containing: [extension type(01 02 03),string content]
|
266
274
|
def add_ext( ext)
|
267
275
|
raise "Nur #{ext.size} Erweiterungstexte, 4 benötigt" if ext.size != 4
|
268
|
-
str =
|
269
|
-
str +=
|
270
|
-
str +=
|
271
|
-
str +=
|
272
|
-
#
|
276
|
+
str = "%2.2s%-27.27s" % format_ext(ext[0][0], ext[0][1] )
|
277
|
+
str += "%2.2s%-27.27s" % format_ext( ext[1][0], ext[1][1] )
|
278
|
+
str += "%2.2s%-27.27s" % format_ext( ext[2][0], ext[2][1] )
|
279
|
+
str += "%2.2s%-27.27s" % format_ext( ext[3][0], ext[3][1] )
|
280
|
+
# devider 12 blanks
|
273
281
|
str += ' ' * 12
|
274
282
|
unless str !~ /\S/ # only add if something is in there .. only whitespace => same as str.blank?
|
275
283
|
raise "DTAUS: Längenfehler C/3 #{str.size} " if str.size != 128
|
276
284
|
dta_string << str
|
277
285
|
end
|
278
|
-
end
|
286
|
+
end #dataC
|
279
287
|
|
280
288
|
#Erstellen E-Segment (Prüfsummen) der DTAUS-Datei
|
281
289
|
#Aufbau:
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
290
|
+
# Nr. Start Länge Beschreibung
|
291
|
+
# 1 0 4 Zeichen Länge des Datensatzes, immer 128 Bytes, also immer "0128"
|
292
|
+
# 2 4 1 Zeichen Datensatz-Typ, immer 'E'
|
293
|
+
# 3 5 5 Zeichen " " (Blanks)
|
294
|
+
# 4 10 7 Zeichen Anzahl der Datensätze vom Typ C
|
295
|
+
# 5 17 13 Zeichen Kontrollsumme Beträge
|
296
|
+
# 6 30 17 Zeichen Kontrollsumme Kontonummern
|
297
|
+
# 7 47 17 Zeichen Kontrollsumme Bankleitzahlen
|
298
|
+
# 8 64 13 Zeichen Kontrollsumme Euro, nur belegt, wenn Euro als Währung angegeben wurde (A12, C17a)
|
299
|
+
# 9 77 51 Zeichen 51 Blanks
|
300
|
+
# Insgesamt 128 Zeichen
|
293
301
|
def add_e
|
294
302
|
str = '0128'
|
295
303
|
str += 'E'
|
@@ -298,11 +306,11 @@ module KingDta
|
|
298
306
|
str += '0' * 13 #Reserve
|
299
307
|
str += '%017i' % @sum_bank_account_numbers
|
300
308
|
str += '%017i' % @sum_bank_numbers
|
301
|
-
str += '%013i' % @
|
309
|
+
str += '%013i' % @sum_values
|
302
310
|
str += ' ' * 51 #Abgrenzung Datensatz
|
303
311
|
raise "DTAUS: Längenfehler E #{str.size} <> 128" if str.size != 128
|
304
312
|
dta_string << str
|
305
313
|
end
|
306
|
-
|
307
|
-
end
|
308
|
-
end
|
314
|
+
|
315
|
+
end #class dtaus
|
316
|
+
end
|
data/lib/king_dta/helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module KingDta
|
2
3
|
module Helper
|
3
4
|
#Zeichen umsetzen gemäss DTA-Norm
|
4
5
|
def convert_text( text)
|
5
6
|
text = text.to_s
|
6
7
|
return text if text.empty?
|
7
|
-
raise "Text kein String >#{text}< (#{text.class})" unless text.kind_of?( String )
|
8
|
+
raise "Text kein String >#{text}< (#{text.class})" unless text.kind_of?( String ) # not possible
|
8
9
|
text.gsub!('Ä', 'AE')
|
9
10
|
text.gsub!('Ü', 'UE')
|
10
11
|
text.gsub!('Ö', 'OE')
|
@@ -14,20 +15,7 @@ module KingDta
|
|
14
15
|
text.gsub!('ß', 'SS')
|
15
16
|
|
16
17
|
text.gsub! /[^a-zA-Z0-9\ \.\,\&\-\/\+\*\$\%]/, '' # Remove all invalid chars
|
17
|
-
|
18
|
-
text = text.upcase.strip
|
19
|
-
text
|
20
|
-
# text = text.to_s()
|
21
|
-
# puts "Text kein String >#{text}< (#{text.class})" if ! text.kind_of?( String )
|
22
|
-
# text = text.upcase()
|
23
|
-
# text = text.gsub('Ä', 'AE')
|
24
|
-
# text = text.gsub('Ü', 'UE')
|
25
|
-
# text = text.gsub('Ö', 'OE')
|
26
|
-
# text = text.gsub('ä', 'AE')
|
27
|
-
# text = text.gsub('ü', 'UE')
|
28
|
-
# text = text.gsub('ö', 'OE')
|
29
|
-
# text = text.gsub('ß', 'SS')
|
30
|
-
# return text = text.strip
|
18
|
+
text.upcase.strip
|
31
19
|
end
|
32
20
|
end
|
33
|
-
end
|
21
|
+
end
|
data/lib/king_dtaus.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/spec_helper"
|
2
|
+
|
3
|
+
describe KingDta::Account do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@bank_account = test_kto2
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should initialize a new account" do
|
10
|
+
lambda{ KingDta::Account.new(@bank_account.nr, @bank_account.blz, @bank_account.name, @bank_account.bank) }.should_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should fail if bank account number is invalid" do
|
14
|
+
lambda{ KingDta::Account.new(0, @bank_account.blz, @bank_account.name, @bank_account.bank) }.should raise_error(KingDta::Exception)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should fail if bank number is invalid" do
|
18
|
+
lambda{ KingDta::Account.new(@bank_account.nr, 0, @bank_account.name, @bank_account.bank) }.should raise_error(KingDta::Exception)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/booking_spec.rb
CHANGED
@@ -12,6 +12,25 @@ describe KingDta::Booking do
|
|
12
12
|
booking = KingDta::Booking.new(@account, "159.73")
|
13
13
|
booking.value.should == 15973
|
14
14
|
end
|
15
|
+
|
16
|
+
it "should raise if initialized without an account" do
|
17
|
+
lambda{ KingDta::Booking.new("account", Date.today) }.should raise_error(KingDta::Exception)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise if initialized with wrong value type" do
|
21
|
+
lambda{ KingDta::Booking.new(@account, Date.today) }.should raise_error(KingDta::Exception)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise if initialized with 0 value" do
|
25
|
+
lambda{ KingDta::Booking.new(@account, 0) }.should raise_error(KingDta::Exception)
|
26
|
+
lambda{ KingDta::Booking.new(@account, 0.00) }.should raise_error(KingDta::Exception)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set pos to false with negative value" do
|
30
|
+
b = KingDta::Booking.new(@account, -1)
|
31
|
+
b.value.should == 100
|
32
|
+
b.should_not be_pos
|
33
|
+
end
|
15
34
|
|
16
35
|
it "should have no rounding error for float" do
|
17
36
|
booking = KingDta::Booking.new(@account, 159.73)
|
data/spec/dtaus_spec.rb
CHANGED
@@ -16,9 +16,38 @@ describe KingDta::Dtaus do
|
|
16
16
|
it "should not init without values" do
|
17
17
|
lambda{ KingDta::Dtaus.new }.should raise_error(ArgumentError)
|
18
18
|
end
|
19
|
+
|
19
20
|
it "should init with valid values" do
|
20
21
|
lambda{ KingDta::Dtaus.new('LK', Date.today) }.should_not raise_error(ArgumentError)
|
21
22
|
end
|
23
|
+
|
24
|
+
it "should not init with an unknown type" do
|
25
|
+
lambda{ KingDta::Dtaus.new('UNKNOWN', "date") }.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not init with an invalid date" do
|
29
|
+
lambda{ KingDta::Dtaus.new('LK', "date") }.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should deny invalid accounts" do
|
33
|
+
lambda{ @dtaus.account = "account" }.should raise_error(KingDta::Exception)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not add a booking if closed" do
|
37
|
+
@dtaus.add(@booking)
|
38
|
+
@dtaus.create
|
39
|
+
lambda{ @dtaus.add(@booking) }.should raise_error(KingDta::Exception)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not add a booking if closed" do
|
43
|
+
@dtaus.add(@booking)
|
44
|
+
negative_booking = KingDta::Booking.new(KingDta::Account.new( @kto2.nr, @kto2.blz, @kto2.name, @kto2.bank ), -120.25 )
|
45
|
+
lambda{ @dtaus.add(negative_booking) }.should raise_error(KingDta::Exception)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not create if there are no bookings" do
|
49
|
+
lambda{ @dtaus.create}.should raise_error(KingDta::Exception)
|
50
|
+
end
|
22
51
|
|
23
52
|
it "should create header" do
|
24
53
|
str = @dtaus.add_a
|
@@ -35,12 +64,12 @@ describe KingDta::Dtaus do
|
|
35
64
|
@dtaus.set_checksums
|
36
65
|
@dtaus.sum_bank_account_numbers.should == 2787777
|
37
66
|
@dtaus.sum_bank_numbers.should == 37040044
|
38
|
-
@dtaus.
|
67
|
+
@dtaus.sum_values.should == 22025
|
39
68
|
end
|
40
69
|
|
41
70
|
it "should create c-sektion with booking text at 19" do
|
42
71
|
@dtaus.add(@booking)
|
43
|
-
|
72
|
+
@dtaus.bookings.first.text = 'SalesKing Monatsbeitrag 08/10 Freelancer Version'
|
44
73
|
@dtaus.add_c(@booking)
|
45
74
|
str = @dtaus.dta_string
|
46
75
|
str.length.should == 256
|
@@ -50,7 +79,7 @@ describe KingDta::Dtaus do
|
|
50
79
|
end
|
51
80
|
|
52
81
|
it "should create c-sektion with default booking text" do
|
53
|
-
|
82
|
+
@dtaus.default_text = 'Default verwendungszweck'
|
54
83
|
@dtaus.add_c(@booking)
|
55
84
|
str = @dtaus.dta_string
|
56
85
|
str.length.should == 256
|
@@ -60,7 +89,7 @@ describe KingDta::Dtaus do
|
|
60
89
|
end
|
61
90
|
|
62
91
|
it "should create the whole dta string with a single booking" do
|
63
|
-
|
92
|
+
@dtaus.default_text = 'Default verwendungszweck'
|
64
93
|
@dtaus.add(@booking)
|
65
94
|
str = @dtaus.create
|
66
95
|
str.length.should == 512
|
@@ -75,7 +104,7 @@ describe KingDta::Dtaus do
|
|
75
104
|
|
76
105
|
it "should create whole dta string with long booking text in extension" do
|
77
106
|
@dtaus.add(@booking)
|
78
|
-
|
107
|
+
@dtaus.bookings.first.text = 'Rgn R-3456-0102220 Monatsbeitrag 08/10 Freelancer Version Vielen Dank Ihre SalesKing GmbH'
|
79
108
|
str = @dtaus.create
|
80
109
|
str.length.should == 640
|
81
110
|
str.should include(@kto2.name.upcase)
|
@@ -86,8 +115,8 @@ describe KingDta::Dtaus do
|
|
86
115
|
end
|
87
116
|
|
88
117
|
it "should create the whole dta string with a lot of bookings" do
|
89
|
-
|
90
|
-
|
118
|
+
@dtaus.default_text = 'Default Verwendungszweck'
|
119
|
+
6.times { @dtaus.add(@booking) }
|
91
120
|
str = @dtaus.create
|
92
121
|
str.length.should == 1792
|
93
122
|
str.should include(@kto1.name.upcase)
|
@@ -103,4 +132,11 @@ describe KingDta::Dtaus do
|
|
103
132
|
"0128E 0000006000000000000000000000016726662000000002222402640000000132150 "
|
104
133
|
str.should == out
|
105
134
|
end
|
106
|
-
|
135
|
+
|
136
|
+
xit "should create file" do
|
137
|
+
@dtaus.default_text = 'Default Verwendungszweck'
|
138
|
+
6.times { @dtaus.add(@booking) }
|
139
|
+
file = @dtaus.create_file
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
data/spec/helper_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'rubygems'
|
2
|
-
require 'spec'
|
3
3
|
require 'ostruct'
|
4
4
|
require 'date'
|
5
5
|
require "#{File.dirname(__FILE__)}/../lib/king_dtaus"
|
6
6
|
|
7
7
|
#Filename der eigenen Kontodaten
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
8
|
+
# Beispiel:
|
9
|
+
# typ:LK
|
10
|
+
# blz:99988811
|
11
|
+
# konto:123456
|
12
|
+
# bank:Nord-Ostschwaebische Sandbank
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
14
|
+
# name:Jodelverein Holladrioe 1863 e.V.
|
15
|
+
# zweck:Mitgliedsbeitrag 2003
|
16
|
+
# Der Typ ist LK oder GK. Siehe Option -t
|
17
|
+
# zweck ist ein optionaler Default-Text, der verwendet wird,
|
18
|
+
# falls eine Buchung keinen Text hat.
|
19
|
+
# Die Adressdaten der Bank sind optional und werdezum erzeugen
|
20
|
+
# des Begleitblatts verwendet
|
21
21
|
# bankstrasse:Kieselweg 3
|
22
|
-
#
|
23
|
-
#
|
22
|
+
# bankplz:0815
|
23
|
+
# bankort:Felsblock
|
24
24
|
def test_kto1
|
25
25
|
opts = { :nr => '2880037', :blz => '37040044', :name =>'Gimme your Money AG',
|
26
26
|
:bank => 'Commerzbank Köln', :zweck => 'Monatsbeitrag' }
|
@@ -40,4 +40,4 @@ def test_kto3
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# the test account responds to everything
|
43
|
-
class TestKonto < OpenStruct; end
|
43
|
+
class TestKonto < OpenStruct; end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: king_dtaus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Georg Leciejewski
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-02-09 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -29,17 +29,18 @@ extensions: []
|
|
29
29
|
extra_rdoc_files:
|
30
30
|
- README.rdoc
|
31
31
|
files:
|
32
|
-
- .gitignore
|
33
32
|
- MIT-LICENSE
|
34
33
|
- README.rdoc
|
35
34
|
- Rakefile
|
36
35
|
- VERSION
|
37
|
-
-
|
36
|
+
- king_dtaus.gemspec
|
38
37
|
- lib/king_dta/account.rb
|
39
38
|
- lib/king_dta/booking.rb
|
40
39
|
- lib/king_dta/dtaus.rb
|
40
|
+
- lib/king_dta/exception.rb
|
41
41
|
- lib/king_dta/helper.rb
|
42
42
|
- lib/king_dtaus.rb
|
43
|
+
- spec/account_spec.rb
|
43
44
|
- spec/booking_spec.rb
|
44
45
|
- spec/dtaus_spec.rb
|
45
46
|
- spec/helper_spec.rb
|
@@ -49,8 +50,8 @@ homepage: http://github.com/salesking/king_dtaus
|
|
49
50
|
licenses: []
|
50
51
|
|
51
52
|
post_install_message:
|
52
|
-
rdoc_options:
|
53
|
-
|
53
|
+
rdoc_options: []
|
54
|
+
|
54
55
|
require_paths:
|
55
56
|
- lib
|
56
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -74,12 +75,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
75
|
requirements: []
|
75
76
|
|
76
77
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.4.1
|
78
79
|
signing_key:
|
79
80
|
specification_version: 3
|
80
81
|
summary: Generate DTAUS strings and files
|
81
82
|
test_files:
|
82
|
-
- spec/
|
83
|
+
- spec/account_spec.rb
|
83
84
|
- spec/booking_spec.rb
|
84
|
-
- spec/helper_spec.rb
|
85
85
|
- spec/dtaus_spec.rb
|
86
|
+
- spec/helper_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/lib/king_dtaus"
|