en16931 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +15 -4
- data/Rakefile +19 -0
- data/data/LICENSE-CLDR.txt +41 -0
- data/data/countries.yml +4632 -0
- data/lib/en16931/invoice.rb +1 -1
- data/lib/en16931/line.rb +2 -2
- data/lib/en16931/pdf/labels.rb +3 -0
- data/lib/en16931/pdf/renderer.rb +1 -4
- data/lib/en16931/pdf.rb +1 -0
- data/lib/en16931/tax.rb +1 -1
- data/lib/en16931/version.rb +1 -1
- data/lib/en16931.rb +8 -0
- metadata +3 -1
data/lib/en16931/invoice.rb
CHANGED
|
@@ -45,7 +45,7 @@ module EN16931
|
|
|
45
45
|
# The list decides the direction; the flag follows it.
|
|
46
46
|
@allowances = allowances.map { |a| a.with(charge: false) }
|
|
47
47
|
@charges = charges.map { |c| c.with(charge: true) }
|
|
48
|
-
@prepaid =
|
|
48
|
+
@prepaid = EN16931.decimal(prepaid)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def type_code = TYPES.fetch(type)
|
data/lib/en16931/line.rb
CHANGED
|
@@ -8,7 +8,7 @@ module EN16931
|
|
|
8
8
|
# DAY day, MON month, LS lump sum, E48 service unit.
|
|
9
9
|
Line = Data.define(:description, :quantity, :unit, :unit_price, :tax, :note, :sellers_id, :period) do
|
|
10
10
|
def initialize(description:, unit_price:, quantity: 1, unit: "C62", tax: nil, note: nil, sellers_id: nil, period: nil)
|
|
11
|
-
super(description:, quantity:
|
|
11
|
+
super(description:, quantity: EN16931.decimal(quantity), unit:, unit_price: EN16931.decimal(unit_price),
|
|
12
12
|
tax:, note:, sellers_id:, period:)
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ module EN16931
|
|
|
18
18
|
# A document-level allowance (discount) or charge (BG-20 / BG-21).
|
|
19
19
|
AllowanceCharge = Data.define(:amount, :reason, :charge, :reason_code, :tax) do
|
|
20
20
|
def initialize(amount:, reason:, charge: false, reason_code: nil, tax: nil)
|
|
21
|
-
super(amount:
|
|
21
|
+
super(amount: EN16931.decimal(amount), reason:, charge:, reason_code:, tax:)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def charge? = charge
|
data/lib/en16931/pdf/labels.rb
CHANGED
|
@@ -166,6 +166,9 @@ module EN16931
|
|
|
166
166
|
|
|
167
167
|
# A supported locale as a symbol; anything unknown falls back to German.
|
|
168
168
|
def self.locale(value) = LABELS.key?(value&.to_sym) ? value.to_sym : :de
|
|
169
|
+
|
|
170
|
+
# Country names per locale from CLDR, see `rake countries`.
|
|
171
|
+
def self.countries = @countries ||= YAML.load_file(File.join(ROOT, "data", "countries.yml"))
|
|
169
172
|
end
|
|
170
173
|
end
|
|
171
174
|
end
|
data/lib/en16931/pdf/renderer.rb
CHANGED
|
@@ -255,10 +255,7 @@ module EN16931
|
|
|
255
255
|
def date(d) = d.strftime(FORMATS.fetch(locale)[2])
|
|
256
256
|
def unit(code) = LABELS.fetch(locale)[:units].fetch(code, code)
|
|
257
257
|
|
|
258
|
-
def country_name(code)
|
|
259
|
-
{ "DE" => "Deutschland", "AT" => "Österreich", "CH" => "Schweiz", "FR" => "Frankreich", "NL" => "Niederlande",
|
|
260
|
-
"US" => "USA", "GB" => "Vereinigtes Königreich", "IE" => "Irland", "LU" => "Luxemburg" }.fetch(code, code)
|
|
261
|
-
end
|
|
258
|
+
def country_name(code) = Renderer.countries.fetch(locale.to_s).fetch(code, code)
|
|
262
259
|
end
|
|
263
260
|
end
|
|
264
261
|
end
|
data/lib/en16931/pdf.rb
CHANGED
data/lib/en16931/tax.rb
CHANGED
|
@@ -10,7 +10,7 @@ module EN16931
|
|
|
10
10
|
# O not subject to VAT L/M Canary Islands / Ceuta-Melilla (unused here)
|
|
11
11
|
Tax = Data.define(:category, :rate, :exemption_reason, :exemption_code) do
|
|
12
12
|
def initialize(category:, rate: 0, exemption_reason: nil, exemption_code: nil)
|
|
13
|
-
super(category: category.to_s, rate:
|
|
13
|
+
super(category: category.to_s, rate: EN16931.decimal(rate), exemption_reason:, exemption_code:)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def taxed? = category == "S"
|
data/lib/en16931/version.rb
CHANGED
data/lib/en16931.rb
CHANGED
|
@@ -21,6 +21,14 @@ module EN16931
|
|
|
21
21
|
ROOT = File.expand_path("..", __dir__)
|
|
22
22
|
|
|
23
23
|
def self.font_path(name) = File.join(ROOT, "fonts", name)
|
|
24
|
+
|
|
25
|
+
# Amounts, quantities and rates as BigDecimal. A Float is refused: it has
|
|
26
|
+
# already lost the exact decimal value an invoice needs.
|
|
27
|
+
def self.decimal(value)
|
|
28
|
+
raise ArgumentError, "#{value.inspect} is a Float; pass a BigDecimal, an Integer or a decimal String" if value.is_a?(Float)
|
|
29
|
+
|
|
30
|
+
BigDecimal(value.to_s)
|
|
31
|
+
end
|
|
24
32
|
end
|
|
25
33
|
|
|
26
34
|
require_relative "en16931/version"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: en16931
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Markus Schwed
|
|
@@ -93,6 +93,8 @@ files:
|
|
|
93
93
|
- LICENSE.txt
|
|
94
94
|
- README.md
|
|
95
95
|
- Rakefile
|
|
96
|
+
- data/LICENSE-CLDR.txt
|
|
97
|
+
- data/countries.yml
|
|
96
98
|
- fonts/DejaVuSans-Bold.ttf
|
|
97
99
|
- fonts/DejaVuSans.ttf
|
|
98
100
|
- fonts/LICENSE-DejaVu.txt
|