en16931 0.2.0 → 0.2.2
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 +9 -0
- data/README.md +7 -7
- data/Rakefile +19 -0
- data/data/LICENSE-CLDR.txt +41 -0
- data/data/countries.yml +4632 -0
- data/lib/en16931/pdf/labels.rb +3 -0
- data/lib/en16931/pdf/renderer.rb +3 -5
- data/lib/en16931/pdf.rb +1 -0
- data/lib/en16931/totals.rb +4 -1
- data/lib/en16931/version.rb +1 -1
- metadata +3 -1
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
|
@@ -244,21 +244,19 @@ module EN16931
|
|
|
244
244
|
|
|
245
245
|
def number(value, decimals)
|
|
246
246
|
text = format("%.#{decimals.max}f", value)
|
|
247
|
+
sign = text.delete_prefix!("-") ? "-" : ""
|
|
247
248
|
int, frac = text.split(".")
|
|
248
249
|
frac = frac&.sub(/0+\z/, "") if decimals.min < decimals.max
|
|
249
250
|
frac = nil if frac && frac.empty?
|
|
250
251
|
sep = FORMATS.fetch(locale)
|
|
251
252
|
int = int.reverse.scan(/\d{1,3}/).join(sep[0]).reverse
|
|
252
|
-
[int, frac].compact.join(sep[1])
|
|
253
|
+
sign + [int, frac].compact.join(sep[1])
|
|
253
254
|
end
|
|
254
255
|
|
|
255
256
|
def date(d) = d.strftime(FORMATS.fetch(locale)[2])
|
|
256
257
|
def unit(code) = LABELS.fetch(locale)[:units].fetch(code, code)
|
|
257
258
|
|
|
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
|
|
259
|
+
def country_name(code) = Renderer.countries.fetch(locale.to_s).fetch(code, code)
|
|
262
260
|
end
|
|
263
261
|
end
|
|
264
262
|
end
|
data/lib/en16931/pdf.rb
CHANGED
data/lib/en16931/totals.rb
CHANGED
|
@@ -25,13 +25,16 @@ module EN16931
|
|
|
25
25
|
private
|
|
26
26
|
|
|
27
27
|
# One subtotal per distinct tax treatment; amount = taxable × rate, rounded.
|
|
28
|
+
# A negative base at 0 % gives BigDecimal -0, which the XML would print as
|
|
29
|
+
# "-0.00" against a total of "0.00" (BR-CO-14); zero is zero.
|
|
28
30
|
def breakdown(invoice)
|
|
29
31
|
bases = Hash.new(BigDecimal("0"))
|
|
30
32
|
invoice.lines.each { |line| bases[invoice.tax_for(line)] += line.net }
|
|
31
33
|
invoice.allowances.each { |a| bases[a.tax || invoice.tax] -= a.amount }
|
|
32
34
|
invoice.charges.each { |c| bases[c.tax || invoice.tax] += c.amount }
|
|
33
35
|
bases.map do |tax, taxable|
|
|
34
|
-
|
|
36
|
+
amount = (taxable * tax.rate / 100).round(2)
|
|
37
|
+
Subtotal.new(tax: tax, taxable: taxable, amount: amount.zero? ? BigDecimal("0") : amount)
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
end
|
data/lib/en16931/version.rb
CHANGED
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.2.
|
|
4
|
+
version: 0.2.2
|
|
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
|