datev 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datev/base.rb +17 -6
- data/lib/datev/booking.rb +14 -2
- data/lib/datev/export.rb +3 -18
- data/lib/datev/field.rb +7 -3
- data/lib/datev/header.rb +18 -0
- data/lib/datev/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f9e40ec72d19dbed69b6822ea7620bd8492d777
|
4
|
+
data.tar.gz: b7918aecf4f2f6f663cf6f6e1e253665a8ecd61e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2946308d40559ff1797aa4e6cc0577cabdd01db663aa1c01092432c58b5a2cbc53335b4917ef4cc1ab1b617ab379d747e8e0aa27582ee09c878c39cc585e32c5
|
7
|
+
data.tar.gz: d6f547b2106860631de50cb5612c94e999b6e6eafc52234713de68938ceaf05c1080e120a19481c1821a210a7fd3da8dce0905374837a4a6cbe8fbbffa595d3a
|
data/lib/datev/base.rb
CHANGED
@@ -8,15 +8,19 @@ module Datev
|
|
8
8
|
|
9
9
|
attr_accessor :attributes
|
10
10
|
|
11
|
-
def self.field(name, type, options={})
|
11
|
+
def self.field(name, type, options={}, &block)
|
12
12
|
self.fields ||= []
|
13
13
|
|
14
14
|
# Check if there is already a field with the same name
|
15
|
-
if
|
15
|
+
if field_by_name(name)
|
16
16
|
raise ArgumentError.new("Field '#{name}' already exists")
|
17
17
|
end
|
18
18
|
|
19
|
-
self.fields << Field.new(name, type, options)
|
19
|
+
self.fields << Field.new(name, type, options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.field_by_name(name)
|
23
|
+
self.fields.find { |f| f.name == name }
|
20
24
|
end
|
21
25
|
|
22
26
|
def initialize(attributes)
|
@@ -26,7 +30,7 @@ module Datev
|
|
26
30
|
|
27
31
|
# Check existing names and set value (if valid)
|
28
32
|
attributes.each_pair do |name,value|
|
29
|
-
unless field = self.class.
|
33
|
+
unless field = self.class.field_by_name(name)
|
30
34
|
raise ArgumentError.new("Field '#{name}' not found")
|
31
35
|
end
|
32
36
|
|
@@ -42,10 +46,17 @@ module Datev
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
|
-
def
|
49
|
+
def [](name)
|
50
|
+
field = self.class.field_by_name(name)
|
51
|
+
raise ArgumentError.new("Field '#{name}' not found") unless field
|
52
|
+
|
53
|
+
attributes[field.name]
|
54
|
+
end
|
55
|
+
|
56
|
+
def output(context=nil)
|
46
57
|
self.class.fields.map do |field|
|
47
58
|
value = attributes[field.name]
|
48
|
-
field.output(value)
|
59
|
+
field.output(value, context)
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
data/lib/datev/booking.rb
CHANGED
@@ -37,17 +37,29 @@ module Datev
|
|
37
37
|
# ISO-Code beachten (siehe Dok.-Nr.1080170)
|
38
38
|
|
39
39
|
# 7
|
40
|
-
field 'Konto', :integer, :limit => 9, :required => true
|
40
|
+
field 'Konto', :integer, :limit => 9, :required => true do
|
41
41
|
# Sach- oder Personen-Kontonummer
|
42
42
|
# Darf max. 8- bzw. max. 9-stellig sein (abhängig von der Information im Header)
|
43
43
|
# Die Personenkontenlänge darf nur 1 Stelle länger sein als die definierte Sachkontennummernlänge.
|
44
44
|
|
45
|
+
def output(value, context)
|
46
|
+
length = context['Sachkontenlänge']
|
47
|
+
value.to_s.rjust(length, '0')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
45
51
|
# 8
|
46
|
-
field 'Gegenkonto (ohne BU-Schlüssel)', :integer, :limit => 9, :required => true
|
52
|
+
field 'Gegenkonto (ohne BU-Schlüssel)', :integer, :limit => 9, :required => true do
|
47
53
|
# Sach- oder Personen-Kontonummer
|
48
54
|
# Darf max. 8- bzw. max. 9-stellig sein (abhängig von der Information im Header)
|
49
55
|
# Die Personenkontenlänge darf nur 1 Stelle länger sein als die definierte Sachkontennummernlänge.
|
50
56
|
|
57
|
+
def output(value, context)
|
58
|
+
length = context['Sachkontenlänge']
|
59
|
+
value.to_s.rjust(length, '0')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
51
63
|
# 9
|
52
64
|
field 'BU-Schlüssel', :string, :limit => 2
|
53
65
|
# Steuerschlüssel und/oder Berichtigungsschlüssel
|
data/lib/datev/export.rb
CHANGED
@@ -6,23 +6,8 @@ module Datev
|
|
6
6
|
class Export
|
7
7
|
CSV_OPTIONS = { :col_sep => ';', :encoding => 'windows-1252' }
|
8
8
|
|
9
|
-
DEFAULT_HEADER_ATTRIBUTES = {
|
10
|
-
'DATEV-Format-KZ' => 'EXTF',
|
11
|
-
'Versionsnummer' => 510,
|
12
|
-
'Datenkategorie' => 21,
|
13
|
-
'Formatname' => 'Buchungsstapel',
|
14
|
-
'Formatversion' => 7,
|
15
|
-
'Erzeugt am' => Time.now.utc,
|
16
|
-
'Sachkontenlänge' => 4,
|
17
|
-
'Bezeichnung' => 'Buchungen',
|
18
|
-
'Buchungstyp' => 1,
|
19
|
-
'WKZ' => 'EUR'
|
20
|
-
}
|
21
|
-
|
22
9
|
def initialize(header_attributes)
|
23
|
-
|
24
|
-
|
25
|
-
@header = Header.new DEFAULT_HEADER_ATTRIBUTES.merge(header_attributes)
|
10
|
+
@header = Header.new header_attributes
|
26
11
|
@rows = []
|
27
12
|
end
|
28
13
|
|
@@ -45,11 +30,11 @@ module Datev
|
|
45
30
|
private
|
46
31
|
|
47
32
|
def write(csv)
|
48
|
-
csv << @header.
|
33
|
+
csv << @header.output
|
49
34
|
csv << Booking.fields.map(&:name)
|
50
35
|
|
51
36
|
@rows.each do |row|
|
52
|
-
csv << row.
|
37
|
+
csv << row.output(@header)
|
53
38
|
end
|
54
39
|
end
|
55
40
|
end
|
data/lib/datev/field.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Datev
|
2
2
|
class Field
|
3
|
-
attr_accessor :name, :type, :options
|
3
|
+
attr_accessor :name, :type, :options, :block
|
4
4
|
|
5
|
-
def initialize(name, type, options={})
|
5
|
+
def initialize(name, type, options={}, &block)
|
6
6
|
unless name.is_a?(String)
|
7
7
|
raise ArgumentError.new('Name param has to be a String')
|
8
8
|
end
|
@@ -22,6 +22,10 @@ module Datev
|
|
22
22
|
self.name = name
|
23
23
|
self.type = type
|
24
24
|
self.options = options
|
25
|
+
|
26
|
+
if block_given?
|
27
|
+
self.instance_eval(&block)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def required?
|
@@ -66,7 +70,7 @@ module Datev
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
def output(value)
|
73
|
+
def output(value, context=nil)
|
70
74
|
return if value.nil?
|
71
75
|
|
72
76
|
case type
|
data/lib/datev/header.rb
CHANGED
@@ -2,6 +2,24 @@ require 'datev/base'
|
|
2
2
|
|
3
3
|
module Datev
|
4
4
|
class Header < Base
|
5
|
+
DEFAULT_ATTRIBUTES = {
|
6
|
+
'DATEV-Format-KZ' => 'EXTF',
|
7
|
+
'Versionsnummer' => 510,
|
8
|
+
'Datenkategorie' => 21,
|
9
|
+
'Formatname' => 'Buchungsstapel',
|
10
|
+
'Formatversion' => 7,
|
11
|
+
'Erzeugt am' => Time.now.utc,
|
12
|
+
'Sachkontenlänge' => 4,
|
13
|
+
'Bezeichnung' => 'Buchungen',
|
14
|
+
'Buchungstyp' => 1,
|
15
|
+
'WKZ' => 'EUR'
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(attributes={})
|
19
|
+
raise ArgumentError.new('Hash required') unless attributes.is_a?(Hash)
|
20
|
+
super DEFAULT_ATTRIBUTES.merge(attributes)
|
21
|
+
end
|
22
|
+
|
5
23
|
# 1
|
6
24
|
field 'DATEV-Format-KZ', :string, :limit => 4
|
7
25
|
# vom Datev angegeben
|
data/lib/datev/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|