sie 1.0.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +7 -11
- data/lib/sie/document.rb +84 -83
- data/lib/sie/version.rb +1 -1
- data/spec/unit/document_spec.rb +15 -12
- metadata +3 -6
- data/lib/sie/document/financial_years.rb +0 -34
- data/spec/unit/document/financial_years_spec.rb +0 -48
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmQ2NTU4OGIwMDIxOTQyN2FjNmZjMGY1MWUzYTBjOWY2YWNkODI4Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTIzODUzYWQyN2ZjNTAwNWM0NDg0NTQyZjQ1ZTY2Mjc4YmM1MTYwOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDUyNWIzZWNmZWE3NzA4NDEzYThkODNkNWViZjI2N2M3MjZhZDlkMWI2OTRl
|
10
|
+
OGZlM2I2MzM4YzExODQ5ODg3Y2E0MDQxYTQ0Y2IzNTIyOGEyMmE1YmMxOWM2
|
11
|
+
MDhhNDE1YjAzOGEzNWYyNzc0MmYwMDQ3ZDQ5ODEzYWU3Njk5ZDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmE4N2Q4MzY0YzljYzJkZWZhYjM0OTYyNzVjZWI5OTZiNmVmYWQ2MzY1MDZj
|
14
|
+
YjNiNWJiNjg0Yzg4ZDMzMTQ3NDk2NTlhYjFiYWJkZDIyZTczOTFiNzlhMTY4
|
15
|
+
NDY3OWI0NGRiYjNkZjQwMjg1MmQ5OGFjNGRjMWYzNTVhMjIzM2M=
|
data/README.md
CHANGED
@@ -38,25 +38,21 @@ class YourDataSource
|
|
38
38
|
Date.today
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def financial_years
|
42
|
+
[
|
43
|
+
Date.new(2011, 1, 1)..Date.new(2011, 12, 31),
|
44
|
+
Date.new(2012, 1, 1)..Date.new(2012, 12, 31),
|
45
|
+
Date.new(2013, 1, 1)..Date.new(2013, 12, 31),
|
46
|
+
]
|
47
47
|
end
|
48
48
|
|
49
49
|
def company_name
|
50
50
|
"Your company"
|
51
51
|
end
|
52
52
|
|
53
|
-
def financial_year_start_month
|
54
|
-
1
|
55
|
-
end
|
56
|
-
|
57
53
|
def accounts
|
58
54
|
[
|
59
|
-
{ number: 1500, description: "Customer ledger" }
|
55
|
+
{ number: 1500, description: "Customer ledger" },
|
60
56
|
]
|
61
57
|
end
|
62
58
|
|
data/lib/sie/document.rb
CHANGED
@@ -1,119 +1,120 @@
|
|
1
1
|
require "attr_extras"
|
2
|
-
require "sie/document/financial_years"
|
3
2
|
require "sie/document/voucher_series"
|
4
3
|
require "sie/document/renderer"
|
5
4
|
require "active_support/core_ext/module/delegation"
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
module Sie
|
7
|
+
class Document
|
8
|
+
pattr_initialize :data_source
|
9
|
+
# Because fortnox imposes these limits
|
10
|
+
DESCRIPTION_LENGTH_MAX = 30
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def render
|
13
|
+
add_header
|
14
|
+
add_financial_years
|
15
|
+
add_accounts
|
16
|
+
add_balances
|
17
|
+
add_vouchers
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
renderer.render
|
20
|
+
end
|
21
21
|
|
22
|
-
|
22
|
+
private
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
delegate :program, :program_version, :generated_on, :company_name,
|
25
|
+
:accounts, :balance_account_numbers, :closing_account_numbers,
|
26
|
+
:balance_before, :each_voucher,
|
27
|
+
to: :data_source
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
def add_header
|
30
|
+
add_line("FLAGGA", 0)
|
31
|
+
add_line("PROGRAM", program, program_version)
|
32
|
+
add_line("FORMAT", "PC8")
|
33
|
+
add_line("GEN", generated_on)
|
34
|
+
add_line("SIETYP", 4)
|
35
|
+
add_line("FNAMN", company_name)
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
def add_financial_years
|
39
|
+
financial_years.each_with_index do |date_range, index|
|
40
|
+
add_line("RAR", -index, date_range.begin, date_range.end)
|
41
|
+
end
|
41
42
|
end
|
42
|
-
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def add_accounts
|
45
|
+
accounts.each do |account|
|
46
|
+
number = account.fetch(:number)
|
47
|
+
description = account.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
48
48
|
|
49
|
-
|
49
|
+
add_line("KONTO", number, description)
|
50
|
+
end
|
50
51
|
end
|
51
|
-
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
def add_balances
|
54
|
+
financial_years.each_with_index do |date_range, index|
|
55
|
+
add_balance_rows("IB", -index, balance_account_numbers, date_range.begin)
|
56
|
+
add_balance_rows("UB", -index, balance_account_numbers, date_range.end)
|
57
|
+
add_balance_rows("RES", -index, closing_account_numbers, date_range.end)
|
58
|
+
end
|
58
59
|
end
|
59
|
-
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
def add_balance_rows(label, year_index, account_numbers, date, &block)
|
62
|
+
account_numbers.each do |account_number|
|
63
|
+
balance = balance_before(account_number, date)
|
64
|
+
add_line(label, year_index, account_number, balance)
|
65
|
+
end
|
65
66
|
end
|
66
|
-
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def add_vouchers
|
69
|
+
each_voucher do |voucher|
|
70
|
+
add_voucher(voucher)
|
71
|
+
end
|
71
72
|
end
|
72
|
-
end
|
73
73
|
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
def add_voucher(opts)
|
76
|
+
creditor = opts.fetch(:creditor)
|
77
|
+
type = opts.fetch(:type)
|
78
|
+
number = opts.fetch(:number)
|
79
|
+
booked_on = opts.fetch(:booked_on)
|
80
|
+
description = opts.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
81
|
+
voucher_lines = opts.fetch(:voucher_lines)
|
82
82
|
|
83
|
-
|
83
|
+
add_line("VER", voucher_series(creditor, type), number, booked_on, description)
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
85
|
+
add_array do
|
86
|
+
voucher_lines.each do |line|
|
87
|
+
account_number = line.fetch(:account_number)
|
88
|
+
amount = line.fetch(:amount)
|
89
|
+
booked_on = line.fetch(:booked_on)
|
90
|
+
# Some SIE-importers (fortnox) cannot handle descriptions longer than 30 characters,
|
91
|
+
# but the specification has no limit.
|
92
|
+
description = line.fetch(:description).slice(0, DESCRIPTION_LENGTH_MAX)
|
93
93
|
|
94
|
-
add_line("TRANS", account_number, Renderer::EMPTY_ARRAY, amount, booked_on, description)
|
95
|
-
|
96
|
-
# Some consumers of SIE cannot handle single voucher lines (fortnox), so add another empty one to make
|
97
|
-
# it balance. The spec just requires the sum of lines to be 0, so single lines with zero amount would conform,
|
98
|
-
# but break for these implementations.
|
99
|
-
if voucher_lines.size < 2 && amount.zero?
|
100
94
|
add_line("TRANS", account_number, Renderer::EMPTY_ARRAY, amount, booked_on, description)
|
95
|
+
|
96
|
+
# Some consumers of SIE cannot handle single voucher lines (fortnox), so add another empty one to make
|
97
|
+
# it balance. The spec just requires the sum of lines to be 0, so single lines with zero amount would conform,
|
98
|
+
# but break for these implementations.
|
99
|
+
if voucher_lines.size < 2 && amount.zero?
|
100
|
+
add_line("TRANS", account_number, Renderer::EMPTY_ARRAY, amount, booked_on, description)
|
101
|
+
end
|
101
102
|
end
|
102
103
|
end
|
103
104
|
end
|
104
|
-
end
|
105
105
|
|
106
|
-
|
106
|
+
delegate :add_line, :add_array, to: :renderer
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
def renderer
|
109
|
+
@renderer ||= Renderer.new
|
110
|
+
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
def financial_years
|
113
|
+
data_source.financial_years.sort_by { |date_range| date_range.first }.reverse
|
114
|
+
end
|
115
115
|
|
116
|
-
|
117
|
-
|
116
|
+
def voucher_series(creditor, type)
|
117
|
+
VoucherSeries.for(creditor, type)
|
118
|
+
end
|
118
119
|
end
|
119
120
|
end
|
data/lib/sie/version.rb
CHANGED
data/spec/unit/document_spec.rb
CHANGED
@@ -4,8 +4,13 @@ require "sie"
|
|
4
4
|
require "active_support/core_ext/date/calculations"
|
5
5
|
|
6
6
|
describe Sie::Document, "#render" do
|
7
|
-
let(:
|
8
|
-
|
7
|
+
let(:financial_years) {
|
8
|
+
[
|
9
|
+
Date.new(2011, 1, 1)..Date.new(2011, 12, 31),
|
10
|
+
Date.new(2012, 1, 1)..Date.new(2012, 12, 31),
|
11
|
+
Date.new(2013, 1, 1)..Date.new(2013, 12, 31),
|
12
|
+
]
|
13
|
+
}
|
9
14
|
let(:generated_on) { Date.yesterday }
|
10
15
|
let(:accounts) {
|
11
16
|
[
|
@@ -15,17 +20,17 @@ describe Sie::Document, "#render" do
|
|
15
20
|
let(:vouchers) {
|
16
21
|
[
|
17
22
|
{
|
18
|
-
creditor: false, type: :invoice, number: 1, booked_on:
|
23
|
+
creditor: false, type: :invoice, number: 1, booked_on: Date.new(2011, 9, 3), description: "Invoice 1",
|
19
24
|
voucher_lines: [
|
20
|
-
{ account_number: 1500, amount: 512.0, booked_on:
|
21
|
-
{ account_number: 3100, amount: -512.0, booked_on:
|
25
|
+
{ account_number: 1500, amount: 512.0, booked_on: Date.new(2011, 9, 3), description: "Item 1" },
|
26
|
+
{ account_number: 3100, amount: -512.0, booked_on: Date.new(2011, 9, 3), description: "Item 1" },
|
22
27
|
]
|
23
28
|
},
|
24
29
|
{
|
25
|
-
creditor: true, type: :payment, number: 2, booked_on:
|
30
|
+
creditor: true, type: :payment, number: 2, booked_on: Date.new(2012, 8, 31), description: "Payout 1",
|
26
31
|
voucher_lines: [
|
27
|
-
{ account_number: 2400, amount: 256.0, booked_on:
|
28
|
-
{ account_number: 1970, amount: -256.0, booked_on:
|
32
|
+
{ account_number: 2400, amount: 256.0, booked_on: Date.new(2012, 8, 31), description: "Payout line 1" },
|
33
|
+
{ account_number: 1970, amount: -256.0, booked_on: Date.new(2012, 8, 31), description: "Payout line 2" },
|
29
34
|
]
|
30
35
|
}
|
31
36
|
]
|
@@ -34,7 +39,7 @@ describe Sie::Document, "#render" do
|
|
34
39
|
class TestDataSource
|
35
40
|
attr_accessor :program, :program_version, :generated_on, :company_name,
|
36
41
|
:accounts, :balance_account_numbers, :closing_account_numbers,
|
37
|
-
:vouchers, :
|
42
|
+
:vouchers, :financial_years
|
38
43
|
|
39
44
|
# vouchers is not part of the expected interface so making it private.
|
40
45
|
#
|
@@ -60,15 +65,13 @@ describe Sie::Document, "#render" do
|
|
60
65
|
|
61
66
|
let(:doc) {
|
62
67
|
data_source = TestDataSource.new(
|
63
|
-
from_date: from_date,
|
64
|
-
to_date: to_date,
|
65
68
|
accounts: accounts,
|
66
69
|
vouchers: vouchers,
|
67
70
|
program: "Foonomic",
|
68
71
|
program_version: "3.11",
|
69
72
|
generated_on: generated_on,
|
70
73
|
company_name: "Foocorp",
|
71
|
-
|
74
|
+
financial_years: financial_years,
|
72
75
|
balance_account_numbers: [ 1500, 2400 ],
|
73
76
|
closing_account_numbers: [ 3100 ]
|
74
77
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barsoom AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attr_extras
|
@@ -96,7 +96,6 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- lib/sie.rb
|
98
98
|
- lib/sie/document.rb
|
99
|
-
- lib/sie/document/financial_years.rb
|
100
99
|
- lib/sie/document/renderer.rb
|
101
100
|
- lib/sie/document/voucher_series.rb
|
102
101
|
- lib/sie/parser.rb
|
@@ -116,7 +115,6 @@ files:
|
|
116
115
|
- spec/fixtures/sie_file.se
|
117
116
|
- spec/integration/parser_spec.rb
|
118
117
|
- spec/spec_helper.rb
|
119
|
-
- spec/unit/document/financial_years_spec.rb
|
120
118
|
- spec/unit/document/voucher_series_spec.rb
|
121
119
|
- spec/unit/document_spec.rb
|
122
120
|
- spec/unit/parser/line_parser_spec.rb
|
@@ -142,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
140
|
version: '0'
|
143
141
|
requirements: []
|
144
142
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.2.
|
143
|
+
rubygems_version: 2.2.1
|
146
144
|
signing_key:
|
147
145
|
specification_version: 4
|
148
146
|
summary: Parses and generates SIE files (http://sie.se/)
|
@@ -150,7 +148,6 @@ test_files:
|
|
150
148
|
- spec/fixtures/sie_file.se
|
151
149
|
- spec/integration/parser_spec.rb
|
152
150
|
- spec/spec_helper.rb
|
153
|
-
- spec/unit/document/financial_years_spec.rb
|
154
151
|
- spec/unit/document/voucher_series_spec.rb
|
155
152
|
- spec/unit/document_spec.rb
|
156
153
|
- spec/unit/parser/line_parser_spec.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "active_support/time"
|
2
|
-
|
3
|
-
class Sie::Document
|
4
|
-
class FinancialYears
|
5
|
-
method_object :between,
|
6
|
-
:start_month, :from_date, :to_date
|
7
|
-
|
8
|
-
def between
|
9
|
-
from_date.year.upto(to_date.year).map { |year|
|
10
|
-
FinancialYear.date_range(year, start_month)
|
11
|
-
}
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class FinancialYear
|
16
|
-
method_object :date_range,
|
17
|
-
:year, :start_month
|
18
|
-
|
19
|
-
def date_range
|
20
|
-
(start_of_year.beginning_of_month..end_of_year.end_of_month)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def start_of_year
|
26
|
-
Date.new(year, start_month, 1)
|
27
|
-
end
|
28
|
-
|
29
|
-
def end_of_year
|
30
|
-
a_year_later = start_of_year >> 11
|
31
|
-
Date.new(a_year_later.year, a_year_later.month, -1)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Sie::Document::FinancialYears, ".between" do
|
4
|
-
it "gives us the financial years between from_date and to_date" do
|
5
|
-
Sie::Document::FinancialYears.between(
|
6
|
-
1,
|
7
|
-
Date.new(2011, 1, 1),
|
8
|
-
Date.new(2011, 12, 31)
|
9
|
-
).should == [
|
10
|
-
Date.new(2011, 1, 1)..Date.new(2011, 12, 31)
|
11
|
-
]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "gives us the financial years over multiple years" do
|
15
|
-
Sie::Document::FinancialYears.between(
|
16
|
-
1,
|
17
|
-
Date.new(2011, 9, 1),
|
18
|
-
Date.new(2013, 12, 31)
|
19
|
-
).should == [
|
20
|
-
Date.new(2011, 1, 1)..Date.new(2011, 12, 31),
|
21
|
-
Date.new(2012, 1, 1)..Date.new(2012, 12, 31),
|
22
|
-
Date.new(2013, 1, 1)..Date.new(2013, 12, 31),
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it "normalizes start and end date for compatibility with other systems" do
|
27
|
-
Sie::Document::FinancialYears.between(
|
28
|
-
1,
|
29
|
-
Date.new(2011, 9, 15),
|
30
|
-
Date.new(2011, 10, 10)
|
31
|
-
).should == [
|
32
|
-
Date.new(2011, 1, 1)..Date.new(2011, 12, 31),
|
33
|
-
]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "uses the start month" do
|
37
|
-
Sie::Document::FinancialYears.between(
|
38
|
-
5,
|
39
|
-
Date.new(2011, 9, 1),
|
40
|
-
Date.new(2014, 1, 31)
|
41
|
-
).should == [
|
42
|
-
Date.new(2011, 5, 1)..Date.new(2012, 4, 30),
|
43
|
-
Date.new(2012, 5, 1)..Date.new(2013, 4, 30),
|
44
|
-
Date.new(2013, 5, 1)..Date.new(2014, 4, 30),
|
45
|
-
Date.new(2014, 5, 1)..Date.new(2015, 4, 30),
|
46
|
-
]
|
47
|
-
end
|
48
|
-
end
|