Class: KingDta::Dtaus
Overview
Create a DTAUS string.
infos
www.ksk-koeln.de/formatbeschreibung_datentraegeraustausch.pdfx www.infodrom.org/projects/dtaus/dtaus.html
Instance Attribute Summary collapse
-
#sum_bank_account_numbers ⇒ Object
readonly
Returns the value of attribute sum_bank_account_numbers.
-
#sum_bank_numbers ⇒ Object
readonly
Returns the value of attribute sum_bank_numbers.
-
#sum_values ⇒ Object
readonly
Returns the value of attribute sum_values.
Attributes inherited from Dta
Instance Method Summary collapse
-
#add_a ⇒ Object
Erstellen A-Segment der DTAUS-Datei Aufbau des Segments: Nr.
-
#add_c(booking) ⇒ Object
Erstellen C-Segmente (Buchungen mit Texten) der DTAUS-Datei Aufbau: Nr.
-
#add_e ⇒ Object
Erstellen E-Segment (Prüfsummen) der DTAUS-Datei Aufbau: Nr.
-
#add_ext(ext) ⇒ Object
- Add a section-C extension, always containing the section type followed by 4 segments with 27 chars and an ending seperator of 12 blanks Only adds the segement if something is in there === Parameter <Array[Array]>
-
two dim.
-
#create ⇒ Object
Creates the whole dta string(in the right order) and returns it === Raises error if there are no bookings.
-
#format_ext(type, content) ⇒ Object
Format an extension so it can be used in string substitution === Returns Array[String, String]::[Extesnsion type(01 02 03), ‘text content ..’].
-
#initialize(typ, date = Date.today) ⇒ Dtaus
constructor
Create a new dtaus file/string.
-
#set_checksums ⇒ Object
TODO do it works? the .to_i stuff.
Methods inherited from Dta
#account=, #add, #bookings, #create_file, #dta_string
Methods included from Helper
Constructor Details
#initialize(typ, date = Date.today) ⇒ Dtaus
Create a new dtaus file/string.
Parameter
- typ<String>
-
valid strings are ‘LK’ (Lastschrift Kunde) and ‘GK’ (Gutschrift Kunde)
- typ<Date>
-
date when the the transfer is to be created
14 15 16 17 18 |
# File 'lib/king_dta/dtaus.rb', line 14 def initialize( typ, date=Date.today ) raise ArgumentError.new("Unknown order type: #{typ}. Allowed Values are LK, GK") unless ['LK','GK'].include?(typ) @typ = typ super(date) end |
Instance Attribute Details
#sum_bank_account_numbers ⇒ Object (readonly)
Returns the value of attribute sum_bank_account_numbers.
8 9 10 |
# File 'lib/king_dta/dtaus.rb', line 8 def sum_bank_account_numbers @sum_bank_account_numbers end |
#sum_bank_numbers ⇒ Object (readonly)
Returns the value of attribute sum_bank_numbers.
8 9 10 |
# File 'lib/king_dta/dtaus.rb', line 8 def sum_bank_numbers @sum_bank_numbers end |
#sum_values ⇒ Object (readonly)
Returns the value of attribute sum_values.
8 9 10 |
# File 'lib/king_dta/dtaus.rb', line 8 def sum_values @sum_values end |
Instance Method Details
#add_a ⇒ Object
Erstellen A-Segment der DTAUS-Datei Aufbau des Segments: Nr. Start Länge Beschreibung 1 0 4 Länge des Datensatzes, immer 128 Bytes, also immer “0128” 2 4 1 Datensatz-Typ, immer ‘A’ 3 5 2 Art der Transaktionen
"LB" f
4 7 8 Bankleitzahl des Auftraggebers 5 15 8 CST, “00000000”, nur belegt, wenn Diskettenabsender Kreditinstitut 6 23 27 Name des Auftraggebers 7 50 6 aktuelles Datum im Format DDMMJJ 8 56 4 CST, “ ” (Blanks) 9 60 10 Kontonummer des Auftraggebers 10 70 10 Optionale Referenznummer 11a 80 15 Reserviert, 15 Blanks 11b 95 8 Ausführungsdatum Format DDMMJJJJ. max A7 + 15 Tage. Default Blanks. 11c 103 24 Reserviert, 24 Blanks 12 127 1 Währungskennzeichen “1” = Euro
Insgesamt 128 Zeichen
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/king_dta/dtaus.rb', line 68 def add_a data = '0128' data += 'A' data += @typ data += '%8i' % @account.bank_number #.rjust(8) data += '%08i' % 0 data += '%-27.27s' % @account.owner_name data += @date.strftime("%d%m%y") # creation date - today data += ' ' * 4 data += '%010i' % @account.bank_account_number data += '%010i' % 0 data += ' ' * 15 data += '%8s' % @date.strftime("%d%m%Y") #Ausführungsdatum - ja hier 8 Stellen data += ' ' * 24 data += '1' raise "DTAUS: Längenfehler A (#{data.size} <> 128)\n" if data.size != 128 dta_string << data end |
#add_c(booking) ⇒ Object
Erstellen C-Segmente (Buchungen mit Texten) der DTAUS-Datei Aufbau:
Nr. St L
Parameter
booking<Object>::Booking object to be written to c-section
Returns
- <String>
-
The current dta_string
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 |
# File 'lib/king_dta/dtaus.rb', line 143 def add_c( booking ) zahlungsart = if @typ == 'LK' booking.account_key || Booking::LASTSCHRIFT_EINZUGSERMAECHTIGUNG elsif @typ == 'GK' booking.account_key || Booking::UEBERWEISUNG_GUTSCHRIFT end #Extended segments Long name & booking texts exts = [] # 1. Part #data1 = '%4i' % ?? #Satzlänge kommt später data1 = 'C' data1 += '%08i' % 0 data1 += '%-08i' % booking.account.bank_number data1 += '%010i' % booking.account.bank_account_number data1 += '0%011i0' % (booking.account.owner_number || 0) #interne Kundennummer data1 += zahlungsart data1 += ' ' data1 += '0' * 11 data1 += '%08i' % @account.bank_number data1 += '%010i' % @account.bank_account_number data1 += '%011i' % booking.value #Betrag in Euro einschl. Nachkomma data1 += ' ' * 3 data1 += '%-27.27s' % booking.account.owner_name exts << ['01', booking.account.owner_name[27..999] ] if booking.account.owner_name.size > 27 data1 += ' ' * 8 #Einfügen erst möglich, wenn Satzlänge bekannt # 2. Part data2 = "%27.27s" % @account.owner_name booking_txt = booking.text || default_text #Erste 27 Zeichen #if text < 26 fill with spaces data2 += booking_txt[0..26].ljust(27) booking_txt = booking_txt[27..999] # cut text into 27 long pieces while booking_txt && booking_txt.size > 0 && exts.size < 13 exts << ['02', booking_txt.ljust(27) ] booking_txt = booking_txt[27..999] end exts << ['03', @account.owner_name[27..999] ] if @account.owner_name.size > 27 data2 += '1' #EUR data2 += ' ' * 2 # Gesamte Satzlänge ermitteln ( data1(+4) + data2 + Erweiterungen ) data1 = "%04i#{data1}" % ( data1.size + 4 + data2.size + 2 + exts.size * 29 ) raise "DTAUS: Längenfehler C/1 #{data1.size} nicht 128, #{booking.account.owner_name}" unless data1.size == 128 dta_string << data1 #Anzahl Erweiterungen anfügen data2 += '%02i' % exts.size #Anzahl Erweiterungsteile #Die ersten zwei Erweiterungen gehen in data2, #Satz 3/4/5 à 4 Erweiterungen -> max. 14 Erweiterungen (ich ignoriere möglichen Satz 6) exts += [ ['00', "" ] ] * (14 - exts.size) #Die ersten zwei Erweiterungen gehen in data2, wenn leer nur mit blanks als füllung exts[0..1].each{|e| data2 += "%2.2s%-27.27s" % format_ext(e[0], e[1]) } data2 += ' ' * 11 # add the final piece of the second C section raise "DTAUS: Längenfehler C/2 #{data2.size} nicht 128, #{booking.account.owner_name}" unless data2.size == 128 dta_string << data2 #Create 4 text extensions add_ext( exts[2..5] ) add_ext( exts[6..9] ) add_ext( exts[10..13] ) dta_string end |
#add_e ⇒ Object
Erstellen E-Segment (Prüfsummen) der DTAUS-Datei Aufbau:
Nr. Start L
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/king_dta/dtaus.rb', line 248 def add_e str = '0128' str += 'E' str += ' ' * 5 str += '%07i' % @bookings.size str += '0' * 13 str += '%017i' % @sum_bank_account_numbers str += '%017i' % @sum_bank_numbers str += '%013i' % @sum_values str += ' ' * 51 raise "DTAUS: Längenfehler E #{str.size} <> 128" if str.size != 128 dta_string << str end |
#add_ext(ext) ⇒ Object
Add a section-C extension, always containing the section type followed by 4 segments with 27 chars and an ending seperator of 12 blanks Only adds the segement if something is in there
Parameter
- <Array[Array]>
-
two dim. ary containing: [extension type(01 02 03),string content]
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/king_dta/dtaus.rb', line 221 def add_ext( ext) raise "Nur #{ext.size} Erweiterungstexte, 4 benötigt" if ext.size != 4 str = "%2.2s%-27.27s" % format_ext(ext[0][0], ext[0][1] ) str += "%2.2s%-27.27s" % format_ext( ext[1][0], ext[1][1] ) str += "%2.2s%-27.27s" % format_ext( ext[2][0], ext[2][1] ) str += "%2.2s%-27.27s" % format_ext( ext[3][0], ext[3][1] ) # devider 12 blanks str += ' ' * 12 unless str !~ /\S/ # only add if something is in there .. only whitespace => same as str.blank? raise "DTAUS: Längenfehler C/3 #{str.size} " if str.size != 128 dta_string << str end end |
#create ⇒ Object
Creates the whole dta string(in the right order) and returns it
Raises
error if there are no bookings
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/king_dta/dtaus.rb', line 23 def create raise Exception.new("Cannot create DTAUS without bookings") if bookings.empty? @closed = true # cleanup before we start @dta_string = dta_string.empty? ? dta_string : '' set_checksums add_a bookings.each{ |b| add_c( b) } add_e dta_string end |
#format_ext(type, content) ⇒ Object
Format an extension so it can be used in string substitution
Returns
Array[String, String]::[Extesnsion type(01 02 03), ‘text content ..’]
211 212 213 214 |
# File 'lib/king_dta/dtaus.rb', line 211 def format_ext(type, content) ext = ( type == '00' ) ? [' ', ' '] : [ type, convert_text(content) ] ext end |
#set_checksums ⇒ Object
TODO do it works? the .to_i stuff
36 37 38 39 40 41 42 43 |
# File 'lib/king_dta/dtaus.rb', line 36 def set_checksums @sum_bank_account_numbers, @sum_bank_numbers, @sum_values = 0,0,0 bookings.each do |b| @sum_bank_account_numbers += b.account.bank_account_number @sum_bank_numbers += b.account.bank_number @sum_values += b.value end end |