en16931 0.1.3 → 0.2.0
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 +4 -0
- data/README.md +13 -2
- data/lib/en16931/invoice.rb +1 -1
- data/lib/en16931/line.rb +2 -2
- data/lib/en16931/tax.rb +1 -1
- data/lib/en16931/version.rb +1 -1
- data/lib/en16931.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bbd210e0095f8219bcd4986120584bfba05a5bba5a19e5a070c2bbfa54fc20a
|
|
4
|
+
data.tar.gz: 744699d446e6aa6a8fa5778a78cd1e3d665ae7e4178daa634dee99609a76c18a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 110226e91fb731c786161418a360eff39dce7b4f1ccc2ef01b67eed1768c5aed49a04b6500f26cc766b1e55a38b0ea9175d435ab75f06ec8acfdc169f632a71a
|
|
7
|
+
data.tar.gz: a0964ab315fc8989ab53e2191f00d5ec3a9249afa5215b63ab20810fbb20e21798211088827eb154c483f5d3f3fa389eac70f51feb55b5ece0176f9036a62781
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-10-22
|
|
4
|
+
|
|
5
|
+
- **Breaking:** amounts, quantities and rates (`Line#unit_price`, `Line#quantity`, `AllowanceCharge#amount`, `Tax#rate`, `Invoice#prepaid`) refuse a `Float` with an `ArgumentError`. Pass a `BigDecimal`, an `Integer` or a decimal `String`.
|
|
6
|
+
|
|
3
7
|
## [0.1.3] - 2026-10-21
|
|
4
8
|
|
|
5
9
|
- The recipient block shows the buyer's contact person ("z. Hd.") and VAT identifier. Like the XML, it leaves the VAT identifier out for invoices outside the scope of VAT (category O).
|
data/README.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# en16931
|
|
2
2
|
|
|
3
|
+
<p align="center"><sub>SPONSORED BY</sub></p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://www.company-mood.com"><picture><source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/companymood-dark.svg"><img src=".github/sponsors/companymood.svg" alt="CompanyMood" height="40"></picture></a>
|
|
6
|
+
|
|
7
|
+
<a href="https://myron.app"><picture><source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/myron-dark.svg"><img src=".github/sponsors/myron.svg" alt="Myron" height="30"></picture></a>
|
|
8
|
+
|
|
9
|
+
<a href="https://www.affliq.com"><picture><source media="(prefers-color-scheme: dark)" srcset=".github/sponsors/affliq-dark.svg"><img src=".github/sponsors/affliq.svg" alt="Affliq" height="42"></picture></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
3
12
|
EN 16931 e-invoices for Ruby, in pure Ruby.
|
|
4
13
|
|
|
5
14
|
- A small invoice model: parties, lines, a VAT treatment, payment details.
|
|
@@ -39,7 +48,7 @@ invoice = EN16931::Invoice.new(
|
|
|
39
48
|
seller: seller, buyer: buyer, buyer_reference: "PO-4711",
|
|
40
49
|
references: { "Kostenstelle" => "4711" }, # printed in the header, an XML note
|
|
41
50
|
tax: EN16931::DE.standard,
|
|
42
|
-
lines: [EN16931::Line.new(description: "Produktvideo TikTok, 60 Sekunden", unit_price: "1500.00")],
|
|
51
|
+
lines: [EN16931::Line.new(description: "Produktvideo TikTok, 60 Sekunden", unit_price: BigDecimal("1500.00"))],
|
|
43
52
|
payment: EN16931::Payment.new(iban: "DE89 3704 0044 0532 0130 00", bic: "COBADEFFXXX", holder: "Lena Beispiel",
|
|
44
53
|
terms: "Zahlbar innerhalb von 14 Tagen ohne Abzug.")
|
|
45
54
|
)
|
|
@@ -49,6 +58,8 @@ pdf = EN16931::PDF.render(invoice) # ZUGFeRD hybrid PDF/A-3b, profi
|
|
|
49
58
|
File.binwrite("2026-0001.pdf", pdf)
|
|
50
59
|
```
|
|
51
60
|
|
|
61
|
+
Amounts, quantities and rates are kept as `BigDecimal`. They accept a `BigDecimal`, an `Integer` or a decimal `String` such as `"1500.00"`; a `Float` raises an `ArgumentError`, because it has already lost the exact value.
|
|
62
|
+
|
|
52
63
|
### Tax cases
|
|
53
64
|
|
|
54
65
|
| Preset | Category | Use |
|
|
@@ -107,7 +118,7 @@ EN16931::Invoice.new(type: :corrected, preceding: { number: "2026-0001", issue_d
|
|
|
107
118
|
EN16931::Invoice.new(type: :credit_note, ...)
|
|
108
119
|
EN16931::Invoice.new(type: :self_billed, ...) # Gutschrift im Sinne von § 14 Abs. 2 UStG
|
|
109
120
|
EN16931::Invoice.new(period: Date.new(2026, 10, 1)..Date.new(2026, 10, 31), ...) # BG-14, e.g. a retainer month
|
|
110
|
-
EN16931::Invoice.new(prepaid: "200.00", allowances: [EN16931::AllowanceCharge.new(amount: "100.00", reason: "Treuerabatt", reason_code: "95")], ...)
|
|
121
|
+
EN16931::Invoice.new(prepaid: BigDecimal("200.00"), allowances: [EN16931::AllowanceCharge.new(amount: BigDecimal("100.00"), reason: "Treuerabatt", reason_code: "95")], ...)
|
|
111
122
|
```
|
|
112
123
|
|
|
113
124
|
### Validation
|
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/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"
|