king_dtaus 2.0.2.pre → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ nbproject/*
2
+ .rvmrc
3
+ coverage/*
4
+ rdoc/*
5
+ pkg/*
6
+ .DS_Store
7
+ DTAUS0.TXT
8
+ dta.txt
9
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,7 +1,2 @@
1
1
  source :rubygems
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem "rcov"
7
- end
2
+ gemspec
@@ -10,7 +10,7 @@ therefore supported in common banking programs too.
10
10
 
11
11
  This gem saves you all the trouble when generating DTAUS- or DTAZV-text.
12
12
 
13
- We love building payment applications
13
+ We love building payment applications.
14
14
 
15
15
  ## Install
16
16
 
@@ -18,25 +18,38 @@ We love building payment applications
18
18
 
19
19
  ## Features
20
20
 
21
- * Create DTAUS debit advice (Lastschrift)
22
- * Create DTAUS credit advice (Gutschrift)
23
- * Create DTAZV debit advice
24
- * High test coverage to ensure software quality
21
+ * Create DTAUS debit transfer (Lastschrift)
22
+ * Create DTAUS credit transfer (Gutschrift)
23
+ * Create DTAZV debit transfer
24
+ * 100% test coverage to ensure software quality
25
+ * works with ruby 1.8 & 1.9.2
26
+
27
+ ## Version Info
28
+
29
+ Version 2 has breaking changes!
30
+
31
+ * account attributes now passed in as hash
32
+ * renamed account.client_xy => owner_xy
33
+ * renamed account.account_number => bank_account_number
34
+ * added iban/bic to account
35
+ * DTAZV added
36
+
37
+ If you want to stay with v1 just pin it in your Gemfile:
38
+
39
+ gem "king_dtaus", "<2"
25
40
 
26
41
  ## TODOs
27
42
 
28
- * first gem with no todo's - never seen it, huh? - just kidding
29
- * some more edge-case tests needed
43
+ * some more edge-case tests needed, we need your feedback here!
30
44
 
31
45
  ## Resources
32
46
 
47
+ * SalesKing: http://salesking.eu
33
48
  * DTAZV-Viewer: http://www.meta-evolutions.de/pages/artikel-20070630-dtazv-datei-betrachter.html
34
49
  * DTA/DTAZV PHP Pear: http://pear.php.net/package/Payment_DTA
35
- * Ruby Kernel Module: http://www.ruby-doc.org/core/classes/Kernel.html
36
50
  * Windata ZV-Tools: http://www.windata.de/Site/2Produkte2/ZVTools.aspx
37
51
  * The Swift Codes: http://www.theswiftcodes.com/
38
52
  * StarMoney: http://www.starmoney.de/index.php?id=starmoneybusiness_testen
39
- * SalesKing: http://salesking.eu
40
53
 
41
54
  ## Examples
42
55
 
@@ -48,14 +61,21 @@ Here are some examples how to create a DTA- or DTAZV-File. Also check out the sp
48
61
  dta = KingDta::Dtaus.new('LK')
49
62
 
50
63
  # set sender account
51
- 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)
64
+ dta.account = KingDta::Account.new(
65
+ :bank_account_number => "123456789",
66
+ :bank_number => "69069096",
67
+ :owner_name => "Return to Sender",
68
+ :bank_name => "Money Burner Bank")
52
69
 
53
- # the following should be done in a loop to add multiple bookings
70
+ # following should be done in a loop to add multiple bookings
54
71
  # create receiving account
55
- 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)
56
-
72
+ receiver = KingDta::Account.new(
73
+ :bank_account_number => "987456123",
74
+ :bank_number => "99099096",
75
+ :owner_name => "Gimme More Lt.",
76
+ :bank_name => "Banking Bandits")
57
77
  # create booking
58
- booking = KingDta::Booking.new(rec_acnt, 100.00 )
78
+ booking = KingDta::Booking.new(receiver, 100.00 )
59
79
 
60
80
  # set booking text if you want to
61
81
  booking.text = "Thanks for your purchase"
@@ -69,48 +89,31 @@ Here are some examples how to create a DTA- or DTAZV-File. Also check out the sp
69
89
 
70
90
  ### DTAZV
71
91
 
72
- @date = Date.today
73
- @dudes_dtazv_export = KingDta::Dtazv.new(@date)
74
- @dudes_konto = self.dudes_konto
75
- @dalai_lamas_account = self.dalai_lamas_account
76
- @dudes_dtazv_export.account = KingDta::Account.new(
77
- :account_number => @dudes_konto.account_number,
78
- :bank_number => @dudes_konto.bank_number,
79
- :client_name => @dudes_konto.client_name,
80
- :client_number => @dudes_konto.client_number,
81
- :bank_street => @dudes_konto.account_street,
82
- :bank_city => @dudes_konto.account_city,
83
- :bank_zip_code => @dudes_konto.account_zip_code,
84
- :bank_name => @dudes_konto.bank_name,
85
- :client_street => @dudes_konto.client_street,
86
- :client_city => @dudes_konto.client_city,
87
- :client_zip_code => @dudes_konto.client_zip_code,
88
- :bank_country_code => @dudes_konto.bank_country_code,
89
- :client_country_code => @dudes_konto.client_country_code
92
+ @dtazv = KingDta::Dtazv.new()
93
+
94
+ # sender account
95
+ @dtazv.account = KingDta::Account.new(
96
+ :bank_account_number => "123456789",
97
+ :bank_number => "40050100",
98
+ :bank_name => "Greedy Fuckers Bank",
99
+ :owner_name => "Sender name"
100
+ )
101
+
102
+ # receiver account
103
+ receiver = KingDta::Account.new(
104
+ :bank_account_number => "987654321",
105
+ :bank_iban => "PLsome-long-Iban",
106
+ :bank_bic => "BicCode",
107
+ :owner_name => "receivers name"
90
108
  )
109
+ # add bookings, probably in a loop
110
+ booking = KingDta::Booking.new(receiver, 220.25)
111
+ @dtazv.add(booking)
112
+
113
+ # get output as string
114
+ @dtazv.create
91
115
 
92
- @dalai_lamas_booking = KingDta::Booking.new(KingDta::Account.new(
93
- :account_number => @dalai_lamas_account.account_number,
94
- :bank_number => @dalai_lamas_account.bank_number,
95
- :client_name => @dalai_lamas_account.client_name,
96
- :client_number => @dalai_lamas_account.bank_name,
97
- :bank_street => @dalai_lamas_account.account_street,
98
- :bank_city => @dalai_lamas_account.account_city,
99
- :bank_zip_code => @dalai_lamas_account.account_zip_code,
100
- :bank_name => @dalai_lamas_account.bank_name,
101
- :client_street => @dalai_lamas_account.client_street,
102
- :client_city => @dalai_lamas_account.client_city,
103
- :client_zip_code => @dalai_lamas_account.client_zip_code,
104
- :bank_country_code => @dalai_lamas_account.bank_country_code,
105
- :client_country_code => @dalai_lamas_account.client_country_code
106
- ), 220.25)
107
-
108
- @dudes_dtazv_export.add(@dalai_lamas_booking)
109
- @dudes_dtazv_export.create_file
110
-
111
- # Output is DTAZV0.TXT
112
-
113
- also make sure to read the specs
116
+ also make sure to read the code and the specs
114
117
 
115
118
  ## Credits
116
119
 
@@ -120,9 +123,6 @@ Bugfixes and enhancements by
120
123
  * Kim Rudolph - https://github.com/krudolph
121
124
  * Thorsten Böttger - https://github.com/alto
122
125
  * Jan Kus - https://github.com/koos
126
+ * used https://rubygems.org/gems/DTAUS as a starting point
123
127
 
124
- This gem used https://rubygems.org/gems/DTAUS as a starting point.
125
- It was disected, turned into a real class structure, bugs were fixed and
126
- of course a full test suite ensures its functionality.
127
-
128
- Copyright (c) 2009-2011 Georg Leciejewski (SalesKing), Jan Kus (Railslove), released under the MIT license
128
+ Copyright (c) 2009-2011 Georg Leciejewski (SalesKing), Jan Kus (Railslove), released under the MIT license
data/Rakefile CHANGED
@@ -1,31 +1,18 @@
1
1
  require 'rake'
2
+ require 'rspec'
2
3
  require 'rspec/core/rake_task'
3
-
4
+ require 'rdoc/task'
5
+ require 'bundler/gem_helper'
6
+ Bundler::GemHelper.install_tasks
4
7
  desc "Run specs"
5
8
  RSpec::Core::RakeTask.new
6
-
7
9
  task :default => :spec
8
10
 
9
- RSpec::Core::RakeTask.new(:coverage) do |t|
10
- t.rcov = true
11
- t.rcov_opts = %q[--exclude "spec"]
12
- t.verbose = true
13
- end
14
-
15
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
16
-
17
- begin
18
- require 'jeweler'
19
- Jeweler::Tasks.new do |gem|
20
- gem.name = "king_dtaus"
21
- gem.summary = %Q{Generate DTAUS strings and files}
22
- gem.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.}
23
- gem.email = "gl@salesking.eu"
24
- gem.homepage = "http://github.com/salesking/king_dtaus"
25
- gem.authors = ["Georg Leciejewski", "Georg Ledermann", "Jan Kus"]
26
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
27
- end
28
- Jeweler::GemcutterTasks.new
29
- rescue LoadError
30
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
11
+ desc 'Generate documentation'
12
+ Rake::RDocTask.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'docs/rdoc'
14
+ rdoc.title = 'KingPdf'
15
+ rdoc.options << '--line-numbers' << '--inline-source'
16
+ rdoc.rdoc_files.include('README')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
18
  end
@@ -1,77 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'king_dta/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{king_dtaus}
8
- s.version = "2.0.2.pre"
7
+ s.version = KingDta::VERSION
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Georg Leciejewski", "Georg Ledermann", "Jan Kus"]
12
- s.date = %q{2011-09-02}
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.}
9
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
+ s.authors = ['Georg Leciejewski', 'Georg Ledermann', 'Jan Kus']
11
+ s.date = %q{2011-11-15}
12
+ s.summary = %q{Generate DTA/DTAUS and DTAZV bank transfer files .. the easy way}
13
+ s.description = %q{DTA/DTAUS and DTAZV are text-based formats to create bank transfers for german banks.
14
+ This gem creates DTA/DATAUS files for inner german credit and debit(Gutschrift/Lastschrift) transfers.
15
+ It is also capable of creating DTAZV credit-files for transfers from Germany to European SEPA region.}
14
16
  s.email = %q{gl@salesking.eu}
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- ".travis.yml",
20
- "Gemfile",
21
- "MIT-LICENSE",
22
- "README.markdown",
23
- "Rakefile",
24
- "VERSION",
25
- "docs/dtazv.pdf",
26
- "docs/dtazv_bank_bbk.pdf",
27
- "docs/example.output",
28
- "king_dtaus.gemspec",
29
- "lib/king_dta/account.rb",
30
- "lib/king_dta/booking.rb",
31
- "lib/king_dta/dta.rb",
32
- "lib/king_dta/dtaus.rb",
33
- "lib/king_dta/dtazv.rb",
34
- "lib/king_dta/exception.rb",
35
- "lib/king_dta/helper.rb",
36
- "lib/king_dtaus.rb",
37
- "spec/account_spec.rb",
38
- "spec/booking_spec.rb",
39
- "spec/dtaus_spec.rb",
40
- "spec/dtazv_spec.rb",
41
- "spec/dtazv_test.rb",
42
- "spec/helper_spec.rb",
43
- "spec/spec_helper.rb"
44
- ]
17
+ s.extra_rdoc_files = ['README.markdown']
18
+ s.executables = nil
19
+ s.files = `git ls-files`.split("\n").reject{|i| i[/^docs\//] }
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+
45
22
  s.homepage = %q{http://github.com/salesking/king_dtaus}
46
- s.require_paths = ["lib"]
23
+ s.require_paths = ['lib']
47
24
  s.rubygems_version = %q{1.6.2}
48
- s.summary = %q{Generate DTAUS strings and files}
49
25
 
50
- if s.respond_to? :specification_version then
51
- s.specification_version = 3
26
+ s.add_runtime_dependency 'i18n'
27
+ s.add_development_dependency 'rdoc'
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'simplecov'
30
+ s.add_development_dependency 'mocha'
31
+ s.add_development_dependency 'rake', '>= 0.9.2'
52
32
 
53
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<king_dtaus>, [">= 0"])
55
- s.add_development_dependency(%q<rspec>, [">= 0"])
56
- s.add_development_dependency(%q<jeweler>, [">= 0"])
57
- s.add_development_dependency(%q<simplecov>, [">= 0"])
58
- s.add_development_dependency(%q<mocha>, [">= 0"])
59
- s.add_development_dependency(%q<i18n>, [">= 0"])
60
- else
61
- s.add_dependency(%q<king_dtaus>, [">= 0"])
62
- s.add_dependency(%q<rspec>, [">= 0"])
63
- s.add_dependency(%q<jeweler>, [">= 0"])
64
- s.add_dependency(%q<simplecov>, [">= 0"])
65
- s.add_dependency(%q<mocha>, [">= 0"])
66
- s.add_dependency(%q<i18n>, [">= 0"])
67
- end
68
- else
69
- s.add_dependency(%q<king_dtaus>, [">= 0"])
70
- s.add_dependency(%q<rspec>, [">= 0"])
71
- s.add_dependency(%q<jeweler>, [">= 0"])
72
- s.add_dependency(%q<simplecov>, [">= 0"])
73
- s.add_dependency(%q<mocha>, [">= 0"])
74
- s.add_dependency(%q<i18n>, [">= 0"])
75
- end
76
33
  end
77
34
 
@@ -1,50 +1,76 @@
1
1
  # encoding: utf-8
2
2
  module KingDta
3
- # A bank account with name of the account owner,
4
- # Kontodaten verwalten mit Name des Inhabers und Bank, Bankleitzahl und Kontonummer.
3
+ # Bank account and owner information
5
4
  class Account
6
5
  include KingDta::Helper
7
-
8
- attr_accessor :account_number, :bank_number, :bank_street, :bank_city,
9
- :bank_zip_code, :bank_name, :bank_country_code,
10
- :client_name, :client_number, :client_street, :client_city,
11
- :client_zip_code, :client_country_code
12
6
 
13
- # TODO test
7
+ attr_accessor :bank_street, :bank_city,
8
+ :bank_zip, :bank_name, :bank_country_code, :bank_iban,
9
+ :bank_bic,
10
+ :owner_name, :owner_number, :owner_street, :owner_city,
11
+ :owner_zip_code, :owner_country_code
12
+ attr_reader :bank_account_number, :bank_number
13
+
14
14
  def initialize(args={})
15
15
 
16
16
  @bank_street = convert_text(args.delete(:bank_street))
17
17
  @bank_city = convert_text(args.delete(:bank_city))
18
18
  @bank_name = convert_text(args.delete(:bank_name))
19
- @client_name = convert_text(args.delete(:client_name))
20
- @client_street = convert_text(args.delete(:client_street))
21
- @client_city = convert_text(args.delete(:client_city))
19
+ @owner_name = convert_text(args.delete(:owner_name))
20
+ @owner_street = convert_text(args.delete(:owner_street))
21
+ @owner_city = convert_text(args.delete(:owner_city))
22
22
 
23
23
  args.each do |key,value|
24
24
  self.send("#{key}=",value)
25
25
  end
26
26
 
27
- raise ArgumentError.new('Account number too long, max 35 allowed') if @account_number && "#{@account_number}".length > 35
28
- raise ArgumentError.new('Bank number too long, max 11 allowed') if @bank_number && "#{@bank_number}".length > 11
29
- raise ArgumentError.new('Client number too long, max 10 allowed') if @client_number && "#{@client_number}".length > 10
30
- raise ArgumentError.new("Bank account number cannot be 0") if @account_number && @account_number == 0
31
- raise ArgumentError.new("Bank number cannot be 0") if @bank_number && @bank_number == 0
32
- raise ArgumentError.new("Bank Street too long, max 35 allowed") if @bank_street && @bank_street.length > 35
33
- raise ArgumentError.new("Bank City too long, max 35 allowed") if @bank_city && @bank_city.length > 35
34
- raise ArgumentError.new("Bank Name too long, max 35 allowed") if @bank_name && @bank_name.length > 35
35
- raise ArgumentError.new("Client Street too long, max 35 allowed") if @client_street && @client_street.length > 35
36
- raise ArgumentError.new("Client City too long, max 35 allowed") if @client_city && @client_city.length > 35
37
- raise ArgumentError.new("Bank Country code too long, max 2 allowed") if @bank_country_code && @bank_country_code.length > 2
38
- raise ArgumentError.new("Client Country code too long, max 2 allowed") if @client_country_code && @client_country_code.length > 2
27
+ raise ArgumentError.new('Owner number too long, max 10 allowed') if @owner_number && "#{@owner_number}".length > 10
28
+ raise ArgumentError.new('Owner street too long, max 35 allowed') if @owner_street && @owner_street.length > 35
29
+ raise ArgumentError.new('Owner city too long, max 35 allowed') if @owner_city && @owner_city.length > 35
30
+ raise ArgumentError.new('Owner country code too long, max 2 allowed') if @owner_country_code && @owner_country_code.length > 2
31
+
32
+
33
+ raise ArgumentError.new("Bank iban wrong length: #{@bank_iban.length}, must be between 15-34") if @bank_iban && !@bank_iban.length.between?(15,34)
34
+ raise ArgumentError.new("Bank bic wrong length: #{@bank_bic.length} must be between 8-11") if @bank_bic && !@bank_bic.length.between?(8,11)
35
+
36
+ raise ArgumentError.new('Bank street too long, max 35 allowed') if @bank_street && @bank_street.length > 35
37
+ raise ArgumentError.new('Bank city too long, max 35 allowed') if @bank_city && @bank_city.length > 35
38
+ raise ArgumentError.new('Bank name too long, max 35 allowed') if @bank_name && @bank_name.length > 35
39
+ raise ArgumentError.new('Bank country code too long, max 2 allowed') if @bank_country_code && @bank_country_code.length > 2
40
+
41
+ @owner_country_code = @bank_iban[0..1 ] if @bank_iban && !@owner_country_code
42
+ end
43
+
44
+ # Cast given account number to integer. Strips spaces and leading zeros
45
+ # from the bank account number.
46
+ # DTA relies on integers for checksums and field values.
47
+ # @param [String|Integer] number
48
+ def bank_account_number=(number)
49
+ nr_str = "#{number}".gsub(/\s/,'')
50
+ raise ArgumentError.new('Bank account number too long, max 10 allowed') if nr_str.length > 10
51
+ raise ArgumentError.new('Bank account number cannot be 0') if nr_str == '0'
52
+
53
+ @bank_account_number = nr_str.to_i
54
+ end
55
+
56
+ # Cast given bank number to integer. Strips spaces and leading zeros
57
+ # from the bank account number.
58
+ # DTA relies on integers for checksums and field values.
59
+ # @param [String|Integer] number
60
+ def bank_number=(number)
61
+ nr_str = "#{number}".gsub(/\s/,'')
62
+ raise ArgumentError.new('Bank number too long, max 8 allowed') if nr_str.length > 8
63
+ raise ArgumentError.new('Bank number cannot be 0') if nr_str == '0'
39
64
 
65
+ @bank_number = nr_str.to_i
40
66
  end
41
67
 
42
- def zip_city
43
- "#{@bank_zip_code} #{@bank_city}"
68
+ def bank_zip_city
69
+ "#{@bank_zip} #{@bank_city}"
44
70
  end
45
71
 
46
- def client_zip_city
47
- "#{@client_zip_code} #{@client_city}"
72
+ def owner_zip_city
73
+ "#{@owner_zip_code} #{@owner_city}"
48
74
  end
49
75
 
50
76
  end
@@ -4,6 +4,16 @@ module KingDta
4
4
  include KingDta::Helper
5
5
  attr_reader :default_text
6
6
 
7
+ # Create a new dta string.
8
+ # === Parameter #
9
+ # typ<Date>:: date when the the transfer is to be created
10
+ def initialize(date=Date.today )
11
+ raise ArgumentError.new("Wrong date format. Make it a Time or Date object with yyyy-mm-dd") unless date.respond_to?(:strftime)
12
+ @date = date
13
+ @value_pos = true #values are positive by default changed by first booking
14
+ @closed = false
15
+ @default_text = ''
16
+ end
7
17
  # Set the sending account(you own)
8
18
  # === Parameter
9
19
  # account<Account>:: the sending account, must be an instance of class