king_dtaus 1.0.2 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/DTAUS0.TXT +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +38 -0
- data/README.rdoc +87 -20
- data/Rakefile +5 -25
- data/VERSION +1 -1
- data/docs/dtazv.pdf +0 -0
- data/docs/dtazv_bank_bbk.pdf +0 -0
- data/example.output +7 -0
- data/king_dtaus.gemspec +31 -11
- data/lib/king_dta/account.rb +48 -15
- data/lib/king_dta/booking.rb +4 -4
- data/lib/king_dta/dta.rb +53 -0
- data/lib/king_dta/dtaus.rb +22 -68
- data/lib/king_dta/dtazv.rb +470 -0
- data/lib/king_dtaus.rb +7 -5
- data/spec/account_spec.rb +140 -13
- data/spec/booking_spec.rb +4 -3
- data/spec/dtaus_spec.rb +44 -23
- data/spec/dtazv_spec.rb +294 -0
- data/spec/dtazv_test.rb +105 -0
- data/spec/helper_spec.rb +3 -4
- data/spec/spec_helper.rb +80 -7
- metadata +91 -20
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create ree@dtazv
|
data/DTAUS0.TXT
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0256Q370502991326049634JAN KUS MEINE EINE STRASSE 2 51063 MEINE KOELN 11060801110608N0000000000 0768T37050299EUR132604963411060800000000 0000000000MARKF1100 DE FIDEL CASTRO BUSH-AVENUE 55 445555 KUBA /GR1601101250000000012300695 EUR00000000000220250 00000000 0013 0 000256Z000000000000220000000000000001
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
king_dtaus (1.0.2)
|
5
|
+
king_dtaus
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
git (1.2.5)
|
12
|
+
jeweler (1.6.2)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
mocha (0.9.12)
|
17
|
+
rake (0.9.1)
|
18
|
+
rspec (2.6.0)
|
19
|
+
rspec-core (~> 2.6.0)
|
20
|
+
rspec-expectations (~> 2.6.0)
|
21
|
+
rspec-mocks (~> 2.6.0)
|
22
|
+
rspec-core (2.6.3)
|
23
|
+
rspec-expectations (2.6.0)
|
24
|
+
diff-lcs (~> 1.1.2)
|
25
|
+
rspec-mocks (2.6.0)
|
26
|
+
simplecov (0.4.2)
|
27
|
+
simplecov-html (~> 0.4.4)
|
28
|
+
simplecov-html (0.4.5)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
jeweler
|
35
|
+
king_dtaus!
|
36
|
+
mocha
|
37
|
+
rspec
|
38
|
+
simplecov
|
data/README.rdoc
CHANGED
@@ -1,32 +1,52 @@
|
|
1
|
-
=
|
1
|
+
= DTAUS & DTAZV always comes together
|
2
2
|
|
3
|
-
DTAUS
|
4
|
-
"Datenträgeraustausch". The format itself totally sucks because it was
|
5
|
-
established in the last century, to be used on floppy disks. Still almost
|
6
|
-
all German banks use it(they only seem innovative at robbing), and it is
|
3
|
+
DTAUS & DTAZV are formats for German bank transfers and is short for
|
4
|
+
"Datenträgeraustausch". The format itself totally sucks because it was
|
5
|
+
established in the last century, to be used on floppy disks. Still almost
|
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
|
-
This gem saves you all the trouble when generating
|
9
|
+
This gem saves you all the trouble when generating DTAUS- or DTAZV-text.
|
10
|
+
|
11
|
+
We love building payment applications
|
10
12
|
|
11
13
|
== Install
|
12
14
|
|
13
15
|
gem install king_dtaus
|
14
16
|
|
15
17
|
== Features
|
16
|
-
|
17
|
-
* create lastschrift
|
18
|
-
* create gutschrift
|
19
18
|
|
19
|
+
* create DTAUS debit advice (Lastschrift)
|
20
|
+
* create DTAUS credit advice (Gutschrift)
|
21
|
+
* create DTAZV debit advice
|
22
|
+
|
23
|
+
== TODOs
|
24
|
+
|
25
|
+
* first gem with no todo's - never seen it, huh?
|
26
|
+
|
27
|
+
== Resources
|
28
|
+
|
29
|
+
* DTAZV-Viewer: http://www.meta-evolutions.de/pages/artikel-20070630-dtazv-datei-betrachter.html
|
30
|
+
* DTA/DTAZV PHP Pear: http://pear.php.net/package/Payment_DTA
|
31
|
+
* Ruby Kernel Module: http://www.ruby-doc.org/core/classes/Kernel.html
|
32
|
+
* Windata ZV-Tools: http://www.windata.de/Site/2Produkte2/ZVTools.aspx
|
33
|
+
* The Swift Codes: http://www.theswiftcodes.com/
|
34
|
+
* StarMoney: http://www.starmoney.de/index.php?id=starmoneybusiness_testen
|
35
|
+
* SalesKing: http://salesking.eu
|
36
|
+
|
37
|
+
== Examples
|
38
|
+
|
39
|
+
Here are some examples how to create a DTA- or DTAZV-File. Also check out the spec/dtazv_test.rb to have a running Example of an Export.
|
40
|
+
|
41
|
+
=== DTA
|
20
42
|
|
21
|
-
|
22
|
-
|
23
|
-
#create a new dtaus object
|
43
|
+
# create a new dtaus object
|
24
44
|
dta = KingDta::Dtaus.new('LK')
|
25
45
|
# set sender account
|
26
|
-
dta.account = KingDta::Account.new(
|
46
|
+
dta.account = KingDta::Account.new(:account_number => @kto1.account_number, :bank_number => @kto1.bank_number, :client_name => @kto1.client_name, :bank_name => @kto1.bank_name)
|
27
47
|
# the following should be done in a loop to add multiple bookings
|
28
48
|
# create receiving account
|
29
|
-
rec_acnt = KingDta::Account.new(
|
49
|
+
rec_acnt = KingDta::Account.new(:account_number => @kto1.account_number, :bank_number => @kto1.bank_number, :client_name => @kto1.client_name, :bank_name => @kto1.bank_name)
|
30
50
|
# create booking
|
31
51
|
booking = KingDta::Booking.new(rec_acnt, 100.00 )
|
32
52
|
# set booking text if you want to
|
@@ -38,15 +58,62 @@ This gem saves you all the trouble when generating dtaus-text.
|
|
38
58
|
# create datausstring and do with it whatever fits your workflow
|
39
59
|
my_str = dta.create
|
40
60
|
|
41
|
-
|
61
|
+
=== DTAZV
|
62
|
+
|
63
|
+
@date = Date.today
|
64
|
+
@dudes_dtazv_export = KingDta::Dtazv.new(@date)
|
65
|
+
@dudes_konto = self.dudes_konto
|
66
|
+
@dalai_lamas_account = self.dalai_lamas_account
|
67
|
+
@dudes_dtazv_export.account = KingDta::Account.new(
|
68
|
+
:account_number => @dudes_konto.account_number,
|
69
|
+
:bank_number => @dudes_konto.bank_number,
|
70
|
+
:client_name => @dudes_konto.client_name,
|
71
|
+
:client_number => @dudes_konto.client_number,
|
72
|
+
:bank_street => @dudes_konto.account_street,
|
73
|
+
:bank_city => @dudes_konto.account_city,
|
74
|
+
:bank_zip_code => @dudes_konto.account_zip_code,
|
75
|
+
:bank_name => @dudes_konto.bank_name,
|
76
|
+
:client_street => @dudes_konto.client_street,
|
77
|
+
:client_city => @dudes_konto.client_city,
|
78
|
+
:client_zip_code => @dudes_konto.client_zip_code,
|
79
|
+
:bank_country_code => @dudes_konto.bank_country_code,
|
80
|
+
:client_country_code => @dudes_konto.client_country_code
|
81
|
+
)
|
82
|
+
|
83
|
+
@fidel_castros_booking = KingDta::Booking.new(KingDta::Account.new(
|
84
|
+
:account_number => @dalai_lamas_account.account_number,
|
85
|
+
:bank_number => @dalai_lamas_account.bank_number,
|
86
|
+
:client_name => @dalai_lamas_account.client_name,
|
87
|
+
:client_number => @dalai_lamas_account.bank_name,
|
88
|
+
:bank_street => @dalai_lamas_account.account_street,
|
89
|
+
:bank_city => @dalai_lamas_account.account_city,
|
90
|
+
:bank_zip_code => @dalai_lamas_account.account_zip_code,
|
91
|
+
:bank_name => @dalai_lamas_account.bank_name,
|
92
|
+
:client_street => @dalai_lamas_account.client_street,
|
93
|
+
:client_city => @dalai_lamas_account.client_city,
|
94
|
+
:client_zip_code => @dalai_lamas_account.client_zip_code,
|
95
|
+
:bank_country_code => @dalai_lamas_account.bank_country_code,
|
96
|
+
:client_country_code => @dalai_lamas_account.client_country_code
|
97
|
+
), 220.25)
|
98
|
+
|
99
|
+
@dudes_dtazv_export.add(@fidel_castros_booking)
|
100
|
+
@dudes_dtazv_export.create_file
|
42
101
|
|
102
|
+
# Output is DTAZV0.TXT
|
103
|
+
|
104
|
+
also make sure to read the specs
|
43
105
|
|
44
106
|
== Credits
|
45
107
|
|
46
|
-
|
47
|
-
|
108
|
+
Bugfixes and enhancements by
|
109
|
+
|
110
|
+
* Georg Ledermann - https://github.com/ledermann
|
111
|
+
* Kim Rudolph - https://github.com/krudolph
|
112
|
+
* Thorsten Böttger - https://github.com/alto
|
113
|
+
* Jan Kus - https://github.com/koos
|
114
|
+
|
115
|
+
This gem used https://rubygems.org/gems/DTAUS as a starting point.
|
116
|
+
It was disected, turned into a real class structure, bugs where fixed and
|
48
117
|
of course a full test suite ensures its functionality.
|
49
118
|
|
50
|
-
Copyright (c) 2009-
|
51
|
-
Bugfixes and enhancements by Georg Ledermann
|
52
|
-
released under the MIT license
|
119
|
+
Copyright (c) 2009-2011 Georg Leciejewski (SalesKing), Jan Kus (Railslove), released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,33 +1,13 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
|
5
|
-
desc 'Default: run specs.'
|
6
|
-
task :default => :spec
|
7
|
-
|
8
|
-
spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
2
|
+
require 'rdoc/task'
|
3
|
+
require 'rspec/core/rake_task'
|
9
4
|
|
10
5
|
desc "Run specs"
|
11
|
-
|
12
|
-
t.spec_files = spec_files
|
13
|
-
t.spec_opts = ["-c"]
|
14
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new
|
15
7
|
|
16
|
-
|
17
|
-
Spec::Rake::SpecTask.new(:coverage) do |t|
|
18
|
-
t.spec_files = spec_files
|
19
|
-
t.rcov = true
|
20
|
-
t.rcov_opts = ['--exclude', 'spec,/var/lib/gems']
|
21
|
-
end
|
8
|
+
task :default => :spec
|
22
9
|
|
23
|
-
|
24
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
-
rdoc.rdoc_dir = 'rdoc'
|
26
|
-
rdoc.title = 'dtaus'
|
27
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
28
|
-
rdoc.rdoc_files.include('README')
|
29
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
-
end
|
10
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
31
11
|
|
32
12
|
begin
|
33
13
|
require 'jeweler'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0.pre
|
data/docs/dtazv.pdf
ADDED
Binary file
|
Binary file
|
data/example.output
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
0256P37040044 Commerzbank Köln 5th avenue 55323 los angeles1106080100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
2
|
+
|
3
|
+
0256Q370400447828970037 GIMME YOUR MONEY AG 6th avenue 445555 los angeles11060801110608N000000000000000000000000000000000000000000000000000000000000000000000000000000
|
4
|
+
|
5
|
+
0572T37040044EUR782897003711060837040044EUR0037040044 MARKF1100 FIDEL CASTRO 0 GR1601101250000000012300695EUR00000000000220025 0 0 0 0 00013 0 00000000000000000000000000000000000000000000000000000 00
|
6
|
+
|
7
|
+
256Y000000000000000000000000000000000000000000000000000000000000000000000001 0
|
data/king_dtaus.gemspec
CHANGED
@@ -5,53 +5,73 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{king_dtaus}
|
8
|
-
s.version = "
|
8
|
+
s.version = "2.0.0.pre"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Georg Leciejewski", "Georg Ledermann"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-15}
|
13
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
14
|
s.email = %q{gl@salesking.eu}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
+
".rvmrc",
|
20
|
+
"DTAUS0.TXT",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
19
23
|
"MIT-LICENSE",
|
20
24
|
"README.rdoc",
|
21
25
|
"Rakefile",
|
22
26
|
"VERSION",
|
27
|
+
"docs/dtazv.pdf",
|
28
|
+
"docs/dtazv_bank_bbk.pdf",
|
29
|
+
"example.output",
|
23
30
|
"king_dtaus.gemspec",
|
24
31
|
"lib/king_dta/account.rb",
|
25
32
|
"lib/king_dta/booking.rb",
|
33
|
+
"lib/king_dta/dta.rb",
|
26
34
|
"lib/king_dta/dtaus.rb",
|
35
|
+
"lib/king_dta/dtazv.rb",
|
27
36
|
"lib/king_dta/exception.rb",
|
28
37
|
"lib/king_dta/helper.rb",
|
29
38
|
"lib/king_dtaus.rb",
|
30
39
|
"spec/account_spec.rb",
|
31
40
|
"spec/booking_spec.rb",
|
32
41
|
"spec/dtaus_spec.rb",
|
42
|
+
"spec/dtazv_spec.rb",
|
43
|
+
"spec/dtazv_test.rb",
|
33
44
|
"spec/helper_spec.rb",
|
34
45
|
"spec/spec_helper.rb"
|
35
46
|
]
|
36
47
|
s.homepage = %q{http://github.com/salesking/king_dtaus}
|
37
48
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.
|
49
|
+
s.rubygems_version = %q{1.3.7}
|
39
50
|
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
51
|
|
48
52
|
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
54
|
s.specification_version = 3
|
50
55
|
|
51
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<king_dtaus>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
52
62
|
else
|
63
|
+
s.add_dependency(%q<king_dtaus>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
53
68
|
end
|
54
69
|
else
|
70
|
+
s.add_dependency(%q<king_dtaus>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
72
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
73
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
74
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
data/lib/king_dta/account.rb
CHANGED
@@ -4,21 +4,54 @@ module KingDta
|
|
4
4
|
class Account
|
5
5
|
include KingDta::Helper
|
6
6
|
# dta~ jeweilige Feld in DTAUS-Norm
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
attr_accessor :account_number, :bank_number, :client_number, :bank_street, :bank_city, :bank_zip_code, :bank_name,
|
8
|
+
:client_name, :client_street, :client_city, :client_zip_code, :bank_country_code, :client_country_code
|
9
|
+
|
10
|
+
# TODO test
|
11
|
+
def initialize(args={})
|
12
|
+
|
13
|
+
@bank_street = convert_text(args.delete(:bank_street))
|
14
|
+
@bank_city = convert_text(args.delete(:bank_city))
|
15
|
+
@bank_name = convert_text(args.delete(:bank_name))
|
16
|
+
@client_name = convert_text(args.delete(:client_name))
|
17
|
+
@client_street = convert_text(args.delete(:client_street))
|
18
|
+
@client_city = convert_text(args.delete(:client_city))
|
19
|
+
|
20
|
+
args.each do |key,value|
|
21
|
+
self.send("#{key}=",value)
|
22
|
+
end
|
23
|
+
|
24
|
+
raise ArgumentError.new('Account number too long, max 35 allowed') if @account_number && "#{@account_number}".length > 35
|
25
|
+
raise ArgumentError.new('Bank number too long, max 11 allowed') if @bank_number && "#{@bank_number}".length > 11
|
26
|
+
raise ArgumentError.new('Client number too long, max 10 allowed') if @client_number && "#{@client_number}".length > 10
|
27
|
+
raise ArgumentError.new("Bank account number cannot be 0") if @account_number && @account_number == 0
|
28
|
+
raise ArgumentError.new("Bank number cannot be 0") if @bank_number && @bank_number == 0
|
29
|
+
raise ArgumentError.new("Street and/or Zip Code too long, max 35 allowed") if @bank_street && @bank_zip_code && "#{@bank_street} #{@bank_zip_code}".length > 35
|
30
|
+
raise ArgumentError.new("City too long, max 35 allowed") if @bank_city && @bank_city.length > 35
|
31
|
+
raise ArgumentError.new("Bank Name too long, max 35 allowed") if @bank_name && @bank_name.length > 35
|
32
|
+
raise ArgumentError.new("Client Street and/or Zip Code too long, max 35 allowed") if @client_street && @client_zip_code && "#{@client_street} #{@client_zip_code}".length > 35
|
33
|
+
raise ArgumentError.new("Client City too long, max 35 allowed") if @client_city && @client_city.length > 35
|
34
|
+
raise ArgumentError.new("Bank Country code too long, max 2 allowed") if @bank_country_code && @bank_country_code.length > 2
|
35
|
+
raise ArgumentError.new("Client Country code too long, max 2 allowed") if @client_country_code && @client_country_code.length > 2
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO test
|
40
|
+
def client_firstname
|
41
|
+
@client_name.split(' ')[0]
|
21
42
|
end
|
22
|
-
|
43
|
+
|
44
|
+
def client_surname
|
45
|
+
@client_name.split(' ')[1]
|
46
|
+
end
|
47
|
+
|
48
|
+
def zip_city
|
49
|
+
"#{@bank_zip_code} #{@bank_city}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def client_zip_city
|
53
|
+
"#{@client_zip_code} #{@client_city}"
|
54
|
+
end
|
55
|
+
|
23
56
|
end
|
24
57
|
end
|
data/lib/king_dta/booking.rb
CHANGED
@@ -8,17 +8,17 @@ module KingDta
|
|
8
8
|
LASTSCHRIFT_EINZUGSERMAECHTIGUNG = '05000'
|
9
9
|
UEBERWEISUNG_GUTSCHRIFT = '51000'
|
10
10
|
|
11
|
-
|
11
|
+
attr_accessor :value, :account, :text, :account_key
|
12
12
|
#Eine Buchung ist definiert durch:
|
13
13
|
#- Konto (siehe Klasse Konto
|
14
14
|
#- Betrag
|
15
15
|
# Der Betrag kann , oder . als Dezimaltrenner enthalten.
|
16
16
|
#- optional Buchungstext
|
17
|
-
def initialize( account, value, text=nil,
|
17
|
+
def initialize( account, value, text=nil, account_key=nil )
|
18
18
|
raise Exception.new("Hey, a booking should have an Account") unless account.kind_of?( Account )
|
19
19
|
@account = account
|
20
20
|
@text = text ? convert_text( text ) : text
|
21
|
-
@
|
21
|
+
@account_key = account_key
|
22
22
|
if value.is_a?(String)
|
23
23
|
value = BigDecimal.new value.sub(',', '.')
|
24
24
|
elsif value.is_a?(Numeric)
|
@@ -37,7 +37,7 @@ module KingDta
|
|
37
37
|
@pos = false
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def text=(text)
|
42
42
|
@text = convert_text( text )
|
43
43
|
end
|
data/lib/king_dta/dta.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module KingDta
|
3
|
+
class Dta
|
4
|
+
include KingDta::Helper
|
5
|
+
attr_reader :default_text
|
6
|
+
|
7
|
+
# Set the sending account(you own)
|
8
|
+
# === Parameter
|
9
|
+
# account<Account>:: the sending account, must be an instance of class
|
10
|
+
# KingDta::Account
|
11
|
+
def account=( account )
|
12
|
+
raise Exception.new("Come on, i need an Account object") unless account.kind_of?( Account )
|
13
|
+
@account = account
|
14
|
+
end
|
15
|
+
|
16
|
+
# The dtaus format as string. All data is appended to it during creation
|
17
|
+
def dta_string
|
18
|
+
@dta_string ||= ''
|
19
|
+
end
|
20
|
+
# Array of bookings
|
21
|
+
def bookings
|
22
|
+
@bookings ||= []
|
23
|
+
end
|
24
|
+
# default text used on all bookings with emtpy text
|
25
|
+
def default_text=(text='')
|
26
|
+
@default_text = convert_text( text )
|
27
|
+
end
|
28
|
+
|
29
|
+
# Add a booking. The prefix (pos/neg) is beeing checked if it is identical
|
30
|
+
# with the last one
|
31
|
+
# === Parameter
|
32
|
+
# booking<Booking>:: KingDta::Booking object
|
33
|
+
# === Raises
|
34
|
+
# error if the prefix within the bookings has changed
|
35
|
+
def add ( booking )
|
36
|
+
raise Exception.new("The file has alreay been closed, cannot add new booking") if @closed
|
37
|
+
#the first booking decides wether all values are po or negative
|
38
|
+
@value_pos = booking.pos? if bookings.empty?
|
39
|
+
raise Exception.new("The prefix within bookings changed from #{@value_pos} to #{booking.pos?}") if @value_pos != booking.pos?
|
40
|
+
bookings << booking
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create a DTA-File, from current dta information
|
44
|
+
# === Parameter
|
45
|
+
# filename<String>:: defaults to dta.txt
|
46
|
+
def create_file(filename ='dta.txt')
|
47
|
+
file = open( filename, 'w')
|
48
|
+
file << create
|
49
|
+
file.close()
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/king_dta/dtaus.rb
CHANGED
@@ -5,9 +5,8 @@
|
|
5
5
|
#Infos zu DTAUS: http://www.infodrom.org/projects/dtaus/dtaus.php3
|
6
6
|
|
7
7
|
module KingDta
|
8
|
-
class Dtaus
|
9
|
-
|
10
|
-
attr_reader :sum_bank_account_numbers, :sum_bank_numbers, :sum_values, :default_text
|
8
|
+
class Dtaus < KingDta::Dta
|
9
|
+
attr_reader :sum_bank_account_numbers, :sum_bank_numbers, :sum_values
|
11
10
|
|
12
11
|
# Create a new dtaus file/string.
|
13
12
|
# === Parameter
|
@@ -23,42 +22,6 @@ module KingDta
|
|
23
22
|
@default_text = '' # default verwendungzweck
|
24
23
|
end
|
25
24
|
|
26
|
-
# Set the sending account(you own)
|
27
|
-
# === Parameter
|
28
|
-
# account<Account>:: the sending account, must be an instance of class
|
29
|
-
# KingDta::Account
|
30
|
-
def account=( account )
|
31
|
-
raise Exception.new("Come on, i need an Account object") unless account.kind_of?( Account )
|
32
|
-
@account = account
|
33
|
-
end
|
34
|
-
|
35
|
-
# The dtaus format as string. All data is appended to it during creation
|
36
|
-
def dta_string
|
37
|
-
@dta_string ||= ''
|
38
|
-
end
|
39
|
-
# Array of bookings
|
40
|
-
def bookings
|
41
|
-
@bookings ||= []
|
42
|
-
end
|
43
|
-
# default text used on all bookings with emtpy text
|
44
|
-
def default_text=(text='')
|
45
|
-
@default_text = convert_text( text )
|
46
|
-
end
|
47
|
-
|
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
|
54
|
-
def add ( booking )
|
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?
|
59
|
-
bookings << booking
|
60
|
-
end
|
61
|
-
|
62
25
|
# Creates the whole dta string(in the right order) and returns it
|
63
26
|
# === Raises
|
64
27
|
# error if there are no bookings
|
@@ -74,26 +37,16 @@ module KingDta
|
|
74
37
|
dta_string
|
75
38
|
end
|
76
39
|
|
40
|
+
# TODO do it works? the .to_i stuff
|
77
41
|
def set_checksums
|
78
42
|
@sum_bank_account_numbers, @sum_bank_numbers, @sum_values = 0,0,0
|
79
43
|
bookings.each do |b|
|
80
|
-
@sum_bank_account_numbers += b.account.
|
81
|
-
@sum_bank_numbers += b.account.bank_number
|
44
|
+
@sum_bank_account_numbers += b.account.account_number.to_i
|
45
|
+
@sum_bank_numbers += b.account.bank_number.to_i
|
82
46
|
@sum_values += b.value
|
83
47
|
end
|
84
48
|
end
|
85
49
|
|
86
|
-
# Create a DTA-File, from current dta information
|
87
|
-
# === Parameter
|
88
|
-
# filename<String>:: defaults to DTAUS0.TXT
|
89
|
-
def create_file(filename ='DTAUS0.TXT')
|
90
|
-
file = open( filename, 'w')
|
91
|
-
file << create
|
92
|
-
file.close()
|
93
|
-
print "#{filename} created containing #{@bookings.size} bookings\n"
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
50
|
#Erstellen A-Segment der DTAUS-Datei
|
98
51
|
#Aufbau des Segments:
|
99
52
|
# Nr. Start Länge Beschreibung
|
@@ -124,10 +77,10 @@ module KingDta
|
|
124
77
|
data += @typ #Lastschriften Kunde
|
125
78
|
data += '%8i' % @account.bank_number #.rjust(8) #bank_number
|
126
79
|
data += '%08i' % 0 #belegt, wenn Bank
|
127
|
-
data += '%-27.27s' % @account.
|
80
|
+
data += '%-27.27s' % @account.client_name
|
128
81
|
data += @date.strftime("%d%m%y") #aktuelles Datum im Format DDMMJJ
|
129
82
|
data += ' ' * 4 #bankinternes Feld
|
130
|
-
data += '%010i' % @account.
|
83
|
+
data += '%010i' % @account.account_number
|
131
84
|
data += '%010i' % 0 #Referenznummer
|
132
85
|
data += ' ' * 15 #Reserve
|
133
86
|
data += '%8s' % @date.strftime("%d%m%Y") #Ausführungsdatum (ja hier 8 Stellen, Erzeugungsdat. hat 6 Stellen)
|
@@ -195,11 +148,9 @@ module KingDta
|
|
195
148
|
# <String>:: The current dta_string
|
196
149
|
def add_c( booking )
|
197
150
|
zahlungsart = if @typ == 'LK'
|
198
|
-
booking.
|
151
|
+
booking.account_key || Booking::LASTSCHRIFT_EINZUGSERMAECHTIGUNG
|
199
152
|
elsif @typ == 'GK'
|
200
|
-
booking.
|
201
|
-
else
|
202
|
-
raise 'Wrong booking type'
|
153
|
+
booking.account_key || Booking::UEBERWEISUNG_GUTSCHRIFT
|
203
154
|
end
|
204
155
|
#Extended segments Long name & booking texts
|
205
156
|
exts = [] #('xx', 'inhalt') xx: 01=Name 02=Verwendung 03=Name
|
@@ -208,22 +159,25 @@ module KingDta
|
|
208
159
|
data1 = 'C'
|
209
160
|
data1 += '%08i' % 0 #freigestellt
|
210
161
|
data1 += '%08i' % booking.account.bank_number
|
211
|
-
data1 += '%010i' % booking.account.
|
212
|
-
|
162
|
+
data1 += '%010i' % booking.account.account_number
|
163
|
+
# RUBY 1.9 workaround => || 0
|
164
|
+
# Ruby 1.9 '0%011i0' % nil => Exception
|
165
|
+
# Ruby 1.8 '0%011i0' % nil => "00000000000"
|
166
|
+
data1 += '0%011i0' % (booking.account.client_number || 0) #interne Kundennummer
|
213
167
|
data1 += zahlungsart
|
214
168
|
data1 += ' ' #bankintern
|
215
169
|
data1 += '0' * 11 #Reserve
|
216
170
|
data1 += '%08i' % @account.bank_number
|
217
|
-
data1 += '%010i' % @account.
|
171
|
+
data1 += '%010i' % @account.account_number
|
218
172
|
data1 += '%011i' % booking.value #Betrag in Euro einschl. Nachkomma
|
219
173
|
data1 += ' ' * 3
|
220
|
-
data1 += '%-27.27s' % booking.account.
|
221
|
-
exts << ['01', booking.account.
|
174
|
+
data1 += '%-27.27s' % booking.account.client_name #Name Begünstigter/Zahlungspflichtiger
|
175
|
+
exts << ['01', booking.account.client_name[27..999] ] if booking.account.client_name.size > 27
|
222
176
|
data1 += ' ' * 8
|
223
177
|
#Einfügen erst möglich, wenn Satzlänge bekannt
|
224
178
|
|
225
179
|
# 2. Satzabschnitt
|
226
|
-
data2 = "%27.27s" % @account.
|
180
|
+
data2 = "%27.27s" % @account.client_name
|
227
181
|
zweck = booking.text || default_text
|
228
182
|
#Erste 27 Zeichen
|
229
183
|
#Wenn text < 26 Zeichen, dann mit spaces auffüllen.
|
@@ -234,13 +188,13 @@ module KingDta
|
|
234
188
|
exts << ['02', zweck.ljust(27) ]
|
235
189
|
zweck = zweck[27..999]
|
236
190
|
end
|
237
|
-
exts << ['03', @account.
|
191
|
+
exts << ['03', @account.client_name[27..999] ] if @account.client_name.size > 27
|
238
192
|
|
239
193
|
data2 += '1' #Währungskennzeichen
|
240
194
|
data2 += ' ' * 2
|
241
195
|
# Gesamte Satzlänge ermitteln ( data1(+4) + data2 + Erweiterungen )
|
242
196
|
data1 = "%04i#{data1}" % ( data1.size + 4 + data2.size+ 2 + exts.size * 29 )
|
243
|
-
raise "DTAUS: Längenfehler C/1 #{data1.size} nicht 128, #{booking.account.
|
197
|
+
raise "DTAUS: Längenfehler C/1 #{data1.size} nicht 128, #{booking.account.client_name}" unless data1.size == 128
|
244
198
|
dta_string << data1
|
245
199
|
#Anzahl Erweiterungen anfügen
|
246
200
|
data2 += '%02i' % exts.size #Anzahl Erweiterungsteile
|
@@ -251,7 +205,7 @@ module KingDta
|
|
251
205
|
exts[0..1].each{|e| data2 += "%2.2s%-27.27s" % format_ext(e[0], e[1]) }
|
252
206
|
data2 += ' ' * 11
|
253
207
|
# add the final piece of the second C section
|
254
|
-
raise "DTAUS: Längenfehler C/2 #{data2.size} nicht 128, #{booking.account.
|
208
|
+
raise "DTAUS: Längenfehler C/2 #{data2.size} nicht 128, #{booking.account.client_name}" unless data2.size == 128
|
255
209
|
dta_string << data2
|
256
210
|
#Erstellen der Texterweiterungen à vier Stück
|
257
211
|
add_ext( exts[2..5] )
|
@@ -313,6 +267,6 @@ module KingDta
|
|
313
267
|
raise "DTAUS: Längenfehler E #{str.size} <> 128" if str.size != 128
|
314
268
|
dta_string << str
|
315
269
|
end
|
316
|
-
|
270
|
+
|
317
271
|
end #class dtaus
|
318
272
|
end
|